[rspec-users] Specifying that code is called in a block

Matthijs Langenberg mlangenberg at gmail.com
Thu Mar 1 02:44:23 EST 2007


I'm actually interested in the other way around: when do you know the
solution should be receiving a block in a method when writing a
specification? Can anyone give me an example of that?

On 2/28/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> On 2/28/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
> > Not sure if this is possible currently.
> >
> > I have a section of code like this:
> >
> >    ActiveRecord::Base.transaction do
> >      cow.save!
> >      duck.save!
> >      dog.save!
> >    end
> >
> > (Names changed to protect the innocent.)
> >
> > I'd like to specify that the saves run in a transaction.  I can do
> >
> >    ActiveRecord::Base.should_receive(:transaction).and_yield
> >
> > But is there any way to specify that the code is called as above, and
> > not as
> >
> >    cow.save!
> >    ActiveRecord::Base.transaction do
> >      duck.save!
> >    end
> >    dog.save!
> >
>
> You can specify order of messages (method calls) on one object
> (http://rspec.rubyforge.org/documentation/mocks/mocks.html) but not
> between different objects.
>
> I can't help but feeling that if you're specifying behaviour at this
> level of detail you're too specific. You're testing implementation,
> not verifying behaviour.
>
> Aslak
>
> > ?
> >
> > Ta
> > Ashley
> > _______________________________________________
> > 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
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list