Use assert_content instead of assert page.has_content?

The assert_content comes from capybara, and gives a much more helpful
error message if the test fails.
This commit is contained in:
Andy Allan 2022-01-06 13:16:47 +00:00
parent 89d9690982
commit d257c21740
10 changed files with 72 additions and 72 deletions

View file

@ -20,7 +20,7 @@ class ConfirmationResendSystemTest < ApplicationSystemTestCase
test "flash message should not contain raw html" do test "flash message should not contain raw html" do
visit user_confirm_resend_path(@user) visit user_confirm_resend_path(@user)
assert page.has_content?("sent a new confirmation") assert_content "sent a new confirmation"
assert_not page.has_content?("<p>") assert_no_content "<p>"
end end
end end

View file

@ -12,7 +12,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
click_on "Send a message to the author" click_on "Send a message to the author"
assert page.has_content? "Send a new message" assert_content "Send a new message"
assert_equal "Re: #{@diary_entry.title}", page.find_field("Subject").value assert_equal "Re: #{@diary_entry.title}", page.find_field("Subject").value
end end
@ -22,7 +22,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
sign_in_as(create(:user)) sign_in_as(create(:user))
visit diary_entries_path visit diary_entries_path
assert_not page.has_content? @deleted_entry.title assert_no_content @deleted_entry.title
end end
test "deleted diary entries should be shown to administrators for review" do test "deleted diary entries should be shown to administrators for review" do
@ -31,7 +31,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
sign_in_as(create(:administrator_user)) sign_in_as(create(:administrator_user))
visit diary_entries_path visit diary_entries_path
assert page.has_content? @deleted_entry.title assert_content @deleted_entry.title
end end
test "deleted diary entries should not be shown to admins when the user is also deleted" do test "deleted diary entries should not be shown to admins when the user is also deleted" do
@ -41,7 +41,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
sign_in_as(create(:administrator_user)) sign_in_as(create(:administrator_user))
visit diary_entries_path visit diary_entries_path
assert_not page.has_content? @deleted_entry.title assert_no_content @deleted_entry.title
end end
test "deleted diary comments should be hidden for regular users" do test "deleted diary comments should be hidden for regular users" do
@ -50,7 +50,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
sign_in_as(create(:user)) sign_in_as(create(:user))
visit diary_entry_path(@diary_entry.user, @diary_entry) visit diary_entry_path(@diary_entry.user, @diary_entry)
assert_not page.has_content? @deleted_comment.body assert_no_content @deleted_comment.body
end end
test "deleted diary comments should be shown to administrators" do test "deleted diary comments should be shown to administrators" do
@ -59,6 +59,6 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase
sign_in_as(create(:administrator_user)) sign_in_as(create(:administrator_user))
visit diary_entry_path(@diary_entry.user, @diary_entry) visit diary_entry_path(@diary_entry.user, @diary_entry)
assert page.has_content? @deleted_comment.body assert_content @deleted_comment.body
end end
end end

View file

