1

假设,我正在运行这个测试

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'

我该如何解决?

4

1 回答 1

3

尝试这个:

@mymodel.stubs(:method).returns(true)
于 2014-04-08T11:13:41.200 回答