Skip to content

Commit

Permalink
Extract host context of system specs into a test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Dec 22, 2023
1 parent c0449d8 commit 7266297
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end

RSpec.configure do |config|
config.include ServicesTestHelper, type: :system

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_paths = [Rails.root.join("spec/fixtures")]

Expand Down
9 changes: 9 additions & 0 deletions spec/support/services_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ServicesTestHelper
def given_i_am_on_the_claims_site
Capybara.app_host = "http://#{ENV["CLAIMS_HOST"]}"
end

def given_i_am_on_the_placements_site
Capybara.app_host = "http://#{ENV["PLACEMENTS_HOST"]}"
end
end
22 changes: 1 addition & 21 deletions spec/system/home_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
require "rails_helper"

RSpec.feature "Home Page" do
after { Capybara.app_host = nil }

RSpec.describe "Home Page", type: :system do
scenario "User visits the claims homepage" do
given_i_am_on_the_claims_site
and_i_am_on_the_start_page
i_can_see_the_claims_service_name_in_the_header
and_i_can_see_the_claims_service_value_in_the_page
end

scenario "User visits the placements homepage" do
given_i_am_on_the_placements_site
and_i_am_on_the_start_page
i_can_see_the_placements_service_name_in_the_header
and_i_can_see_the_placements_service_value_in_the_page
end

private

def given_i_am_on_the_claims_site
Capybara.app_host = "http://#{ENV["CLAIMS_HOST"]}"
end

def given_i_am_on_the_placements_site
Capybara.app_host = "http://#{ENV["PLACEMENTS_HOST"]}"
end

def and_i_am_on_the_start_page
visit "/"
end
Expand All @@ -42,12 +30,4 @@ def i_can_see_the_placements_service_name_in_the_header
expect(page).to have_content("Manage School Placements")
end
end

def and_i_can_see_the_claims_service_value_in_the_page
expect(page).to have_css(".govuk-summary-list__value", text: "Claims")
end

def and_i_can_see_the_placements_service_value_in_the_page
expect(page).to have_css(".govuk-summary-list__value", text: "Placements")
end
end
12 changes: 1 addition & 11 deletions spec/system/service_updates_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "rails_helper"

RSpec.feature "Service updates page" do
after { Capybara.app_host = nil }

RSpec.describe "Service updates page", type: :system do
scenario "User visits the claims Service updates" do
given_i_am_on_the_claims_site
and_i_am_on_the_service_updates_page
Expand All @@ -17,14 +15,6 @@

private

def given_i_am_on_the_claims_site
Capybara.app_host = "http://#{ENV["CLAIMS_HOST"]}"
end

def given_i_am_on_the_placements_site
Capybara.app_host = "http://#{ENV["PLACEMENTS_HOST"]}"
end

def and_i_am_on_the_service_updates_page
visit "/service_updates"
end
Expand Down

0 comments on commit 7266297

Please sign in to comment.