expect(page).to have_css("h3", text: "Expected text here...")
click_button "Submit"
expect(page).to(
have_css("h3", text: "Expected text here..."),
"stay on page on invalid form submit"
)
expect(page).to be_new_user_page
click_button "Submit"
expect(page).to(be_new_user_page, "stay on page on invalid form submit")
...
Add this at the bottom of the *_spec.rb
file, within the feature
block:
require "rails_helper"
feature "..." do
scenario "..." do
...
end
matcher :be_new_user_page do
match_unless_raises do |page|
# Added a path expectation to increase confidence we're on
# the correct page.
expect(page).to have_current_path "/expected/path/here"
expect(page).to have_css "h3", text: "Expected text here..."
end
end
end
Further reading: https://www.wetestrails.com/blog/extract-matcher