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
ErrorGenerator#arg_list interferes with arg#description methods #685
Comments
What do you mean by "save the expectation"? |
@myronmarston Into a variable. |
Found the issue I think, although the expect output missing the first argument prevented me from noticing it at first:
@myronmarston I'll let you close but it does seem like weird error feedback. |
Can you show an example of what you mean? |
It's still unclear to me what the issue is you are reporting. I'm not trying to be obtuse...can you paste a reproducible example? |
Only way I could reproduce this was with an ActiveRecord object. the_object = double("the object")
subscription = double("the subscription")
owner = User.create # had to use an AR model here, didn't work with doubles
allow(subscription).to receive(:owner).and_return(owner)
allow(subscription).to receive(:next_charge_on).and_return(1.month.from_now.in_time_zone)
expect(the_object).to receive(:die).with(subscription.owner, subscription.next_charge_on)
subscription_with_weird_date = double("a subscription", next_charge_on: 1.month.from_now.in_time_zone.to_date.to_formatted_s(:long_ordinal))
the_object.die(owner, subscription_with_weird_date.next_charge_on) Here, This is the output: RSpec::Mocks::MockExpectationError: Double "the object" received :die with unexpected arguments
expected: (, Fri, 27 Jun 2014 18:46:25 UTC +00:00)
got: (#<User id: 5, ...>, "June 27th, 2014")
from /Users/olivierlacan/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/rspec-mocks-2.14.6/lib/rspec/mocks/error_generator.rb:144:in `__raise' |
Welp, figured it out further. Our Maybe rspec-mocks shouldn't expect such a common method name? Why not See:
|
Because rspec-mocks supports any custom matcher (using the matcher protocol defined by rspec-expectations) for You're right that using I've got some thoughts on how to fix it, though: we can do a check using a method like this: ...and only use |
@myronmarston That sounds like a good non-API breaking way to do that. I agree with you, it's pretty edgy case even if I can see it bitting other people unexpectedly. Want me to submit a PR? Or you want to tackle it? |
You are welcome to :). It's a bit more complicated then it appears at first, though:
|
This fixes #685. It means that we only print descriptions in errors for matcher objects and not for user objects.
This fixes #685. It means that we only print descriptions in errors for matcher objects and not for user objects.
### 3.2.0 / 2015-02-03 [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.1.3...v3.2.0) Enhancements: * Treat `any_args` as an arg splat, allowing it to match an arbitrary number of args at any point in an arg list. (Myron Marston, #786) * Print diffs when arguments in mock expectations are mismatched. (Sam Phippen, #751) * Support names for verified doubles (`instance_double`, `instance_spy`, `class_double`, `class_spy`, `object_double`, `object_spy`). (Cezary Baginski, #826) * Make `array_including` and `hash_including` argument matchers composable. (Sam Phippen, #819) * Make `allow_any_instance_of(...).to receive(...).and_wrap_original` work. (Ryan Fitzgerald, #869) Bug Fixes: * Provide a clear error when users wrongly combine `no_args` with additional arguments (e.g. `expect().to receive().with(no_args, 1)`). (Myron Marston, #786) * Provide a clear error when users wrongly use `any_args` multiple times in the same argument list (e.g. `expect().to receive().with(any_args, 1, any_args)`. (Myron Marston, #786) * Prevent the error generator from using user object #description methods. See [#685](rspec/rspec-mocks#685). (Sam Phippen, #751) * Make verified doubles declared as `(instance|class)_double(SomeConst)` work properly when `SomeConst` has previously been stubbed. `(instance|class)_double("SomeClass")` already worked properly. (Myron Marston, #824) * Add a matcher description for `receive`, `receive_messages` and `receive_message_chain`. (Myron Marston, #828) * Validate invocation args for null object verified doubles. (Myron Marston, #829) * Fix `RSpec::Mocks::Constant.original` when called with an invalid constant to return an object indicating the constant name is invalid, rather than blowing up. (Myron Marston, #833) * Make `extend RSpec::Mocks::ExampleMethods` on any object work properly to add the rspec-mocks API to that object. Previously, `expect` would be undefined. (Myron Marston, #846) * Fix `require 'rspec/mocks/standalone'` so that it only affects `main` and not every object. It's really only intended to be used in a REPL like IRB, but some gems have loaded it, thinking it needs to be loaded when using rspec-mocks outside the context of rspec-core. (Myron Marston, #846) * Prevent message expectations from being modified by customization methods (e.g. `with`) after they have been invoked. (Sam Phippen and Melanie Gilman, #837) * Handle cases where a method stub cannot be removed due to something external to RSpec monkeying with the method definition. This can happen, for example, when you `file.reopen(io)` after previously stubbing a method on the `file` object. (Myron Marston, #853) * Provide a clear error when received message args are mutated before a `have_received(...).with(...)` expectation. (Myron Marston, #868)
I'm having a hard time diagnosing this issue I'm having (running 2.14.6 on Rails 3.1.12).
When I set the following expectation:
I receive the following error:
If I save the expectation, the expected arguments are indeed:
Any clue as to what could impact the expectation like that?
The text was updated successfully, but these errors were encountered: