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

Migrate Controller Specs to Request Specs #739

Closed
armahillo opened this issue Mar 11, 2019 · 6 comments
Closed

Migrate Controller Specs to Request Specs #739

armahillo opened this issue Mar 11, 2019 · 6 comments
Assignees

Comments

@armahillo
Copy link
Collaborator

We have dozens (literally dozens!) of Controller specs. The current attitudes are to move away from Controller specs in favor of Request specs. We have some Request specs started for our API.

See here for some more discussion: rspec/rspec-rails#1838

This is also an opportunity to review our specs and ensure:

  • we have good coverage for our controller actions
  • we are not testing things unnecessarily

Reference

@tomrossi7
Copy link
Collaborator

Hi everyone! I've started work on this issue and setup this branch. I'm new to participating in Open Source, so please don't hesitate to tell me if I need to do anything differently!

@armahillo
Copy link
Collaborator Author

Awesome, thank you @tomrossi7 !

@tomrossi7
Copy link
Collaborator

tomrossi7 commented May 26, 2019

I've gone ahead and committed the migration of the organizations_controller_spec to the organizations_requests_spec, and would love to get feedback for tackling the others.

  1. I'm not sure if I should be having the conversation here on the issue or should I create a PR before its done to have the discussion?
  2. What type of assertions do we want in the integration test vs. a system test? I noticed there is already an organization system test that could eliminate the entire integration test with just a few modifications. In our organization, we have moved to only create system and unit tests with very few exceptions.
  3. Do we like the naming and formatting?

Thanks for letting me a part of the good you all are doing!

@tomrossi7 tomrossi7 self-assigned this May 26, 2019
@holytoastr
Copy link
Collaborator

This branch is awesome! Where do we stand on it? I'd like to help and add a few more request specs!

@tomrossi7
Copy link
Collaborator

I’m traveling a ton through August and haven’t been able to push out any more tests. Feel free to jump in!

@armahillo armahillo modified the milestones: Ruby By The Bay, Release 1.8 Aug 4, 2019
@armahillo
Copy link
Collaborator Author

@tomrossi7 Sorry, just now saw your comments!

To answer your questions:

  1. I would recommend doing a series of smaller PRs that reference, but not close, this issue. Perhaps one PR per spec you create (or maybe per chunk, if you do multiple specs in a single session).
  2. I'm not totally familiar with the specifics of Request specs (perhaps @holytoastr might have some insight?) but I'm thinking you'll be primarily looking for success and failure with the requests themselves, and not caring so much about whether or not the database is changed.
  3. Naming and formatting looked fine in the specs I looked at -- one thing I would recommend though is to use FactoryBot factories instead of Model.create! -- many of our models have associations and the factories ensure that the associations are built out correctly. (For example: https://github.com/rubyforgood/diaper/blob/739-Migrate-Controller-Specs-to-Request-Specs/spec/requests/adjustments_requests_spec.rb#L28 -- this could be: create(:adjustment)

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

No branches or pull requests

4 participants