rspec-mocks icon indicating copy to clipboard operation
rspec-mocks copied to clipboard

Spies do not support ordering with interleaved calls

Open myronmarston opened this issue 10 years ago • 12 comments

RSpec.describe "Specifying ordering for calls that are interleaved with each other" do
  it 'fails when using `have_received`' do
    dbl = spy

    dbl.one
    dbl.one
    dbl.two
    dbl.one
    dbl.two

    expect(dbl).to have_received(:one).twice.ordered
    expect(dbl).to have_received(:two).once.ordered
    expect(dbl).to have_received(:one).once.ordered
    expect(dbl).to have_received(:two).once.ordered
  end

  it 'passes when using `receive`' do
    dbl = double

    expect(dbl).to receive(:one).twice.ordered
    expect(dbl).to receive(:two).once.ordered
    expect(dbl).to receive(:one).once.ordered
    expect(dbl).to receive(:two).once.ordered

    dbl.one
    dbl.one
    dbl.two
    dbl.one
    dbl.two
  end
end

The second spec passes, but the first fails:

Specifying ordering for calls that are interleaved with each other
  fails when using `have_received` (FAILED - 1)
  passes when using `receive`

Failures:

  1) Specifying ordering for calls that are interleaved with each other fails when using `have_received`
     Failure/Error: expect(dbl).to have_received(:one).twice.ordered
       (Double).one(*(any args))
           expected: 2 times with any arguments
           received: 3 times with any arguments

I originally put a failing spec in #881 but don't have the time to fix it so I figured I'd convert it into an issue in the hope that someone else would pick it up.

myronmarston avatar Mar 26 '15 04:03 myronmarston