undefined method `should_receive' for subject

175 views Asked by At

I have class similar to this:

class SomeClass

  attr_accessor :numbers

  # (...)

  def external_method
    numbers.each do |variant, duration|
      duration.each do |duration, value|
        internal_method(variant, duration, value)
      end
    end
  end

  def internal_method(variant, duration, value)
    # do something with these arguments
  end

end

And I try to check, If external_method calls internal_method with proper arguments.

describe("#external_method") do
  let!(:numbers) do 
    {
      1 => {
        1 => 0.1,
        2 => 0.2
      },
      2 => {
        1 => 0.3,
        2 => 0.4
      }
    } 
  end

  it "should call internal method for all values" do
    value = 0
    (1..2).each do |variant|
      (1..2).each do |duration|
        value += 0.1
        subject.should_receive(:internal_method).with(variant, duration, value).once
      end
    end
    subject.external_method
  end
end

What I get is:

 Failure/Error: subject.should_receive(:internal_method).with(variant, duration, value)
 NoMethodError:
   undefined method `should_receive' for #<SomeClass:0x007fabb2321ff8>

What am I doing wrong?

0

There are 0 answers