@ -5,21 +5,21 @@ class IssuesTest < ApplicationSystemTestCase
def test_view_issues_not_logged_in def test_view_issues_not_logged_in
visit issues_path visit issues_path
assert page.has_content?(I18n.t("sessions.new.title")) assert_content I18n.t("sessions.new.title")
end end
def test_view_issues_normal_user def test_view_issues_normal_user
sign_in_as(create(:user)) sign_in_as(create(:user))
visit issues_path visit issues_path
assert page.has_content?("Forbidden") assert_content "Forbidden"
end end
def test_view_no_issues def test_view_no_issues
sign_in_as(create(:moderator_user)) sign_in_as(create(:moderator_user))
visit issues_path visit issues_path
assert page.has_content?(I18n.t("issues.index.issues_not_found")) assert_content I18n.t("issues.index.issues_not_found")
end end
def test_view_issues def test_view_issues
@ -27,7 +27,7 @@ class IssuesTest < ApplicationSystemTestCase
issues = create_list(:issue, 3, :assigned_role => "moderator") issues = create_list(:issue, 3, :assigned_role => "moderator")
visit issues_path visit issues_path
assert page.has_content?(issues.first.reported_user.display_name) assert_content issues.first.reported_user.display_name
end end
def test_view_issues_with_no_reported_user def test_view_issues_with_no_reported_user
@ -36,10 +36,10 @@ class IssuesTest < ApplicationSystemTestCase
issue = create(:issue, :reportable => anonymous_note, :assigned_role => "moderator") issue = create(:issue, :reportable => anonymous_note, :assigned_role => "moderator")
visit issues_path visit issues_path
assert page.has_content?(reportable_title(anonymous_note)) assert_content reportable_title(anonymous_note)
visit issue_path(issue) visit issue_path(issue)
assert page.has_content?(reportable_title(anonymous_note)) assert_content reportable_title(anonymous_note)
end end
def test_search_issues_by_user def test_search_issues_by_user
@ -53,22 +53,22 @@ class IssuesTest < ApplicationSystemTestCase
visit issues_path visit issues_path
fill_in "search_by_user", :with => good_user.display_name fill_in "search_by_user", :with => good_user.display_name
click_on "Search" click_on "Search"
assert_not page.has_content?(I18n.t("issues.index.user_not_found")) assert_no_content I18n.t("issues.index.user_not_found")
assert page.has_content?(I18n.t("issues.index.issues_not_found")) assert_content I18n.t("issues.index.issues_not_found")
# User doesn't exist # User doesn't exist
visit issues_path visit issues_path
fill_in "search_by_user", :with => "Nonexistent User" fill_in "search_by_user", :with => "Nonexistent User"
click_on "Search" click_on "Search"
assert page.has_content?(I18n.t("issues.index.user_not_found")) assert_content I18n.t("issues.index.user_not_found")
assert page.has_content?(I18n.t("issues.index.issues_not_found")) assert_content I18n.t("issues.index.issues_not_found")
# Find Issue against bad_user # Find Issue against bad_user
visit issues_path visit issues_path
fill_in "search_by_user", :with => bad_user.display_name fill_in "search_by_user", :with => bad_user.display_name
click_on "Search" click_on "Search"
assert_not page.has_content?(I18n.t("issues.index.user_not_found")) assert_no_content I18n.t("issues.index.user_not_found")
assert_not page.has_content?(I18n.t("issues.index.issues_not_found")) assert_no_content I18n.t("issues.index.issues_not_found")
end end
def test_commenting def test_commenting
@ -79,8 +79,8 @@ class IssuesTest < ApplicationSystemTestCase
fill_in :issue_comment_body, :with => "test comment" fill_in :issue_comment_body, :with => "test comment"
click_on "Add Comment" click_on "Add Comment"
assert page.has_content?(I18n.t("issue_comments.create.comment_created")) assert_content I18n.t("issue_comments.create.comment_created")
assert page.has_content?("test comment") assert_content "test comment"
issue.reload issue.reload
assert_equal("test comment", issue.comments.first.body) assert_equal("test comment", issue.comments.first.body)

View file

@ -7,7 +7,7 @@ class PreferencesTest < ApplicationSystemTestCase
visit edit_preferences_path visit edit_preferences_path
click_on "Update Preferences" click_on "Update Preferences"
assert page.has_content?("Preferences updated") assert_content "Preferences updated"
end end
def test_flash_message_shows_in_new_language def test_flash_message_shows_in_new_language
@ -17,6 +17,6 @@ class PreferencesTest < ApplicationSystemTestCase
fill_in "Preferred Languages", :with => "fr" fill_in "Preferred Languages", :with => "fr"
click_on "Update Preferences" click_on "Update Preferences"
assert page.has_content?("Préférences mises à jour") assert_content "Préférences mises à jour"
end end
end end

View file

@ -9,19 +9,19 @@ class ReportDiaryCommentTest < ApplicationSystemTestCase
def test_no_link_when_not_logged_in def test_no_link_when_not_logged_in
visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
assert page.has_content?(@comment.body) assert_content @comment.body
assert_not page.has_content?(I18n.t("diary_entries.diary_comment.report")) assert_no_content I18n.t("diary_entries.diary_comment.report")
end end
def test_it_works def test_it_works
sign_in_as(create(:user)) sign_in_as(create(:user))
visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
assert page.has_content? @diary_entry.title assert_content @diary_entry.title
click_on I18n.t("diary_entries.diary_comment.report") click_on I18n.t("diary_entries.diary_comment.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.diary_comment.spam_label") choose I18n.t("reports.new.categories.diary_comment.spam_label")
fill_in "report_details", :with => "This comment is spam" fill_in "report_details", :with => "This comment is spam"
@ -29,7 +29,7 @@ class ReportDiaryCommentTest < ApplicationSystemTestCase
click_on "Create Report" click_on "Create Report"
end end
assert page.has_content? "Your report has been registered successfully" assert_content "Your report has been registered successfully"
assert_equal @comment, Issue.last.reportable assert_equal @comment, Issue.last.reportable
assert_equal "administrator", Issue.last.assigned_role assert_equal "administrator", Issue.last.assigned_role

View file

