我正试着通过这次考试,我不知道该如何通过考试。
测试
def test_it_is_thirsty_by_default
vampire = Vampire.new("Count von Count")
assert vampire.thirsty?
end
def test_it_is_not_thirsty_after_drinking
vampire = Vampire.new("Elizabeth Bathory")
vampire.drink
refute vampire.thirsty?
end码
def thirsty?
true
end
def drink
thirsty? === false
end它在上一次测试中给出了一个失败的消息:
Failed refutation, no message given
我遗漏了什么?我的想法是,最初,吸血鬼口渴(是真的),然后定义了一种方法,然后使吸血鬼不渴(假)。
编辑
即使我将饮料方法重新分配到:
thirsty? = false
我收到指向=符号的语法错误。
发布于 2019-06-03 03:47:10
您缺少了一些东西,最重要的是某种编写方法,它允许您将@thirsty更新到drink方法调用中
有几种不同的方法可以做到这一点,但我在下面向您展示了一种方法,并给出了一些注意事项:
require 'test/unit'
class Vampire
def initialize(name)
@name = name
@thirsty = true # true by default
end
def drink
@thirsty = false # updates @thirsty for the respective instance
end
def thirsty?
@thirsty
end
end
class VampireTests < Test::Unit::TestCase
def test_it_is_thirsty_by_default
vampire = Vampire.new("Count von Count")
assert vampire.thirsty?
end
def test_it_is_not_thirsty_after_drinking
vampire = Vampire.new("Elizabeth Bathory")
vampire.drink
refute vampire.thirsty?
end
endhttps://stackoverflow.com/questions/56420576
复制相似问题