Question

I'm finding the whole TDD very confusing. I've passed the first two test successfully but I am not sure on how to write the last last one.

All it needs is to return the student's name. I've highlighted where it should go.

RSpec:

describe Game do
    describe "#start The impossible machine game" do
        before(:each) do
            @process = []
            @output = double('output').as_null_object
            @game = Game.new(@output)
        end
        it "sends a welcome message" do
            @output.should_receive(:puts).with('Welcome to the Impossible Machine!')
            @game.start
        end
        it "sends a starting message" do
            @output.should_receive(:puts).with('Starting game...')
            @game.start         
        end
        it "should contain a method created_by which returns the students name" do
            myname = @game.created_by
            myname.should == "Student's name"
        end
    end
end

Current tests (first two tests work fine)

class Game
    attr_reader :process, :output
    attr_writer :process, :output
    def initialize(output)
        @output = output
        puts "[#{@output}]"
    end
    def start
        @output.puts'Welcome to the Impossible Machine!'
        @output.puts'Starting game...'
        # code to return student's name here
    end
end
Was it helpful?

Solution

well you seem to need a game created_by field which you should add, you then need to set it when you create the game and then return it when you start the game, something like this:

class Game
    attr_accessor :created_by
    attr_reader :process, :output
    attr_writer :process, :output
    def initialize(output, created_by)
        @output = output
        @created_by = created_by
        puts "[#{@output}]"
    end
    def start
        @output.puts 'Welcome to the Impossible Machine!'
        @output.puts 'Starting game...'
        @output.puts @created_by
        # code to return student's name here
    end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top