[rspec-users] expecting one of two conditions

Matt Wynne matt at mattwynne.net
Sun Mar 10 14:59:45 UTC 2013

On 10 Mar 2013, at 02:04, Robert Poor <rdpoor at gmail.com> wrote:

> On Sat, 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. 
> I don't care which error I'm getting, so suggestion 2) works.  The errors I expect are within a specific module (UpdateOrInsert::), so I could simply check for that.  Not sure how do to that short of parsing the class name string (e.g. error_class.name.split("::")), but I'm not sure that is less smelly than the code I already have.
> I'll contemplate 3), which could make life easer.  Thanks!

Could you give both errors a common base class, then assert on that?


http://mattwynne.net || https://twitter.com/mattwynne || http://the-cucumber-book.com || http://bddkickstart.com || http://www.relishapp.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130310/5fe8e727/attachment-0001.html>

More information about the rspec-users mailing list