Thanks John. Yes, I think I'm violating TDA with that merge helper sitting in order.
But, it can't really sit in OrderItem. I think it'll have to sit on the association proxy. And, I'm assuming that would be tested by an integration test? I think your singleton class on the mock would work too, but you're right it is messy. I was wondering if there was something built in. Time to redesign! > From: "John D. Hume" <[EMAIL PROTECTED]> > Reply-To: rspec-users <[email protected]> > Date: Wed, 4 Jun 2008 10:50:45 -0400 > To: rspec-users <[email protected]> > Subject: Re: [rspec-users] Mock with an attributes that has state > > On Wed, Jun 4, 2008 at 9:06 AM, Matthew Lins <[EMAIL PROTECTED]> wrote: >> I realize I could do this differently and just do a should_receive on the >> OrderItem, looking for '+=' or something, but that doesn't feel right. > > I know this isn't what you're looking for, but note that whether you do: > item.quantity = item.quantity + other_item.quantity > or > item.quantity += other_item.quantity > the sequence of calls to item will be the same: first item.quantity, > then item.quantity=, with + being sent to the return value of > item.quantity in between. > > To try and help with what you're actually trying to do, I think you > could define a singleton method on your mocked model. > class << @order_item1 > attr_accessor :quantity > end > but that's smelly. > > It feels to me like the logic for rolling one item into another > belongs in OrderItem. So maybe instead your order spec turns out to be > something like: > @order_item1.should_receive(:merge).with(@order_item4) > If the logic for determining whether to merge also moved into > OrderItem, Order (and its spec) could forget about all the attributes > of OrderItem. > > -hume. > _______________________________________________ > rspec-users mailing list > [email protected] > http://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
