I have a negative scenario to test with Cucumber. Specifically, I want to make sure that when someone posts a URL with an invalid handle then the site returns an error.
My scenario looks like:
Scenario: create person with too short a handle When person named "Fred" with handle "tooshort" updates Then I should get a 500 error
My step looks like
When /^person named "(.)" with handle "(.)" updates$/ do |name, handle| visit "/mobile/update?handle=#{udid}&name=#{name}"
When I run the scenario, it never gets to the THEN part because of the error from the When
ERROR: No Handle (RuntimeError)
This is CORRECT, the When should turn a 500 error.
I just don't know how to phrase the When as a negative test. Maybe I should use something different than a when?
If for you the correct behavior of your When step is to raise an error you case use a lambda block to catch this RuntimeError:
You may have to tweak the raise_error part as I don't know exactly the type of error you are raising
And you can have a Then step like this one (starting point)