[rspec-users] expecting one of two conditions

Samer Masry samer.masry at gmail.com
Sun Mar 10 02:08:35 UTC 2013


It would be better to split that into two tests that test when each error is raised.


On Mar 9, 2013, at 4:24 PM, Adam Sroka <adam.sroka at gmail.com> wrote:

> 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 for? 
> 
> 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
> 
> _______________________________________________
> 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/63d417a7/attachment.html>


More information about the rspec-users mailing list