1

Cucumberの使用中にユーザーが作成されなかったことをどのように主張しますか?RSpecでは、次のブロックを使用しますが、これは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
4

3 に答える 3

2

この例では、ユーザーが使用する電子メールがわかっているので、次のことができます。

Then /^an account should not be created$/ do
  User.where(email: "youremail@example.com").first.should be_nil
end
于 2012-10-02T19:13:53.073 に答える
2

あなたもすることができます

Given I have 3 users
When I submit with invalid information
Then I should have 3 users
于 2012-10-02T19:38:21.927 に答える
1

回避策に頼るのではなく、ラムダを使用してRSpecテストを直接変換できます。

Then /^an account should not be created$/ do
  save = lambda { click_button :submit }
  expect(save).not_to change(User, :count)
end
于 2014-09-30T07:28:47.033 に答える