You should DRY up your code to minimize duplication. You can move directives you call at the beginning of each test to before
, and extract helper method for the repeated code:
describe "Signup" do
before do
visit signups_path
end
def fill_form(fields = {})
fields.each do |field_name, field_value|
fill_in field_name.to_s.capitalize, with: field_value
end
click_button "Signup"
end
it "informs user of an invalid email" do
fill_form email: ""
expect(page).to have_text("Email can't be blank")
end
it "informs user of an invalid password" do
fill_form email: "test@test.com", password: ""
expect(page).to have_text("Password can't be blank")
end
it "informs user of an invalid credit card" do
fill_form email: "test@test.com",
password: "valid-password",
card: "bogus"
expect(page).to have_text("Card is invalid")
end
end