Reputation: 951
Does anyone know why this test is failing? All I'm trying to do is prove this method (starting positions) assigns the current_room to the starting_room and I can't get a value returned for current_room?
class Room
attr_reader :starting_room, :current_room
def initialize
@starting_room = "Room 5"
@current_room = nil
end
def starting_positions
@current_room = starting_room
end
end
before(:each) do
@room = Room.new
end
describe '#starting_positions' do
it 'sets the starting location to the current location' do
@room.instance_variable_set(:@starting_room, "Room 5")
expect(@room.current_room).to eql("Room 5")
end
end
My output:
Failures:
1) Room#starting_positions sets the starting location to the current location
Failure/Error: expect(@room.current_room).to eql("Room 5")
expected: "Room 5"
got: nil
Any ideas?
Upvotes: 0
Views: 871
Reputation: 5998
You assign @starting_room
and don't assign current_room
. You need trigger starting_positions
before(:each) do
@room = Room.new
end
describe '#starting_positions' do
it 'sets the starting location to the current location' do
@room.instance_variable_set(:@starting_room, "Room 5")
@room.starting_positions
expect(@room.current_room).to eql("Room 5")
end
end
Upvotes: 2