我在使用minitest (4.7.0)
运行的测试中创建存根的问题。我试着从以下是我已经从以前的SO问题的研究和它不工作:使用minitest创建存根的正确方法是什么?
测试/模型/ book_test.rb
Book.stub :title, "War and Peace" do
book = Book.new
book.title.must_equal "War and Peace"
end
错误
NameError: undefined method 'title' for `Book'
应用程序/模型/ book.rb
class Book
#I tried adding the following according to the github readme but it doesn't work:
#def title.fake_method
#end
end
你到底想干什么?你以后的行为是什么?上述有些事情是错误的,但我并不完全清楚你的目标是什么。 – 2013-03-25 00:50:51
以上是我用来学习存根工作原理的一个例子。我想要做的是在'Book'类中创建一个'title'方法的存根用于测试。我目前还没有创建'标题'方法,所以我只需要一个假的测试。 – perseverance 2013-03-25 00:56:54