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

Convert Frontend Test Runner from Minitest to RSpec #4090

Merged
merged 75 commits into from
Jul 30, 2024

Conversation

KludgeKML
Copy link
Contributor

@KludgeKML KludgeKML commented Jun 4, 2024

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

NB: Currently failing checks because it's expecting a minitest check - as long as that's the only failure it is safe to merge but we will need to update the settings

What

Replace Frontend's existing minitest test suite with the equivalent in RSpec.

Why

RSpec is our standard, and we want to merge some smaller apps (using RSpec test suites) into Frontend. We have decided it's better to rewrite the larger app to conform to our standard than move the smaller app in the other direction.

Trello card

How

We do the bulk of the conversion using a fork of the minitest_to_rspec gem; then tidy up the code with rubocop before manually tweaking the remaining tests that don't run. Finally we compare coverage to ensure that we have the same between the versions.

Coverage

Line coverage is slightly improved (97.8% -> 97.94%)

Style decisions I have made (and can unmake!)

In tidying up the autogenerated specs, I've made a bunch of style decisions that aren't really covered by rubocop but which I've tried to maintain to keep the new files consistent with other spec tests (we don't have a perfect consistency in other apps, but there's a rough consensus). I'm not married to these decisions, so feel free to comment on them and we can update the files:

  • requires at the top of _spec files don't have parentheses around their parameters
  • describe/context/it blocks don't have parentheses around their parameter
  • describe blocks at the top of a file are namespaced explicitly (ie RSpec.describe instead of just describe)
  • includes at the top of a describe block don't have parentheses around their parameters
  • expect does have parentheses (if not a block), and so do the matches, but #to and #not_to don't.
  • There are blank links between contexts and its.
  • Inside an it block, I try to leave a blank line between setup and the first expectation
  • I use #describe for the top block in a file, and for any block that is a named method, #context otherwise.
  • I don't have separate assertions for "check for a status of redirect" and "check the current location" - expect(response).to redirect_to() covers both of these tests.

Test Type Conversion

The current idiom is to prefer system spec over feature specs, so all feature tests have been converted to system specs, and request specs over controller specs, so all controller tests have been converted to request specs. Note that in a few cases this has meant a slight adjustment to the tests (some previous controller tests were not suitable for request specs, so have been moved into the system specs for the related feature, and some tests have been simplified as above).

In addition, I've moved tests into directories that reflect their test types, allowing us to avoid explicit test types with teh config.infer_spec_type_from_file_location! RSpec directive - so some of the previous unit tests are moved out into /models and /helpers. Ideally no test types should be added explicitly. The sole exception to this is components, since by convention we tend to put those in /components, and they need to be a mixture of view types (the actual component tests) and default type (the all_components code).

Decisions I have avoided making

I haven't closely examined each test to determine whether it's actually worthwhile as a test. Some of the reviewers pointed out tests that are not great, I've dealt with them. But don't take this PR as an endorsement of the quality of individual tests.

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 4, 2024 12:32 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 4, 2024 12:40 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 4, 2024 13:02 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 4, 2024 14:32 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 4, 2024 16:00 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 5, 2024 08:41 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 5, 2024 18:09 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 5, 2024 18:15 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 6, 2024 09:58 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 6, 2024 14:38 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 6, 2024 14:50 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 6, 2024 14:56 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 6, 2024 15:04 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 6, 2024 15:23 Inactive
@govuk-ci govuk-ci had a problem deploying to govuk-frontend-app-pr-4090 June 6, 2024 15:53 Failure
@KludgeKML KludgeKML marked this pull request as ready for review June 6, 2024 15:57
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 6, 2024 15:57 Inactive
@KludgeKML KludgeKML changed the title Rspec conversion test Convert Frontend Test Runner from Minitest to RSpec Jun 6, 2024
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 10, 2024 15:49 Inactive
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. And the tests are running 🎉

A couple of things I'm not sure about is the nesting of the components helper modules. Other thoughts / comments are inline.

app/helpers/components/calendar_helper.rb Outdated Show resolved Hide resolved
app/controllers/account_home_controller.rb Show resolved Hide resolved
Gemfile Show resolved Hide resolved
spec/support/govuk_spec.rb Outdated Show resolved Hide resolved
spec/support/content_schema_helpers.rb Outdated Show resolved Hide resolved
spec/components/calendar_spec.rb Outdated Show resolved Hide resolved
spec/feature/account_home_spec.rb Outdated Show resolved Hide resolved
spec/feature/account_home_spec.rb Outdated Show resolved Hide resolved
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 11, 2024 12:17 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 11, 2024 15:41 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 June 11, 2024 15:53 Inactive
- Move the fixture file used by this test
- Update to use CalendarHelpers rather
  than test code in Calendar class.
- Remove content_schema_helpers, and reference in
  the CalendarPublisher spec. For the test we're
  making here, it's a lighter touch to remove the
  dependency on Mocha and just match the actual
  example rather than validating that it matches
  a schema.
- Move fixture file used by theses tests
- Update Calendar spec to use
  CalendarHelper rather than test
  code in Calendar class.
- Move fixture used in this test
- Also suppress the "good job!" message which
  messes up the neat RSpec dots.
- delete unused fixture
- delete _helper files from test
- remove test-related gems
- remove content_store_helpers from test/support,
  the only remaining functions in it were never
  used.
- Neither of these methods are referenced in the app.
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4090 July 30, 2024 09:12 Inactive
Copy link
Contributor

@hannako hannako left a comment

Choose a reason for hiding this comment

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

END OF AN ERA!

Well done on not giving up in the face of 8 thousand review comments 💪

@KludgeKML KludgeKML merged commit eb281ac into main Jul 30, 2024
12 checks passed
@KludgeKML KludgeKML deleted the rspec-conversion-test branch July 30, 2024 09:31
@KludgeKML
Copy link
Contributor Author

Those 8 thousand review comments helped it move from a poorly formed mass of clay into a fine china pot (with a few blemishes). Thanks @hannako and @leenagupte for all the suggestions!

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.

4 participants