假设,我正在运行这个测试
Class MyModelTest < ActiveSupport::TestCase
def setup do
@mymodel = MyModel.new
end
@mymodel.stub(:method).and_return { true }
但我得到:undefined method 'stub' for nil:NilClass
。我认为它与 nil
实例有关,实际上当我用 @mymodel
转储数据时,我得到了相同的消息 undefined method stub'
。然后我尝试了 @mymodel.stubs(:method).and_return { true }
,我收到了这条消息
undefined method `and_return'
我该如何解决?
最佳答案
试试这个:
@mymodel.stubs(:method).returns(true)
关于ruby-on-rails - 测试时未定义 stub ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22935128/