当对象收到消息两次时,Rspec如何期望收到消息""

时间:2014-12-31 05:58:54

标签: ruby-on-rails rspec

我有以下示例:

it 'receives message' do
  expect(Foo).to receive(:bar).with(baz)
  OtherClass.send(baz)
end

class OtherClass
  def self.send(baz)
    Foo.bar(1) # this first one is the problem
    Foo.bar(baz)
  end
end

class Foo
  def self.bar(whatever)
    puts whatever + " was received"
  end
end

这是错误:

Failure/Error: Foo received :bar with unexpected arguments