OK... I know the problem now:

My spec_helper.rb was configured with:
config.mock_with :rspec

and a controller_spec is using
Postcard.any_instance.stubs(:valid?).returns(true)

Obviously this stub wasn't properly reset after that one controller
spec, that uses it. So it screwed up my Postcard specs. I switched to
using mocha now, and all tests pass as expected.

But one question remains: Why didn't this stub get reseted
automatically after each spec?

On 12 Jan., 09:39, Dennis Schmidt <[email protected]> wrote:
> On 12 Jan., 04:05, Nick <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > On Tuesday, January 11, 2011 6:23:07 AM UTC-5, Dennis Schmidt wrote:
>
> > > # postcard_spec.rb
> > > require File.dirname(__FILE__) + '/../spec_helper'
> > > describe Postcard do
> > >   it {should validate_presence_of(:text)}
> > >   it "should validate presence of text" do
> > >     p = Postcard.new
> > >     p.save!
> > >     p.errors.include?(:text).should be_true
> > >   end
> > > end
>
> > If you use the non-bang version of save, the spec passes. IE:
> >     p.save
> > instead of
> >     p.save!
>
> It makes no difference, whether I use the bang or the non-bang
> version. Both ways it fails. Especially the shoulda spec one-line test
> should work, but doesn't. And as I said, the strangest thing of all
> is, that the test works as expected (passes) if I put it in any
> controller spec for instance (not the shoulda one, of course). So my
> code must be correct (since rails itself works as expected and the
> console works as expected) BUT only this very spec in that spec file
> doesn't work at all. And that's the thing, I have absolutely NO clue
> at all, what might be the reason for that. To me, it looks like a bug
> in some of the components I'm using or their interaction. But then, it
> is such a simple test, I can hardly believe a bug like this would slip
> through undetected. So yeah... any further suggestions?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to