[rspec-users] expecting one of two conditions
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@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] expecting one of two conditions
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 li...@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@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] expecting one of two conditions
On Sat, Mar 9, 2013 at 4:24 PM, Adam Sroka adam.sr...@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! ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] expecting one of two conditions
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.sr...@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 li...@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@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] expecting one of two conditions
On Sat, Mar 9, 2013 at 6:08 PM, Samer Masry samer.ma...@gmail.com wrote: It would be better to split that into two tests that test when each error is raised. Except that the specific error that I receive depends on the ordering of the data in the database, which isn't something I control. Hmm -- as I stare at that previous sentence, I detect a broader design smell rather than a specific code smell. I'll go think about this... ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users