Given this simple cucumber feature (related to another rspec bug I am working on): http://gist.github.com/266335 I''m fighting with this error messages that _only_ shows up in certain situations that I can''t quite pin down (rake features breaks, individual cucumber run works, rake with debugger beforehand works...)> expected NoMethodError, got #<NameError: undefined local variable or method `nap'' for Time:Class > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time should not be defined$/'' > features/either/stubs_dont_leak.feature:11:in `Then nap time should not be defined''I''ve tracked it down to this line: http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 def message_received(sym, *args, &block) expectation = find_matching_expectation(sym, *args) stub = find_matching_method_stub(sym, *args) if (stub && expectation && expectation.called_max_times?) || (stub && !expectation) if expectation = find_almost_matching_expectation(sym, *args) expectation.advise(args, block) unless expectation.expected_messages_received? end stub.invoke(*args, &block) elsif expectation expectation.invoke(*args, &block) elsif expectation = find_almost_matching_expectation(sym, *args) expectation.advise(args, block) if null_object? unless expectation.expected_messages_received? raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(sym) or null_object?) else --> @target.__send__ :method_missing, sym, *args, &block end end My question is this... why do we fall back to method_missing here rather than a simple ''send'' to the target? I figure there is likely a reason, so if someone could help me understand I''ll happily open up my expectation to should_raise(NameError) and move along. :) Cheers, Paul
On 30 Dec 2009, at 21:04, Paul Hinze wrote:> I''m fighting with this error messages that _only_ shows up in certain situations that I can''t quite pin downSounds eerily familiar: http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/ Cheers, -Tom
Andrew Premdas
2010-Jan-04 20:57 UTC
[rspec-users] ''Expected NoMethodError, got NameError''
2009/12/30 Paul Hinze <paul.t.hinze at gmail.com>> Given this simple cucumber feature (related to another rspec bug I am > working on): > > http://gist.github.com/266335 > > I''m fighting with this error messages that _only_ shows up in certain > situations that I can''t quite pin down (rake features breaks, individual > cucumber run works, rake with debugger beforehand works...) > > > expected NoMethodError, got #<NameError: undefined local variable or > method `nap'' for Time:Class > > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time > should not be defined$/'' > > features/either/stubs_dont_leak.feature:11:in `Then nap time should not > be defined'' > > I''ve tracked it down to this line: > > http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117This method is really unpleasant, perhaps some standard refactorings to remove the complex conditional conditions and remove the nested if''s would be useful first of all.> > def message_received(sym, *args, &block) > expectation = find_matching_expectation(sym, *args) > stub = find_matching_method_stub(sym, *args) > > if (stub && expectation && expectation.called_max_times?) || (stub && > !expectation) > if expectation = find_almost_matching_expectation(sym, *args) > expectation.advise(args, block) unless > expectation.expected_messages_received? > end > stub.invoke(*args, &block) > elsif expectation > expectation.invoke(*args, &block) > elsif expectation = find_almost_matching_expectation(sym, *args) > expectation.advise(args, block) if null_object? unless > expectation.expected_messages_received? > raise_unexpected_message_args_error(expectation, *args) unless > (has_negative_expectation?(sym) or null_object?) > else > --> @target.__send__ :method_missing, sym, *args, &block > end > end > > My question is this... why do we fall back to method_missing here rather > than a simple ''send'' to the target? I figure there is likely a reason, > so if someone could help me understand I''ll happily open up my > expectation to should_raise(NameError) and move along. :) > > Cheers, > > Paul > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100104/721be99d/attachment-0001.html>
David Chelimsky
2010-Jan-04 21:00 UTC
[rspec-users] ''Expected NoMethodError, got NameError''
On Mon, Jan 4, 2010 at 2:57 PM, Andrew Premdas <apremdas at gmail.com> wrote:> 2009/12/30 Paul Hinze <paul.t.hinze at gmail.com> > > Given this simple cucumber feature (related to another rspec bug I am >> working on): >> >> http://gist.github.com/266335 >> >> I''m fighting with this error messages that _only_ shows up in certain >> situations that I can''t quite pin down (rake features breaks, individual >> cucumber run works, rake with debugger beforehand works...) >> >> > expected NoMethodError, got #<NameError: undefined local variable or >> method `nap'' for Time:Class >> > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time >> should not be defined$/'' >> > features/either/stubs_dont_leak.feature:11:in `Then nap time should not >> be defined'' >> >> I''ve tracked it down to this line: >> >> >> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 > > > This method is really unpleasant, perhaps some standard refactorings to > remove the complex conditional conditions and remove the nested if''s would > be useful first of all. >Agreed. Patches welcome!> def message_received(sym, *args, &block) >> expectation = find_matching_expectation(sym, *args) >> stub = find_matching_method_stub(sym, *args) >> >> if (stub && expectation && expectation.called_max_times?) || (stub && >> !expectation) >> if expectation = find_almost_matching_expectation(sym, *args) >> expectation.advise(args, block) unless >> expectation.expected_messages_received? >> end >> stub.invoke(*args, &block) >> elsif expectation >> expectation.invoke(*args, &block) >> elsif expectation = find_almost_matching_expectation(sym, *args) >> expectation.advise(args, block) if null_object? unless >> expectation.expected_messages_received? >> raise_unexpected_message_args_error(expectation, *args) unless >> (has_negative_expectation?(sym) or null_object?) >> else >> --> @target.__send__ :method_missing, sym, *args, &block >> end >> end >> >> My question is this... why do we fall back to method_missing here rather >> than a simple ''send'' to the target? I figure there is likely a reason, >> so if someone could help me understand I''ll happily open up my >> expectation to should_raise(NameError) and move along. :) >> >> Cheers, >> >> Paul >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100104/7e2b2352/attachment.html>
David Chelimsky
2010-Jan-05 08:38 UTC
[rspec-users] ''Expected NoMethodError, got NameError''
On Mon, Jan 4, 2010 at 3:00 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> >>> >>> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 >> >> >> This method is really unpleasant, perhaps some standard refactorings to >> remove the complex conditional conditions and remove the nested if''s would >> be useful first of all. >> >http://github.com/dchelimsky/rspec/commit/386e3347ed7cecbb2ea3095909b93ac8c97bb638 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100105/43aaafae/attachment.html>
Andrew Premdas
2010-Jan-05 13:35 UTC
[rspec-users] ''Expected NoMethodError, got NameError''
2010/1/4 David Chelimsky <dchelimsky at gmail.com>> On Mon, Jan 4, 2010 at 2:57 PM, Andrew Premdas <apremdas at gmail.com> wrote: > >> 2009/12/30 Paul Hinze <paul.t.hinze at gmail.com> >> >> Given this simple cucumber feature (related to another rspec bug I am >>> working on): >>> >>> http://gist.github.com/266335 >>> >>> I''m fighting with this error messages that _only_ shows up in certain >>> situations that I can''t quite pin down (rake features breaks, individual >>> cucumber run works, rake with debugger beforehand works...) >>> >>> > expected NoMethodError, got #<NameError: undefined local variable or >>> method `nap'' for Time:Class >>> > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time >>> should not be defined$/'' >>> > features/either/stubs_dont_leak.feature:11:in `Then nap time should not >>> be defined'' >>> >>> I''ve tracked it down to this line: >>> >>> >>> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 >> >> >> This method is really unpleasant, perhaps some standard refactorings to >> remove the complex conditional conditions and remove the nested if''s would >> be useful first of all. >> > > Agreed. Patches welcome! >David, I hope my comment didn''t come out as sniping/bitchy/negative, and the suggested refactorings were useful. Couldn''t really make a patch as I don''t have the context to name things correctly. Anyhow thanks once again for all your wonderful work on rspec and on this mailing list it really is very much appreciated. All best Andrew> > >> def message_received(sym, *args, &block) >>> expectation = find_matching_expectation(sym, *args) >>> stub = find_matching_method_stub(sym, *args) >>> >>> if (stub && expectation && expectation.called_max_times?) || (stub && >>> !expectation) >>> if expectation = find_almost_matching_expectation(sym, *args) >>> expectation.advise(args, block) unless >>> expectation.expected_messages_received? >>> end >>> stub.invoke(*args, &block) >>> elsif expectation >>> expectation.invoke(*args, &block) >>> elsif expectation = find_almost_matching_expectation(sym, *args) >>> expectation.advise(args, block) if null_object? unless >>> expectation.expected_messages_received? >>> raise_unexpected_message_args_error(expectation, *args) unless >>> (has_negative_expectation?(sym) or null_object?) >>> else >>> --> @target.__send__ :method_missing, sym, *args, &block >>> end >>> end >>> >>> My question is this... why do we fall back to method_missing here rather >>> than a simple ''send'' to the target? I figure there is likely a reason, >>> so if someone could help me understand I''ll happily open up my >>> expectation to should_raise(NameError) and move along. :) >>> >>> Cheers, >>> >>> Paul >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100105/93e13ce4/attachment-0001.html>
David Chelimsky
2010-Jan-05 16:16 UTC
[rspec-users] ''Expected NoMethodError, got NameError''
On Tue, Jan 5, 2010 at 7:35 AM, Andrew Premdas <apremdas at gmail.com> wrote:> 2010/1/4 David Chelimsky <dchelimsky at gmail.com> > > On Mon, Jan 4, 2010 at 2:57 PM, Andrew Premdas <apremdas at gmail.com> wrote: >> >>> 2009/12/30 Paul Hinze <paul.t.hinze at gmail.com> >>> >>> Given this simple cucumber feature (related to another rspec bug I am >>>> working on): >>>> >>>> http://gist.github.com/266335 >>>> >>>> I''m fighting with this error messages that _only_ shows up in certain >>>> situations that I can''t quite pin down (rake features breaks, individual >>>> cucumber run works, rake with debugger beforehand works...) >>>> >>>> > expected NoMethodError, got #<NameError: undefined local variable or >>>> method `nap'' for Time:Class >>>> > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time >>>> should not be defined$/'' >>>> > features/either/stubs_dont_leak.feature:11:in `Then nap time should >>>> not be defined'' >>>> >>>> I''ve tracked it down to this line: >>>> >>>> >>>> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 >>> >>> >>> This method is really unpleasant, perhaps some standard refactorings to >>> remove the complex conditional conditions and remove the nested if''s would >>> be useful first of all. >>> >> >> Agreed. Patches welcome! >> > > David, > > I hope my comment didn''t come out as sniping/bitchy/negative, >Absolutely not! You were spot on.> and the suggested refactorings were useful. >I learned a lot about that code going through it.> Couldn''t really make a patch as I don''t have the context to name things > correctly. >Understood. Hopefully that will improve over time.> Anyhow thanks once again for all your wonderful work on rspec and on this > mailing list it really is very much appreciated. >Thank you for saying so. Appreciation is always appreciated :) Cheers, David> > All best > > Andrew > > >> >> >>> def message_received(sym, *args, &block) >>>> expectation = find_matching_expectation(sym, *args) >>>> stub = find_matching_method_stub(sym, *args) >>>> >>>> if (stub && expectation && expectation.called_max_times?) || (stub && >>>> !expectation) >>>> if expectation = find_almost_matching_expectation(sym, *args) >>>> expectation.advise(args, block) unless >>>> expectation.expected_messages_received? >>>> end >>>> stub.invoke(*args, &block) >>>> elsif expectation >>>> expectation.invoke(*args, &block) >>>> elsif expectation = find_almost_matching_expectation(sym, *args) >>>> expectation.advise(args, block) if null_object? unless >>>> expectation.expected_messages_received? >>>> raise_unexpected_message_args_error(expectation, *args) unless >>>> (has_negative_expectation?(sym) or null_object?) >>>> else >>>> --> @target.__send__ :method_missing, sym, *args, &block >>>> end >>>> end >>>> >>>> My question is this... why do we fall back to method_missing here rather >>>> than a simple ''send'' to the target? I figure there is likely a reason, >>>> so if someone could help me understand I''ll happily open up my >>>> expectation to should_raise(NameError) and move along. :) >>>> >>>> Cheers, >>>> >>>> Paul >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100105/febf186e/attachment.html>
Rick DeNatale
2010-Jan-05 23:10 UTC
[rspec-users] ''Expected NoMethodError, got NameError''
On Tue, Jan 5, 2010 at 11:16 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Tue, Jan 5, 2010 at 7:35 AM, Andrew Premdas <apremdas at gmail.com> wrote: >> Anyhow thanks once again for all your wonderful work on rspec and on this >> mailing list it really is very much appreciated. > > Thank you for saying so. Appreciation is always appreciated :)I can appreciate that! -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale