[rspec-users] Mock objects not getting unloaded between specs
nate at nateclark.com
Mon Feb 4 19:54:41 EST 2008
David, thanks for getting back.
Here is the pastie with (hopefully) all the relevant code:
We're using the latest and greatest Rspec 1.1.3, so I don't think it's old
versions that is the problem.
Through some debugging, I have determined that in fact my
"paginate_by_tag_set" method is never getting called in the model spec
example as long as the section_controller spec is run first. If I run the
model spec alone, or before the controller spec where the mock is defined,
it works fine.
On Feb 4, 2008 1:07 PM, David Chelimsky <dchelimsky at gmail.com> wrote:
> On Feb 4, 2008 2:51 PM, Nate Clark <nate at nateclark.com> wrote:
> > I'm having a frustrating experience with a mock object in one example (a
> > Rails controller test) interfering with an actual model test in a
> > model example. More specifically, I have
> > spec/controllers/section_controller_spec.rb with a mock call like this
> > one of the examples:
> > Section.should_receive(:paginate_by_tag_set).with(, :page =>
> > nil).and_return()
> > Ok, everything is fine so far. The mock does what it is supposed to and
> > example succeeds.
> > Later on, I have a model spec in spec/models/section_spec.rb that
> > tests the functionality of this "paginate_by_tag_set" class method, like
> > this:
> > Section.paginate_by_tag_set(, :page => nil).total_entries.should == 19
> > This model example fails, and I've determined that the code for my
> > paginate_by_tag_set class method is never even getting called in this
> > example. It seems to have something to do with the order in which my
> > are run ... whenever I run the controller test before the model tests,
> > model example fails, presumably because the mocked call to
> > paginate_by_tag_set is still living, and the actual code isn't getting
> > called.
> This was a bug a long time ago (probably a year), so unless you're on
> a very old version I doubt it's related. What version of rspec are you
> Also - can you pastie the spec and code for this controller? It would
> help to see what else is going on that might be leading to this.
> > If I run spec spec/models/section_spec.rb individually, everything
> > just fine.
> > Any ideas on how to isolate the mock to live only within the test in
> > it is defined? Am I understanding something wrong here?
> > Thanks,
> > Nate
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> rspec-users mailing list
> rspec-users at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users