Skip to content

Commit

Permalink
Merge pull request #76 from koic/fix_false_negative_for_global_expect…
Browse files Browse the repository at this point in the history
…ations_using_without_arguments

[Fix #75] Fix a false negative for `Minitest/GlobalExpectations`
  • Loading branch information
koic committed Apr 13, 2020
2 parents 16b29db + fb1131c commit bdd4fb1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#75](https://github.com/rubocop-hq/rubocop-minitest/issues/75): Fix a false negative for `Minitest/GlobalExpectations` when using global expectation methods with no arguments. ([@koic][])

### Changes

* [#73](https://github.com/rubocop-hq/rubocop-minitest/issues/73): The Minitest department works on file names end with `_test.rb` by default. ([@koic][])
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/global_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GlobalExpectations < Cop
end.join(' ').freeze

def_node_matcher :value_global_expectation?, <<~PATTERN
(send !(send nil? {#{DSL_METHODS_LIST}} _) {#{VALUE_MATCHERS_STR}} _)
(send !(send nil? {#{DSL_METHODS_LIST}} _) {#{VALUE_MATCHERS_STR}} ...)
PATTERN

def_node_matcher :block_global_expectation?, <<~PATTERN
Expand Down
15 changes: 15 additions & 0 deletions test/rubocop/cop/minitest/global_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,20 @@ def test_works_with_chained_method_calls
end
RUBY
end

def test_registers_offense_when_using_global_expectations_without_arguments
assert_offense(<<~RUBY)
it 'does something' do
n.must_be_nil
^ Use `_(n)` instead.
end
RUBY

assert_correction(<<~RUBY)
it 'does something' do
_(n).must_be_nil
end
RUBY
end
end
end

0 comments on commit bdd4fb1

Please sign in to comment.