Reputation: 35349
How do I assert that a user was not created while using Cucumber? In RSpec, I would use the following block, which I can not translate to Cucumber:
...
describe "with invalid information" do
it "should not create a new user" do
expect { click_button submit }.not_to change(User, :count)
end
end
# Cucumber equivalent
When /^he submits invalid information$/ do
click_button "Sign up"
end
Then /^an account should not be created$/ do
# not sure how to translate the expect block
end
Upvotes: 1
Views: 158
Reputation: 13800
You can use a lambda to directly translate your RSpec test, rather than rely on a workaround.
Then /^an account should not be created$/ do
save = lambda { click_button :submit }
expect(save).not_to change(User, :count)
end
Upvotes: 1
Reputation: 16720
You could also do
Given I have 3 users
When I submit with invalid information
Then I should have 3 users
Upvotes: 2
Reputation: 40277
In this example, you'll know the email that the user would use, so you could:
Then /^an account should not be created$/ do
User.where(email: "[email protected]").first.should be_nil
end
Upvotes: 2