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

Fearless Fool lists at ruby-forum.com
Thu Jan 12 19:32:46 EST 2012


I have two blocks of tests: one for testing positive outcomes and one
for testing negative.  After poking around, I've concluded that the
underlying :verify_credentials method is getting called, despite the
stub:

  describe 'electricity credentials' do
    before(:each) do
      @wizard.electricity_service = MeteredService::Base.create!()
    end

      it 'with valid credentials should spawn external loader' do
        @wizard.electricity_service.stub(:verify_credentials).and_return(true)
        @wizard.electricity_loader.stub(:start)
        @wizard.electricity_loader.should_receive(:start)
        @wizard.validate_setting_electricity_credentials
      end

      it 'with invalid credentials should not spawn external loader' do
        @wizard.electricity_service.stub(:verify_credentials).and_raise('no
can do')
        @wizard.electricity_loader.stub(:start)
        @wizard.electricity_loader.should_not_receive(:start)
        @wizard.validate_setting_electricity_credentials
      end

    end

Am I missing something fundamental about .stub()?

- ff

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


More information about the rspec-users mailing list