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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/dd9d8127/attachment.html
On 7/25/07, Daniel N <has.sox at gmail.com> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/4f74b415/attachment-0001.html
On 7/24/07, Daniel N <has.sox at gmail.com> wrote:> > > On 7/25/07, Daniel N <has.sox at gmail.com> 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?Absolutely not. Please submit a bug report to the tracker on this, with the examples you have here. http://rubyforge.org/tracker/index.php?group_id=797 Thanks, David> > Cheers > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 7/25/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 7/24/07, Daniel N <has.sox at gmail.com> wrote: > > > > > > On 7/25/07, Daniel N <has.sox at gmail.com> 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? > > Absolutely not. Please submit a bug report to the tracker on this, > with the examples you have here. > > http://rubyforge.org/tracker/index.php?group_id=797 > > Thanks, > DavidDone -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/74ed489c/attachment.html
On 7/24/07, Daniel N <has.sox at gmail.com> wrote:> > > > On 7/25/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 7/24/07, Daniel N <has.sox at gmail.com> wrote: > > > > > > > > > On 7/25/07, Daniel N <has.sox at gmail.com> 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? > > > > Absolutely not. Please submit a bug report to the tracker on this, > > with the examples you have here. > > > > http://rubyforge.org/tracker/index.php?group_id=797 > > > > Thanks, > > David > > DoneThanks> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >