RSpec: how to test if a method was called? RSpec: how to test if a method was called? ruby ruby

RSpec: how to test if a method was called?


it "should call 'bar' with appropriate arguments" do  expect(subject).to receive(:bar).with("an argument I want")  subject.fooend


In the new rspec expect syntax this would be:

expect(subject).to receive(:bar).with("an argument I want")


The below should work

describe "#foo"  it "should call 'bar' with appropriate arguments" do     subject.stub(:bar)     subject.foo     expect(subject).to have_received(:bar).with("Invalid number of arguments")  endend

Documentation: https://github.com/rspec/rspec-mocks#expecting-arguments