[rspec-users] expecting one of two conditions

Adam Sroka adam.sroka at gmail.com
Sun Mar 10 00:24:40 UTC 2013

It depends on what you really mean:

1) If you care that it is either OneError or OtherError, then these are two
separate scenarios and should be written as such.

2) If you don't care which one it is, then you probably just be less
specific. Is there a common message they respond to that you could check

3) If you care which error you are getting, but you don't want to have to
check for each one, then you might consider wrapping the error with
something easier to inspect.

There are probably a number of other good answers too, depending on which
smell is bugging you the most.

On Sat, Mar 9, 2013 at 3:20 PM, Fearless Fool <lists at ruby-forum.com> wrote:

> I'm expecting my_test to raise one error or another, but since I'm
> pulling data from a db, I don't know which error it will be.  Is there a
> better way to write this?
> expect { my_test }.to raise_error { |error|
>   error.should satisfy {|e|
>     e.instance_of?(OneError) || e.instance_of?(OtherError)
>   }
> }
> ?
> I'm not complaining, mind you -- I'm really impressed that RSpec lets me
> test for such specific pathology!  I'm just wondering if there's another
> matcher that won't be quite so verbose.
> - ff
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130309/b92517c4/attachment-0001.html>

More information about the rspec-users mailing list