こんにちは、Lase エクササイズ os に到達しました。Ruby The Hard Way を学ぶと、壁にぶつかります...
テストコードは次のとおりです。
def test_gothon_map()
assert_equal(START.go('shoot!'), generic_death)
assert_equal(START.go('dodge!'), generic_death)
room = START.go("tell a joke")
assert_equal(room, laser_weapon_armory)
end
テストするファイルのコードは次のとおりです。
class Room
attr_accessor :name, :description, :paths
def initialize(name, description)
@name = name
@description = description
@paths = {}
end
def ==(other)
self.name==other.name&&self.description==other.description&&self.paths==other.paths
end
def go(direction)
@paths[direction]
end
def add_paths(paths)
@paths.update(paths)
end
end
generic_death = Room.new("death", "You died.")
そして、テストファイルを起動しようとすると、エラーが発生します:
generic_death = Room.new("death", "You died.")
test_gothon_map メソッドで "generic_death = Room.new("death", "You die.")" を設定しようとしましたが、うまくいきましたが、次のオブジェクトの説明が非常に長いことが問題なので、私の質問は次のとおりです。
- 定義されたオブジェクトにアサーションが応答しないのはなぜですか?
- 次のオブジェクトの説明が非常に長いため、オブジェクト全体をテストメソッドに入れることによって、別の方法で実行できますか...