/ / Testowanie przypisania zmiennej w rspec - ruby, rspec

Testowanie przypisania zmiennych w rspec - ruby, rspec

Czy ktoś wie, dlaczego ten test kończy się niepowodzeniem? Wszystko, co próbuję zrobić, to udowodnić, że ta metoda (pozycje początkowe) przypisuje bieżącą salę do sali początkowej i nie mogę zwrócić wartości dla bieżącej sali?

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

Moje wyniki:

 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

Jakieś pomysły?

Odpowiedzi:

2 dla odpowiedzi № 1

Przypisujesz @starting_room i nie przypisuj current_room. Potrzebujesz spustu 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