The nature of local variable is that they are, well, local. This means that they are not available outside the scope they were defined.
That's why ruby does not know what generic_death
means in your test.
You can solve this in a couple of ways:
define rooms as constants in the Room class:
class Room # ... GENERIC_DEATH = Room.new("death", "You died.") LASER_WEAPON_ARMORY = Room.new(...) end def test_gothon_map() assert_equal(Room::START.go('shoot!'), Room::GENERIC_DEATH) assert_equal(Room::START.go('dodge!'), Room::GENERIC_DEATH) room = Room::START.go("tell a joke") assert_equal(room, Room::LASER_WEAPON_ARMORY) end
assert the room by its name, or some other identifier:
def test_gothon_map() assert_equal(START.go('shoot!').name, "death") assert_equal(START.go('dodge!').name, "death") room = START.go("tell a joke") assert_equal(room.name, "laser weapon armory") end