user1611830
user1611830

Reputation: 4867

stub is not defined while testing

Suppose, I am running this test

Class MyModelTest < ActiveSupport::TestCase  
  def setup do
    @mymodel = MyModel.new
  end

  @mymodel.stub(:method).and_return { true }

but I get :undefined method 'stub' for nil:NilClass. I thought it was related to the nil instance, in fact when I dump with @mymodel with data, I get the same message undefined method stub'. Then I tried @mymodel.stubs(:method).and_return { true }, and I got this message

undefined method `and_return'

How can I solve that ?

Upvotes: 1

Views: 478

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51181

Try this:

@mymodel.stubs(:method).returns(true)

Upvotes: 3

Related Questions