Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rspec rubocop #30

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
inherit_gem:
rubocop-govuk:
- config/default.yml
- config/rspec.yml

inherit_mode:
merge:
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/recruitment_banner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
allow(YAML).to receive(:load_file).with(original_path).and_return(replacement_file)
end

context "getting a path with the banner partial" do
context "when visiting a path with the banner partial" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(__dir__, "../../spec/fixtures/requests_banners.yml"))
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
RSpec.describe GovukWebBanners::RecruitmentBanner do
let(:fixtures_dir) { Rails.root.join(__dir__, "../../fixtures/") }

before do
original_path = Rails.root.join(__dir__, described_class::BANNER_CONFIG_FILE)
original_path = Rails.root.join(__dir__, "../", described_class::BANNER_CONFIG_FILE)
allow(YAML).to receive(:load_file).with(original_path).and_return(replacement_file)
end

describe ".for_path" do
context "with banners" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(__dir__, "../../spec/fixtures/active_recruitment_banners.yml"))
YAML.load_file(Rails.root.join(fixtures_dir, "active_recruitment_banners.yml"))
end

it "returns banner that includes the path" do
Expand All @@ -21,12 +23,12 @@

context "with timed banners" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(__dir__, "../../spec/fixtures/timed_recruitment_banners.yml"))
YAML.load_file(Rails.root.join(fixtures_dir, "timed_recruitment_banners.yml"))
end

after { travel_back }

context "Before timed banners are active" do
context "but before timed banners are active" do
before { travel_to Time.local(2024, 12, 31) }

it "finds only banners with no start time" do
Expand All @@ -37,7 +39,7 @@
end
end

context "The day banners 1 and 3 become active and banner 2 ends" do
context "and on the day banners 1 and 3 become active and banner 2 ends" do
before { travel_to Time.local(2025, 1, 1) }

it "finds only banners active on that date" do
Expand All @@ -52,7 +54,7 @@
end
end

context "The day the page-3 banner swaps" do
context "and on the day the page-3 banner swaps" do
before { travel_to Time.local(2025, 2, 1) }

it "finds only banners active on that date" do
Expand All @@ -67,7 +69,7 @@
end
end

context "After all timed banners end" do
context "but after all timed banners end" do
before { travel_to Time.local(2025, 3, 1) }

it "finds only banners active on that date" do
Expand Down
148 changes: 148 additions & 0 deletions spec/units/govuk_web_banners/validators/recruitment_banner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
require "govuk_web_banners/validators/recruitment_banner"

RSpec.describe GovukWebBanners::Validators::RecruitmentBanner do
subject(:recruitment_banner) { described_class.new(GovukWebBanners::RecruitmentBanner.all_banners) }

let(:fixtures_dir) { Rails.root.join(__dir__, "../../../../spec/fixtures/") }

before do
original_path = Rails.root.join(__dir__, "../../", GovukWebBanners::RecruitmentBanner::BANNER_CONFIG_FILE)
allow(YAML).to receive(:load_file).with(original_path).and_return(replacement_file)

stub_request(:get, %r{\Ahttps://www\.gov\.uk/api/content/.*})
end

context "with valid banners" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(fixtures_dir, "active_recruitment_banners.yml"))
end

describe ".valid?" do
it "returns true" do
expect(recruitment_banner.valid?).to be true
end
end

describe "errors attribute" do
it "returns an empty array" do
expect(recruitment_banner.errors).to be_empty
end
end
end

context "with invalid banners" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(fixtures_dir, "invalid_recruitment_banners.yml"))
end

describe ".valid?" do
it "returns false" do
expect(recruitment_banner.valid?).to be false
end
end

describe "errors attribute" do
it "returns the relevant errors" do
expect(recruitment_banner.errors["Empty Survey URL"]).to eq(["is missing a survey_url"])
expect(recruitment_banner.errors["Suggestion Link Text Broken"]).to eq(["is missing a suggestion_link_text"])
expect(recruitment_banner.errors["Page Paths Empty"]).to eq(["is missing any page_paths"])
expect(recruitment_banner.errors["Suggestion Text Empty"]).to eq(["is missing a suggestion_text"])
expect(recruitment_banner.errors["Page Paths include invalid path"]).to eq(["page_path views/old should start with a /"])
end
end
end

context "with a banner that has expired" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(fixtures_dir, "expired_recruitment_banners.yml"))
end

before { travel_to Time.local(2024, 1, 2) }
after { travel_back }

describe ".valid?" do
it "returns true" do
expect(recruitment_banner.valid?).to be true
end
end

describe ".warnings?" do
it "returns true" do
expect(recruitment_banner.warnings?).to be true
end
end

describe "warnings attribute" do
it "returns the relevant warnings" do
expect(recruitment_banner.warnings).to eq({ "Banner 1" => ["is expired"] })
end
end
end

context "with banners on the same path" do
context "when they aren't active at the same time" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(fixtures_dir, "path_clash_different_times_recruitment_banners.yml"))
end

describe ".valid?" do
it "returns true" do
expect(recruitment_banner.valid?).to be true
end
end

describe "errors attribute" do
it "returns an empty array" do
expect(recruitment_banner.errors).to be_empty
end
end
end

context "when they are active at the same time" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(fixtures_dir, "path_clash_same_time_recruitment_banners.yml"))
end

describe ".valid?" do
it "returns false" do
expect(recruitment_banner.valid?).to be false
end
end

describe "errors attribute" do
it "returns the relevant errors" do
expect(recruitment_banner.errors["Banner feb-apr"]).to eq(["is active at the same time as Banner jan-mar and points to the same paths"])
expect(recruitment_banner.errors["Banner jan-mar"]).to eq(["is active at the same time as Banner feb-apr and points to the same paths"])
end
end
end
end

context "with a path that doesn't exist on the live site" do
let(:replacement_file) do
YAML.load_file(Rails.root.join(fixtures_dir, "active_recruitment_banners.yml"))
end

before do
stub_request(:get, %r{\Ahttps://www\.gov\.uk/api/content/email-signup}).to_return(status: 404)
end

describe ".valid?" do
it "returns true" do
expect(recruitment_banner.valid?).to be true
end
end

describe ".warnings?" do
it "returns true" do
expect(recruitment_banner.warnings?).to be true
end
end

describe "warnings attribute" do
it "returns the relevant warnings" do
expect(recruitment_banner.warnings).to eq({ "Banner 2" => ["refers to a path /email-signup which is not currently live on gov.uk"] })
end
end
end
end
147 changes: 0 additions & 147 deletions spec/units/validators/recruitment_banner_spec.rb

This file was deleted.

Loading