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

aslak hellesoy aslak.hellesoy at gmail.com
Wed Feb 28 16:27:48 EST 2007


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
>


More information about the rspec-users mailing list