@ -8,19 +8,19 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
def test_no_link_when_not_logged_in def test_no_link_when_not_logged_in
visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
assert page.has_content?(@diary_entry.title) assert_content @diary_entry.title
assert_not page.has_content?(I18n.t("diary_entries.diary_entry.report")) assert_no_content I18n.t("diary_entries.diary_entry.report")
end end
def test_it_works def test_it_works
sign_in_as(create(:user)) sign_in_as(create(:user))
visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
assert page.has_content? @diary_entry.title assert_content @diary_entry.title
click_on I18n.t("diary_entries.diary_entry.report") click_on I18n.t("diary_entries.diary_entry.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.diary_entry.spam_label") choose I18n.t("reports.new.categories.diary_entry.spam_label")
fill_in "report_details", :with => "This is advertising" fill_in "report_details", :with => "This is advertising"
@ -28,7 +28,7 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
click_on "Create Report" click_on "Create Report"
end end
assert page.has_content? "Your report has been registered successfully" assert_content "Your report has been registered successfully"
assert_equal @diary_entry, Issue.last.reportable assert_equal @diary_entry, Issue.last.reportable
assert_equal "administrator", Issue.last.assigned_role assert_equal "administrator", Issue.last.assigned_role
@ -40,11 +40,11 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
sign_in_as(create(:user)) sign_in_as(create(:user))
visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
assert page.has_content? @diary_entry.title assert_content @diary_entry.title
click_on I18n.t("diary_entries.diary_entry.report") click_on I18n.t("diary_entries.diary_entry.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.diary_entry.spam_label") choose I18n.t("reports.new.categories.diary_entry.spam_label")
fill_in "report_details", :with => "This is advertising" fill_in "report_details", :with => "This is advertising"
@ -60,6 +60,6 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
def test_missing_report_params def test_missing_report_params
sign_in_as(create(:user)) sign_in_as(create(:user))
visit new_report_path visit new_report_path
assert page.has_content? I18n.t("reports.new.missing_params") assert_content I18n.t("reports.new.missing_params")
end end
end end

View file

@ -4,9 +4,9 @@ class ReportNoteTest < ApplicationSystemTestCase
def test_no_link_when_not_logged_in def test_no_link_when_not_logged_in
note = create(:note_with_comments) note = create(:note_with_comments)
visit browse_note_path(note) visit browse_note_path(note)
assert page.has_content?(note.comments.first.body) assert_content note.comments.first.body
assert_not page.has_content?(I18n.t("browse.note.report")) assert_no_content I18n.t("browse.note.report")
end end
def test_can_report_anonymous_notes def test_can_report_anonymous_notes
@ -15,8 +15,8 @@ class ReportNoteTest < ApplicationSystemTestCase
visit browse_note_path(note) visit browse_note_path(note)
click_on I18n.t("browse.note.report") click_on I18n.t("browse.note.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.note.spam_label") choose I18n.t("reports.new.categories.note.spam_label")
fill_in "report_details", :with => "This is spam" fill_in "report_details", :with => "This is spam"
@ -24,7 +24,7 @@ class ReportNoteTest < ApplicationSystemTestCase
click_on "Create Report" click_on "Create Report"
end end
assert page.has_content? "Your report has been registered successfully" assert_content "Your report has been registered successfully"
assert_equal note, Issue.last.reportable assert_equal note, Issue.last.reportable
assert_equal "moderator", Issue.last.assigned_role assert_equal "moderator", Issue.last.assigned_role
@ -36,8 +36,8 @@ class ReportNoteTest < ApplicationSystemTestCase
visit browse_note_path(note) visit browse_note_path(note)
click_on I18n.t("browse.note.report") click_on I18n.t("browse.note.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.note.spam_label") choose I18n.t("reports.new.categories.note.spam_label")
fill_in "report_details", :with => "This is spam" fill_in "report_details", :with => "This is spam"
@ -45,7 +45,7 @@ class ReportNoteTest < ApplicationSystemTestCase
click_on "Create Report" click_on "Create Report"
end end
assert page.has_content? "Your report has been registered successfully" assert_content "Your report has been registered successfully"
assert_equal note, Issue.last.reportable assert_equal note, Issue.last.reportable
assert_equal "moderator", Issue.last.assigned_role assert_equal "moderator", Issue.last.assigned_role

View file

