-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add Rails/ControllerTesting cop #638
Conversation
b7046b9
to
8405f86
Compare
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.
Thank you!
expect_no_offenses(<<~RUBY) | ||
class MyControllerTest < ActionDispatch::IntegrationTest; end | ||
RUBY | ||
end |
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.
Can you add a test case that does not have a superclass as a test?
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.
Added one that tests:
expect_no_offenses(<<~RUBY)
class MyControllerTest < SuperControllerTest
end
RUBY
for a custom superclass. Let me know if you meant that, or something else 😄
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.
I was worried about class Foo; end
, but there was no problem :-)
f2ac26a
to
b33f717
Compare
b33f717
to
07869be
Compare
Add controller testing cop to discourage use of ActionController::TestCase. ActionDispatch::IntegrationTest should be used instead to test controllers.
07869be
to
4fd37fd
Compare
Thanks! |
Thank you both for the reviews, I learned a lot! ❤️ |
Follow up of rubocop/rubocop-rails#638 (comment). This PR adds new `InternalAffairs/RedundantContextConfigParameter` cop that checks for redundant `:config` parameter in the `context` arguments. ```ruby # bad context 'foo', :config do end # good context 'foo' do end ```
Follow up of rubocop/rubocop-rails#638 (comment). This PR adds new `InternalAffairs/RedundantContextConfigParameter` cop that checks for redundant `:config` parameter in the `context` arguments. ```ruby # bad context 'foo', :config do end # good context 'foo' do end ```
👋 I wrote a cop recently to list usage of all old controller tests. Essentially, it replaces
ActionController::TestCase
withActionDispatch::IntegrationTest
. The actual process of converting between the two test case types is a little more involved, but I think the cop is valuable just to keep track of this tech debt within a codebase. I thought that other developers could possibly benefit from this cop as well. Let me know what you think. Thanks!Add controller testing cop to discourage use of
ActionController::TestCase
.ActionDispatch::IntegrationTest
should be used instead to test controllers. See https://api.rubyonrails.org/classes/ActionController/TestCase.htmlRelated issue for updating the style guide: rubocop/rails-style-guide#302.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.and description in grammatically correct, complete sentences.