[rspec-users] stub().and_raise() ain't raising?

Fearless Fool lists at ruby-forum.com
Fri Jan 13 00:18:02 EST 2012

Justin Ko wrote in post #1040632:
> What are the failed expectations? Just paste it.

You've identified the problem (see below), but to answer your question:

  1) Wizard electricity credentials with valid credentials should spawn 
external loader
     Failure/Error: @wizard.electricity_loader.should_receive(:start)
       (#<Wizard::ElectricityLoader:0x000001029bc140>).start(any args)
           expected: 1 time
           received: 0 times
     # ./spec/models/wizard_spec.rb:181:in `block (4 levels) in <top 

> Are you sure that @wizard.electricity_service is returning the same
> object on each call? If a database call is being made, there's a good
> chance it is returning a different object (which has not mocks).

Ah!  I think that's the culprit -- @wizard.electricity_service invokes a 
db call:

class Wizard < ActiveRecord::Base
  def electricity_service
    premise.metered_services.where(:natural_resource_id => 

It seems obvious now that you point it out.  So in rspec-land, what's 
the stylistically appropriate way to test this?  Stub .any_class()?

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list