Skip to content

Commit

Permalink
introduce with_locale test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly committed May 5, 2024
1 parent 44a44af commit 26dd2df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
end

ENV["DEBUG"] ? driven_by(:chrome) : driven_by(:headless_chrome)

def with_locale(locale)
visit root_path(locale: locale)
yield if block_given?
end
end
6 changes: 4 additions & 2 deletions test/system/home_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class HomePageSystemTest < ApplicationSystemTestCase


test "display the home page in english" do
visit root_path(locale: :en)
with_locale(:en) do
visit root_path

assert_selector "h1", text: "Paris.rb"
assert_selector "h1", text: "Paris.rb"
end
end
end
6 changes: 4 additions & 2 deletions test/system/talks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ class TalksTest < ApplicationSystemTestCase
end

test "visit talks in english" do
visit talks_path(locale: :en)
assert_selector "h1", text: I18n.t("talks.index.lineup", locale: :en)
with_locale(:en) do
visit talks_path
assert_selector "h1", text: I18n.t("talks.index.lineup", locale: :en)
end
end


Expand Down
6 changes: 4 additions & 2 deletions test/system/videos_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class VideosTest < ApplicationSystemTestCase
end

test "visiting the index in english" do
visit videos_url(locale: :en)
assert_selector "h1", text: I18n.t("videos.index.title", locale: :en)
with_locale(:en) do
visit videos_url
assert_selector "h1", text: I18n.t("videos.index.title", locale: :en)
end
end
end

0 comments on commit 26dd2df

Please sign in to comment.