Forum: RSpec NoMethodError dependent on spec order

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
315035a47dcb93f4427b8a1e18da4ff7?d=identicon&s=25 Jim Lindley (Guest)
on 2008-11-04 16:34
(Received via mailing list)
Hello,

Sometimes when we place expectations on class methods, the class
methods seem to be not available in their previous form for other,
later specs. Calling the class methods in other specs result in a no
method error. We commonly find this happening when model specs run
after controller specs - the Model.find expectations in controller
specs make Model.find actual calls in model specs result in errors.
Running them in reverse removes the errors.

I'm wondering if I'm using RSpec wrong, or if it's a bug. My
assumption is that after the example group in which the expectation
has been placed, the original functionality of the class is restored.
That's supposed to be the function of of Proxy#reset_proxied_methods,
if I'm understanding the RSpec source correctly.

Here's a link to a minimal, standalone, example of what I'm talking
about, although it deals with define_method instead of find. The
output we get when running the specs is in the pastie at the bottom,
commented out.

http://gist.github.com/22144

It's extracted from a Rails app but has been modified to be run on
it's own, with no external dependencies or configuration. The error
happens under 1.1.11 and also edge RSpec from github. We are seeing it
on Mac 10.5 and also Ubuntu 8.04.

jlindley@Hypatia:~/sites/cpi2/spec/models(master)$ spec -v
rspec 1.1.11

jlindley@Hypatia:~/sites/cpi2/spec/models(master)$ ruby -v
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]

Thanks!

Jim Lindley
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-11-04 16:40
(Received via mailing list)
On Tue, Nov 4, 2008 at 9:32 AM, Jim Lindley <jimlindley@gmail.com>
wrote:
> I'm wondering if I'm using RSpec wrong, or if it's a bug. My
> http://gist.github.com/22144
> ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
>
> Thanks!
>
> Jim Lindley

Hey Jim - I think this is related to this:

http://rspec.lighthouseapp.com/projects/5645/tickets/589

Would you kindly add your comments to that ticket?

Thanks,
David
315035a47dcb93f4427b8a1e18da4ff7?d=identicon&s=25 Jim Lindley (Guest)
on 2008-11-04 16:58
(Received via mailing list)
> Hey Jim - I think this is related to this:
>
> http://rspec.lighthouseapp.com/projects/5645/tickets/589
>
> Would you kindly add your comments to that ticket?
>

I updated the ticket, thanks David! I also changed the title to
something more general then the existing case implied. It's not just
Kernel that's affected in our case.
315035a47dcb93f4427b8a1e18da4ff7?d=identicon&s=25 Jim Lindley (Guest)
on 2008-11-05 01:58
(Received via mailing list)
I have created an updated example, the issue I am seeing happens when
any method has been included into a class from a module. It doesn't
get re-added like methods that have been inherited or added directly
to a class are.

http://gist.github.com/22159

I've updated the ticket as well, but I think it's a separate issue
then the original ticket you directed me to.

Thanks,

Jim
This topic is locked and can not be replied to.