有谁知道为什么这个测试失败了? 我要做的就是证明这个方法(起始位置)将current_room分配给starting_room,而我无法获得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

我的输出:

 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

有任何想法吗?

===============>>#1 票数:2 已采纳

您指定@starting_room并且不指定current_room 你需要触发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

  ask by user3007294 translate from so

未解决问题?本站智能推荐: