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 #4524

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Rspec rubocop #4524

wants to merge 20 commits into from

Conversation

KludgeKML
Copy link
Contributor

@KludgeKML KludgeKML commented Dec 11, 2024

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

What

During the rspec conversion, we missed that rubocop-govuk has an opt-in rspec lint ruleset, which wasn't turned on (because previously there was no rspec). This PR turns on that setting, and fixes the many cops that were triggered.

Why

We should adhere to our standards, especially as Frontend is the candidate for merging the other frontend apps.

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 11, 2024 16:32 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 11, 2024 17:09 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 12, 2024 10:12 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 12, 2024 13:53 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 12, 2024 16:13 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 12, 2024 16:29 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 12, 2024 17:19 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 12, 2024 17:27 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 11:49 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 11:59 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 14:19 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 15:01 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 15:13 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 15:18 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 16:26 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 17:04 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 19:54 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4524 December 16, 2024 19:57 Inactive
- will be used in the following commits, allows us to
  include expectations in methods that would otherwise appear
  erroneously to have no expectations, fooling rubocop
- But is also a more consistent call.
- One lint (RSpec/SubjectStub) is disabled in two classes rather than being fixed,
  because fixing it really requires a rethink about the actual classes, and
  this set of commits is scoped to just making the lint pass. We should
  revisit how these two classes work later (especially the call out to mtime
  in ics_renderer)
Copy link
Contributor

@leenagupte leenagupte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good. I've added some inline comments, but they are quite small.

@@ -1,5 +1,5 @@
RSpec.describe GetInvolved do
let(:consultation_1) do
let(:consultation_closing_november) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are much nicer names!

end
end

context "with invalid postcode" do
it "shows location error" do
post "/slug", params: { postcode: invalid_postcode }

expect(LocationError.new(PlacesManagerResponse::INVALID_POSTCODE).postcode_error).to eq(@controller.view_assigns["location_error"].postcode_error)
expect(LocationError.new(PlacesManagerResponse::INVALID_POSTCODE).postcode_error).to eq(describecontroller.view_assigns["location_error"].postcode_error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo? Should this be controller rather than describecontroller?

@@ -37,29 +38,31 @@
end

context "with a protocol-relative redirect" do
let(:referer) { "//protocol-relative-path" }
let(:redirect_path) { referer }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think redirect_path is needed for this test if it's just a copy of referrer. However, I think that might be out of scope for these changes.

@@ -128,11 +131,11 @@
get "/sign-in/callback", params: { code: "code123", state: "state123", _ga: underscore_ga }

expect(response).to have_http_status(:redirect)
assert_includes(@response.redirect_url, underscore_ga)
assert_includes(response.redirect_url, underscore_ga)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't assert_includes Minitest?
Should it be expect(response.redirect_url).to include(underscore_ga)?

@@ -142,10 +145,10 @@
get "/sign-in/callback", params: { code: "code123", state: "state123" }

expect(response).to have_http_status(:redirect)
assert_includes(@response.redirect_url, @redirect_path)
assert_includes(response.redirect_url, @redirect_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and below about using assert_includes

end
end

context "with CSV containing CRLF line terminators" do
subject { described_class.new(@crlf_csv).csv_rows }
let(:csv) { "header 1,header 2,header 3\ncontent 1,content 2,content 3\n".gsub(/\n/, "\r\n") }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just set this to "header 1,header 2,header 3\ncontent 1,content 2,content 3\r\n?

Comment on lines +28 to +31
"kind" => "outcome",
"slug" => "outcome-1",
"title" => "Outcome 1",
"body" => "<p>This is outcome 1</p>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange that Outcome 1 is duplicated. Perhaps it can be deleted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So has this file has been renamed from "spec/unit/strategy_spec.rb"? If so, I'd expect to see a corresponding deleted file.

Comment on lines 2 to 9
# Stop the checker putting it's jaunty message to stdout
around do |ex|
original_stdout = $stdout
$stdout = File.open(File::NULL, "w")
ex.run
$stdout = original_stdout
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for removing this! I too want to see the error if the test fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! This deletion should be fixed up to the previous commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants