On Sep 13, 2010, at 5:30 PM, Michael Xavier wrote:
> 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)}
ActiveResource::ResourceNotFound.new requires arguments, so you have to pass
in an instance instead.
http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Mocks/BaseExpectation.html#M000072
Maybe we just need a better error message.
HTH,
David
> 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
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users