Skipping callbacks that aren't necessary for what i'm testing

I have an Address model that has a before_validation callback that goes
off and geocodes the address.

I’m concerned that for all the tests in my Address model I’m going to be
triggering that callback, even when it’s not what I’m testing.

Is there a nice way to stub the callback by default for all tests on a
model and then re-enable it for specific tests that are testing the
geocoding functionality.

I’m using Rspec 2.5, Factory Girl and also Shoulda matchers.

Any tips greatly received.

Paul.

Hi,

On Wed, Apr 13, 2011 at 16:56, Paul S. [email protected] wrote:

I have an Address model that has a before_validation callback that goes
off and geocodes the address.

I’m concerned that for all the tests in my Address model I’m going to be
triggering that callback, even when it’s not what I’m testing.

Is there a nice way to stub the callback by default for all tests on a
model and then re-enable it for specific tests that are testing the
geocoding functionality.

If you’re using the RSpec Mocks framework, you can stub the specific
before_validation method in spec_helper.rb, then use unstub![1] in a
before for those specs where you need it.

I’m not sure whether an unstub equivalent is available in other
mocking frameworks.

HTH,
Mike

[1]
http://rubydoc.info/gems/rspec-mocks/2.5.0/RSpec/Mocks/Methods:unstub