我在使用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