[rspec-users] Incorrect wrong number of arguments exception when stubbing find

Michael Xavier nemesisdesign at gmail.com
Mon Sep 13 18:30:39 EDT 2010


I'm working with a subclass of ActiveResource and I came across this
oddity when trying to stub its find method. Occurring with rspec
1.3.0:

The spec code looks like:

[1,2].each {|id|
Hive::CategoryResource.should_receive(:find).with(id).and_raise(ActiveResource::ResourceNotFound)}
Hive::CategoryResource.should_receive(:find).with(3).and_return(gg_parent)
--------------------------------------

The code being called looks like

return Hive::CategoryResource.find(c.hive_category_id).default_weight

--------------------------------------

And the exception looks like:

wrong number of arguments (0 for 1)

/home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/
mocks/message_expectation.rb:113:in `initialize'
/home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/
mocks/message_expectation.rb:113:in `exception'
/home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/
mocks/message_expectation.rb:113:in `raise'
/home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/
mocks/message_expectation.rb:113:in `invoke'
/home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/
mocks/proxy.rb:127:in `invoke_expectation'
/home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/
mocks/proxy.rb:111:in `message_received'
/home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/
mocks/proxy.rb:177:in `find'
/home/michael/Scripts/admin/app/models/category.rb:392:in
`closest_default_weight'
/home/michael/Scripts/admin/app/models/category.rb:389:in `each'
/home/michael/Scripts/admin/app/models/category.rb:389:in
`closest_default_weight'
./spec/models/category_spec.rb:209

--------------------------------------

I was hoping someone could help me figure out what's going on here.
It's making an area of my code particularly hard to test


More information about the rspec-users mailing list