-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: add rswag cop #47
base: main
Are you sure you want to change the base?
feat: add rswag cop #47
Conversation
e427f2f
to
96412be
Compare
module Cop | ||
module Betterment | ||
class NotUsingRswag < Base | ||
MSG = 'API tests should use documented using rswag and not the built in `get`, `post`, `put`, `patch`, `delete` methods' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it distinguish between API tests and request tests that test ERB endpoints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written it won't distinguish between the two, I hadn't considered that case. However I think if we wanted to write spec for an endpoint that produces html we'd just specify produces 'text/html
and not specify anything about the structure of it. In the tests themselves whether using rswag's built in run_test!
or our Retail helper submit_request!
we will still have access to the response
and could assert things about the html from that. So this as written might work for endpoints that respond with other content types.
This approach is perhaps a bit too naive, instead it could try to assert that a request spec is written in a particular structure using methods that come from rswag:
path 'url_string' do
...
get/post/put/patch/delete 'some_description' do
...
response 'http_status_code', 'some_description' do
...
run_test!
# or
it 'some_description' do
submit_request!
end
end
end
end
96412be
to
6820c4e
Compare
6820c4e
to
e0beafd
Compare
This adds a new cop for request specs to ensure they are written using rswag to document their API contracts. This is accomplished by searching for usages of the built in http verb request methods in spec examples, helper functions, and before blocks. Specs written using RSwag should not be using these methods, they should instead be using RSwag built-ins like
run_test!
orsubmit_request!