@ -4,9 +4,9 @@ class ReportUserTest < ApplicationSystemTestCase
def test_no_link_when_not_logged_in def test_no_link_when_not_logged_in
note = create(:note_with_comments) note = create(:note_with_comments)
visit browse_note_path(note) visit browse_note_path(note)
assert page.has_content?(note.comments.first.body) assert_content note.comments.first.body
assert_not page.has_content?(I18n.t("users.show.report")) assert_no_content I18n.t("users.show.report")
end end
def test_can_report_user def test_can_report_user
@ -15,8 +15,8 @@ class ReportUserTest < ApplicationSystemTestCase
visit user_path(user) visit user_path(user)
click_on I18n.t("users.show.report") click_on I18n.t("users.show.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.user.vandal_label") choose I18n.t("reports.new.categories.user.vandal_label")
fill_in "report_details", :with => "This user is a vandal" fill_in "report_details", :with => "This user is a vandal"
@ -24,7 +24,7 @@ class ReportUserTest < ApplicationSystemTestCase
click_on "Create Report" click_on "Create Report"
end end
assert page.has_content? "Your report has been registered successfully" assert_content "Your report has been registered successfully"
assert_equal user, Issue.last.reportable assert_equal user, Issue.last.reportable
assert_equal "moderator", Issue.last.assigned_role assert_equal "moderator", Issue.last.assigned_role
@ -36,8 +36,8 @@ class ReportUserTest < ApplicationSystemTestCase
visit user_path(user) visit user_path(user)
click_on I18n.t("users.show.report") click_on I18n.t("users.show.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.user.vandal_label") choose I18n.t("reports.new.categories.user.vandal_label")
fill_in "report_details", :with => "This user is a vandal" fill_in "report_details", :with => "This user is a vandal"
@ -45,7 +45,7 @@ class ReportUserTest < ApplicationSystemTestCase
click_on "Create Report" click_on "Create Report"
end end
assert page.has_content? "Your report has been registered successfully" assert_content "Your report has been registered successfully"
assert_equal user, Issue.last.reportable assert_equal user, Issue.last.reportable
assert_equal "moderator", Issue.last.assigned_role assert_equal "moderator", Issue.last.assigned_role
@ -53,8 +53,8 @@ class ReportUserTest < ApplicationSystemTestCase
visit user_path(user) visit user_path(user)
click_on I18n.t("users.show.report") click_on I18n.t("users.show.report")
assert page.has_content? "Report" assert_content "Report"
assert page.has_content? I18n.t("reports.new.disclaimer.intro") assert_content I18n.t("reports.new.disclaimer.intro")
choose I18n.t("reports.new.categories.user.spam_label") choose I18n.t("reports.new.categories.user.spam_label")
fill_in "report_details", :with => "This user is a spammer" fill_in "report_details", :with => "This user is a spammer"
@ -62,7 +62,7 @@ class ReportUserTest < ApplicationSystemTestCase
click_on "Create Report" click_on "Create Report"
end end
assert page.has_content? "Your report has been registered successfully" assert_content "Your report has been registered successfully"
assert_equal user, Issue.last.reportable assert_equal user, Issue.last.reportable
assert_equal "administrator", Issue.last.assigned_role assert_equal "administrator", Issue.last.assigned_role

View file

@ -4,45 +4,45 @@ class UserLogoutTest < ApplicationSystemTestCase
test "Sign out via link" do test "Sign out via link" do
user = create(:user) user = create(:user)
sign_in_as(user) sign_in_as(user)
assert_not page.has_content? "Log In" assert_no_content "Log In"
click_on user.display_name click_on user.display_name
click_on "Log Out" click_on "Log Out"
assert page.has_content? "Log In" assert_content "Log In"
end end
test "Sign out via link with referer" do test "Sign out via link with referer" do
user = create(:user) user = create(:user)
sign_in_as(user) sign_in_as(user)
visit traces_path visit traces_path
assert_not page.has_content? "Log In" assert_no_content "Log In"
click_on user.display_name click_on user.display_name
click_on "Log Out" click_on "Log Out"
assert page.has_content? "Log In" assert_content "Log In"
assert page.has_content? "Public GPS Traces" assert_content "Public GPS Traces"
end end
test "Sign out via fallback page" do test "Sign out via fallback page" do
sign_in_as(create(:user)) sign_in_as(create(:user))
assert_not page.has_content? "Log In" assert_no_content "Log In"
visit logout_path visit logout_path
assert page.has_content? "Logout from OpenStreetMap" assert_content "Logout from OpenStreetMap"
click_button "Logout" click_button "Logout"
assert page.has_content? "Log In" assert_content "Log In"
end end
test "Sign out via fallback page with referer" do test "Sign out via fallback page with referer" do
sign_in_as(create(:user)) sign_in_as(create(:user))
assert_not page.has_content? "Log In" assert_no_content "Log In"
visit logout_path(:referer => "/traces") visit logout_path(:referer => "/traces")
assert page.has_content? "Logout from OpenStreetMap" assert_content "Logout from OpenStreetMap"
click_button "Logout" click_button "Logout"
assert page.has_content? "Log In" assert_content "Log In"
assert page.has_content? "Public GPS Traces" assert_content "Public GPS Traces"
end end
end end

View file

@ -6,6 +6,6 @@ class UserSignupTest < ApplicationSystemTestCase
click_on "Register now" click_on "Register now"
assert page.has_content? "Confirm Password" assert_content "Confirm Password"
end end
end end