[rspec-users] Mysterious interaction between RSpec 1.1.4 and has_finder/named_scope

Rick DeNatale rick.denatale at gmail.com
Thu Jun 12 17:25:47 EDT 2008


I just opened a Rails ticket on a problem with named_scope in Rails 2.1, and
cross-posted a message here which I send to rails-core.

I'm still a bit mystified, because I'm having a problem caused by this on
RSpec 1.1.4, but not on 1.1.3, and I don't see a difference in code which
would explain it.

The basic problem, which I encountered upgrading our rails app to RSpec
1.1.4 was a case like this:

class SpaceFile < ActiveRecord::Base
   named_scope :public
   ...
end

In a spec I have code like this:
   ...
11:    model = Model.new
12:   model.stub!(:path).and_return("x/y")

NoMethodError in 'SpaceFile be readable'
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.call
/Users/rick/near-time/near-time.net-exp-migrate-to-rspec-1-1-4-6750/spec/models/space_file_spec.rb:12:

What's happening is when Spec::Mocks::Proxy.define_expected_method uses
class_eval to define the stub method, Ruby is calling public under the
covers but instead of getting the standard method which makes the method
public, it ends up calling the method generated by the named_scope method
which tries to get a proc from an empty hash, and ends up trying to send
call to nil.

What I can't figure out is why this is failing under RSpec 1.1.4, but it
doesn't fail under 1.1.3, the code I've looked at doesn't seem to have
changed.  Any ideas?

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080612/75c49295/attachment-0001.html>


More information about the rspec-users mailing list