我在为正在运行的测试创建存根时遇到问题minitest (4.7.0)
。我从以前的 SO 问题中研究过的内容尝试了以下内容,但它不起作用:
测试/模型/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