Skip to content

Commit

Permalink
Remove declarative testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Edey committed Dec 13, 2023
1 parent 89bda47 commit 5b0c5da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ require "custom_cops/my_cop"
module CustomCops
class MyCopTest < RuboCop::Minitest::Test
test "registers offense" do
def test_registers_offense
assert_offense(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
Expand All @@ -117,7 +117,7 @@ module CustomCops
RUBY
end

test "assert offense and correction"
def test_assert_offense_and_correction
assert_offense(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
Expand All @@ -136,7 +136,7 @@ module CustomCops
RUBY
end

test "assert offense and no corrections"
def test_assert_offense_and_no_corrections
assert_offense(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
Expand All @@ -149,7 +149,7 @@ module CustomCops
assert_no_corrections
end

test "assert no offense"
def test_assert_no_offense
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
Expand All @@ -160,7 +160,7 @@ module CustomCops
end

# You can set the `@cop` attribute to override the auto-detected cop and provide configuration options
test "override cop configuration" do
def test_override_cop_configuration
cop_config = RuboCop::Config.new('Minitest/MultipleAssertions' => { 'Max' => 1 })
@cop = RuboCop::Cop::Minitest::MultipleAssertions.new(cop_config)

Expand Down
28 changes: 3 additions & 25 deletions lib/rubocop/minitest/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Minitest
# @example Usage
#
# class AssertNilTest < RuboCop::Minitest::Test
# test "fails when using assert_equal(nil, ...)" do
# def test_fails_when_using_assert_equal_nil
# assert_offense(<<~RUBY)
# class FooTest < Minitest::Test
# def test_do_something
Expand All @@ -40,7 +40,7 @@ module Minitest
# @example `assert_offense` and `assert_correction`
#
# class AssertNilTest < RuboCop::Minitest::Test
# test "autocorrects when using assert_equal(nil, ...)" do
# def test_autocorrects_when_using_assert_equal
# assert_offense(<<~RUBY)
# class FooTest < Minitest::Test
# def test_do_something
Expand Down Expand Up @@ -72,7 +72,7 @@ module Minitest
# @example `assert_offense` and `assert_no_corrections`
#
# class AssertNilTest < RuboCop::Minitest::Test
# test "no autocorrections"
# def test_no_autocorrections
# assert_offense(<<~RUBY)
# class FooTest < Minitest::Test
# def test_do_something
Expand All @@ -86,28 +86,6 @@ module Minitest
# end
# end
class Test < ::Minitest::Test
class << self
# Helper to define a test method using a String. Under the hood, it replaces
# spaces with underscores and defines the test method.
#
# test "verify something" do
# ...
# end
def test(name, &block)
test_name = :"test_#{name.gsub(/\s+/, '_')}"
defined = method_defined?(test_name)
raise "#{test_name} is already defined in #{self}" if defined

if block
define_method(test_name, &block)
else
define_method(test_name) do
raise("No implementation provided for #{name}")
end
end
end
end

private

def setup
Expand Down

0 comments on commit 5b0c5da

Please sign in to comment.