On 7/25/07, Daniel N <[EMAIL PROTECTED]> wrote:
I'm trying to test some code that has validates each and I've got a very strange failure Mock 'Book_1027' expected :store_with_privacy? with (#<Clip:0x1a99b96 @name="Clip_1025">) but received it with (#<Clip:0x1a99b96 @name="Clip_1025">) The Spec it "should check that a book can save a clip" do @user = mock_model( User, :id => 3 ) @clip = mock_model( Clip, :id => 1, :privacy => :public, :user => @user ) @book = mock_model( Book, :id => 2, :privacy => :public, :user => @user, :user_id => @user.id ) @book.should_receive( :store_with_privacy? ).with( @clip ) clipping = Clipping.new( valid_clipping_attributes.with( :clip => @clip, :book => @book ) ) clipping.valid? end And the model class Clipping < AR:B belongs_to :clip belongs_to :book ... validates_each :clip do |model, attr, value| if !model.book.nil? && !model.clip.nil? if !model.book.store_with_privacy?( model.clip ) model.errors.add( :clip, "You can't add this item to this book" ) end end end ... end Any thoughts on what might be causing that? Cheers Daniel
I've also found that by stubbing the @book.store_with_privacy? in a before block, and then having an example that just mocks that method @book.should_receive( :store_with_privacy? ).with( @clip ) makes it act differently. In this case I get Mock 'Book_1026' expected :store_with_privacy? with (#<Clip:0x1a92aee @name="Clip_1025">) once, but received it 0 times It seems that the stub is taking precedence over the should_receive call. Is this expected behaviour? Cheers Daniel
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users