[rspec-users] NoMethodError dependent on spec order

Jim Lindley jimlindley at gmail.com
Tue Nov 4 10:32:07 EST 2008


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.


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 at Hypatia:~/sites/cpi2/spec/models(master)$ spec -v
rspec 1.1.11

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


Jim Lindley

More information about the rspec-users mailing list