-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Cop idea: discourage the use of assert_
/refute_
Minitest matchers
#7
Comments
Do we know why rspec-expectations provide this feature? Is it going to be deprecated? One of the non-goals of rubocop-rspec is
and I wonder if the suggested cop doesn’t fall under this category. |
Fair enough. RSpec.configure do |config|
config.expect_with :minitest
end which is exclusively using config.expect_with :rspec do |expectations| If with this it's still possible to use Minitest's assertions, there's probably something wrong. However, |
Indeed, it's coming from module RSpec
module Rails
# @api public
# Common rails example functionality.
module RailsExampleGroup
# ...
include RSpec::Rails::MinitestAssertionAdapter I'll give it a shot to only include it if |
Fails, e.g.: 1) UploadsController DELETE #destroy redirects to the uploads list
Failure/Error: expect(response).to redirect_to(uploads_url)
NoMethodError:
undefined method `assert' for #<RSpec::ExampleGroups::UploadsController::DELETEDestroy "redirects to the uploads list" (./spec/controllers/uploads_controller_spec.rb:138)>
# ./spec/controllers/uploads_controller_spec.rb:141:in `block (3 levels) in <top (required)>' If it's impossible to restrict this on RSpec level, I suppose we're left with static analysis. |
There are also a few aliases that Rails defines here. I guess the cop could make this list configurable, and |
I am still not sure which problem this PR fixes. Minitest matchers are not loaded by default. This example:
gives me the error |
They are if you use It makes sense to re-target this cop to be |
Let's keep this open, since there are a few more matchers than can be covered. |
Please note that the order of the arguments of |
test-unit assertions, for completeness https://www.rubydoc.info/gems/test-unit/2.3.2/Test/Unit/Assertions |
Also here's the Rails aliased assertion methods: https://github.com/rails/rails/blob/main/activesupport/lib/active_support/test_case.rb#L153 |
Suggested by @Darhazer
RSpec Expectations allows using
assert_
/refute_
Minitest matchersHowever, RSpec comes with its matchers that pretty much cover the same:
A notable difference is that Minitest allows for an optional failure message.
It's a lesser known RSpec feature, but it allows it, too:
The text was updated successfully, but these errors were encountered: