RSpec: how to test if a method was called?

后端 未结 4 2232
眼角桃花
眼角桃花 2020-12-13 03:00

When writing RSpec tests, I find myself writing a lot of code that looks like this in order to ensure that a method was called during the execution of a test (for the sake o

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 03:38

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

提交回复
热议问题