KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Scenario I'm writing a library (no Ruby on Rails) for which I'd like to have very detailed Cucumber features. This especially includes describing errors/exceptions that should be thrown in various cases. Example The most intuitive way to write the Cucumber steps would probably be something like When I do something unwanted Then an "ArgumentError" should be thrown Problem There are two issues I have to address: The first step should not fail when an exception is thrown. The exception that the first step throws should be accessible to the second step in order to do some assertion magic. Unelegant And Cumbersome Solution The best approach I've been able to come up with is caching the exception in the first step and putting it into an instance variable that the second step can access, like so: When /^I do something unwanted$/ do begin throw_an_exception! rescue => @error end end Then /^an "(.*)" should be thrown$/ do |error| @error.class.to_s.should == error end However, this makes the first step more or less useless in cases where I don't want it to fail, and it requires an instance variable, which is never a good thing. So, can anyone help me out with an at least less cumbersome solution? Or should I write my features differently anyway? Any help would be much appreciated.
Tags (comma-separated)
Save Edits
Cancel