On Tuesday, July 23, 2013 5:20:51 AM UTC-7, [email protected] wrote: > > On Tue, Jul 23, 2013 at 8:57 AM, David Chelimsky > <[email protected]<javascript:> > > wrote: > >> On Tue, Jul 23, 2013 at 8:43 AM, David Chelimsky >> <[email protected]<javascript:> >> > wrote: >> >>> On Tue, Jul 23, 2013 at 7:22 AM, George Mendoza >>> <[email protected]<javascript:> >>> > wrote: >>> >>>> Hello everybody, >>>> >>>> I'm trying to update my rspec extension gem ( >>>> https://github.com/gsmendoza/verified_double) to the new expect syntax >>>> of rspec-mocks. I guessed that I can do this by creating a thin wrapper >>>> over the expect, receive, and allow methods of RSpec::Mocks::Syntax: >>>> >>>> # >>>> https://github.com/gsmendoza/verified_double/blob/7-convert-from-should_receive-to-expect-syntax/lib/verified_double/rspec_mocks_syntax_overrides.rb >>>> >>>> module VerifiedDouble >>>> module RSpecMocksSyntaxOverrides >>>> def expect(*args) >>>> VerifiedDouble.registry.current_double = args[0] >>>> super(*args) >>>> end >>>> >>>> def receive(*args) >>>> >>>> VerifiedDouble.registry.add_method_signature_with_current_double(args[0]) >>>> super(*args).tap {|result| >>>> result.extend(VerifiedDouble::CanRecordInteractions) } >>>> end >>>> end >>>> end >>>> >>>> The test for overridden >>>> expect<https://github.com/gsmendoza/verified_double/blob/7-convert-from-should_receive-to-expect-syntax/spec/verified_double/rspec_mocks_syntax_overrides_spec.rb> >>>> method passes, >>>> but the test for the receive method fails. If I rename my receive method >>>> to >>>> something else like better_receive, then the test suite can pick it up. >>>> >>>> If you can point me where or how to integrate the >>>> VerifiedDouble::RSpecMocksSyntaxOverrides module, that would be a big help >>>> :) >>>> >>> >>> I cloned the repo, checked out the branch, ran rspec and got the >>> following error: >>> >>> undefined method `add_method_signature_with_current_double' for >>> #<VerifiedDouble::RecordedMethodSignatureRegistry:0x007f9cdab73f58> >>> >>> Then I grepped through the code and I don't see >>> any add_method_signature_with_current_double method, so the error seems >>> legit to me. I might be missing something (like a `method_missing` designed >>> to handle this) but maybe that helps point you in the right direction. >>> >>> HTH, >>> David >>> >> >> Just realized I ran that using rspec-2.13 :) >> >> Please disregard. >> >> As a general FYI, please include the failure message when asking for help >> instead of just saying that it failed. Had I seen the error message was >> different from mine I wouldn't have wasted your time or mine w/ my previous >> response. >> > > I think I found part of the problem: receive is defined by rspec-mocks > when the configuration is eval'd and `enable_expect` is invoked: > https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/syntax.rb#L87 > > That happens after all the requires, therefore verified-double's version > of `receive` is defined _before_ rspec's version. You'll need a way to > ensure verified-double's version gets defined after rspec's version. > > @myronmarston - any thoughts on the best way to do that ^^? > > That, plus I still don't see add_method_signature_with_current_double > anywhere in the code, so that might still be a problem. > > HTH, > David >
Yeah, we've had to do some slightly non-standard things to make the syntax configurable. David, you mention it happening after all the requires, but when `rspec/mocks/configuration.rb` is required it configures it: https://github.com/rspec/rspec-mocks/blob/e6d19803585e0f8488f650a8fbc0057c6ec9751b/lib/rspec/mocks/configuration.rb#L52 These sorts of things usually come down to the order of modules/classes in the ancestors chain, and one difference between `expect` and `receive` is that `expect` is defined in rspec-expectations in the RSpec::Matchers module: https://github.com/rspec/rspec-expectations/blob/b303274dc5eb9427664f71e652b2da256e472a71/lib/rspec/expectations/syntax.rb#L79-L91 ...whereas `receive` is defined in rspec-mocks in the RSpec::Mocks::ExampleMethods module: https://github.com/rspec/rspec-mocks/blob/e6d19803585e0f8488f650a8fbc0057c6ec9751b/lib/rspec/mocks/syntax.rb#L87-L113 So, it sounds like your module is being inserted between these two modules, such that it can override one method, but not the other. Maybe you can change the way you are including your module so that it winds up at the right place in the ancestors chain? You can inspect it by putting `p self.class.ancestors` inside an example. HTH, Myron -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/4bb181c2-bb5a-405d-87b7-bdec56b3c50e%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
