主题的未定义方法`should_receive'

时间:2014-11-19 18:39:16

标签: ruby methods rspec mocking subject

我的班级与此相似:

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

我尝试检查,如果external_method使用适当的参数调用internal_method

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

我得到的是:

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

我做错了什么?

0 个答案:

没有答案