Skip to content

Commit

Permalink
Merge pull request #203 from koic/support_it_block
Browse files Browse the repository at this point in the history
[Fix #200] Support `it` testing block for minitest/spec
  • Loading branch information
koic authored Dec 5, 2022
2 parents 0c34fed + f913555 commit 2ae881b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/new_support_it_block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#200](https://github.com/rubocop/rubocop-minitest/issues/200): Support `it` testing block for minitest/spec. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_cases(class_node)

# Support Active Support's `test 'example' { ... }` method.
# https://api.rubyonrails.org/classes/ActiveSupport/Testing/Declarative.html
test_blocks = class_node.each_descendant(:block).select { |block_node| block_node.method?(:test) }
test_blocks = class_node.each_descendant(:block).select { |block| block.method?(:test) || block.method?(:it) }

test_cases + test_blocks
end
Expand Down
21 changes: 20 additions & 1 deletion test/rubocop/cop/minitest/no_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_another_valid_test
RUBY
end

def test_registers_offense_when_no_assertions_in_block_form
def test_registers_offense_when_no_assertions_in_test_block_form
assert_offense(<<~RUBY)
class FooTest < Minitest::Test
include Foo
Expand All @@ -49,6 +49,25 @@ class FooTest < Minitest::Test
RUBY
end

def test_registers_offense_when_no_assertions_in_it_block_form
assert_offense(<<~RUBY)
class FooTest < Minitest::Test
describe Foo do
setup { }
teardown { }
it "asserts the truth" do
assert true
end
it "does nothing" do
^^^^^^^^^^^^^^^^^^^^ Test case has no assertions.
end
end
end
RUBY
end

def test_register_no_offense_if_test_has_assertion
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
Expand Down

0 comments on commit 2ae881b

Please sign in to comment.