-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matchers missing compound methods #1298
Comments
Good catch on Reproduction example with the difference between non-composable and composable expectations: RSpec.describe 'have_received' do
class A
def foo(x)
end
end
subject(:a) { A.new }
it 'fails with a proper error message' do
allow(a).to receive(:foo).with(1)
allow(a).to receive(:foo).with(2)
# action here
expect(a).to have_received(:foo).with(1).ordered
expect(a).to have_received(:foo).with(2).ordered
end
it 'fails with a proper error message when chained' do
allow(a).to receive(:foo).with(1)
allow(a).to receive(:foo).with(2)
# action here
expect(a)
.to have_received(:foo).with(1).ordered
.and have_received(:foo).with(2).ordered
end
end Depending on the order of the calls in a.foo(1)
a.foo(2)
a.foo(2)
a.foo(1)
# #<A:0x00007ffd7dc89da8> received :foo out of order
a.foo(1)
# #<A:0x00007ffaa4a836e8> received :foo with unexpected arguments
# expected: (2)
# got: (1)
#
# vs
#
# #<A:0x00007ffaa3a9e340> received :foo out of order In order for composability to work, include RSpec::Matchers::Composable should be added to One spec in the suite fails, supposedly due to an issued warning. |
We'd need to check that the module is defined before including it, as |
@eLod would you like to work on this improvement? |
@eLod incorrect message ( So I'd say go ahead and add that new feature, while incorrect message should be dealt with separately. Appreciate if you could file a ticket (with an example from case 3 from #1298 (comment)). |
@pirj i started to work on it, but i'm having trouble writing specs or features, getting "only the edit: sorry for the confusion, i think i've realised the compound functionality should only apply to |
@eLod hm. Can you please push your work in progress? Let's figure it out together. |
@pirj see my edit, i was trying to do |
@pirj pushed changes, not sure about the shared examples, a bit complex on how the compound expectation is built and verified. also there are examples failing, all because of (edit: typo) |
i am guessing it is because |
Subject of the issue
I was trying to use rspec expectations' compound feature as in
expect().to have_received().and.have_received()
(actually for using with.ordered
), but theand
method is missing fromHaveReceived
matcher (and i guess from the others too). IncludingRSpec::Matchers::Composable
into the matcher solves the problem (though the error may be somewhat misleading, as for example if the argument expectations fail it still complains about calls out of order).Your environment
Steps to reproduce
Try to chain compound methods onto have_received matcher.
Expected behavior
Should work.
Actual behavior
It raises NoMethodError.
The text was updated successfully, but these errors were encountered: