[rspec-users] autospec fails but rake spec tasks pass (solution)

David Chelimsky dchelimsky at gmail.com
Sun Mar 29 12:38:10 EDT 2009

On Sat, Mar 28, 2009 at 11:05 PM, jakepaul <dotjake at gmail.com> wrote:
> I figured out what the problem was. Turns out that the controller specs used
> Mocha's any_instance method to stub valid? and return false (I got this idea
> from a Railscast). Due to the order in which autospec runs the specs,
> editing the model spec was causing it to be run after the controller spec,
> and the Mocha stubs were still being applied in the model specs. I'm not
> sure if I was doing something wrong, if there is some way to 'clear' the
> stubbed methods that would be great, or perhaps I just shouldn't use
> any_instance.

I haven't seen the railscast to which you refer, but if you're using
mocha instead of rspec's mock framework, be sure to configure that in
spec_helper.rb (or anywhere that gets loaded before the specs run):

Spec::Runner.configure do |config|
  config.mock_with :mocha

If you do that, then the mocha stubs and expectations should get
cleared out after each example runs, eliminating the ordering
dependency that is causing you trouble.


> --
> View this message in context: http://www.nabble.com/autospec-fails-but-rake-spec-tasks-pass-tp22746792p22763942.html
> Sent from the rspec-users mailing list archive at Nabble.com.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list