You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use this gem to test your own cops, by using the `RuboCop::Minitest::Test` test class, you'll get `assert_offense`, `assert_correction`, and `assert_no_offense` helpers
101
+
102
+
```ruby
103
+
104
+
require "rubocop/minitest/support"
105
+
require "custom_cops/my_cop"
106
+
107
+
module CustomCops
108
+
class MyCopTest < RuboCop::Minitest::Test
109
+
def test_registers_offense
110
+
assert_offense(<<~RUBY)
111
+
class FooTest < Minitest::Test
112
+
def test_do_something
113
+
assert_equal(nil, somestuff)
114
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_nil(somestuff)`.
115
+
end
116
+
end
117
+
RUBY
118
+
end
119
+
120
+
def test_assert_offense_and_correction
121
+
assert_offense(<<~RUBY)
122
+
class FooTest < Minitest::Test
123
+
def test_do_something
124
+
assert_equal(nil, somestuff)
125
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_nil(somestuff)`.
126
+
end
127
+
end
128
+
RUBY
129
+
130
+
assert_correction(<<~RUBY)
131
+
class FooTest < Minitest::Test
132
+
def test_do_something
133
+
assert_nil(somestuff)
134
+
end
135
+
end
136
+
RUBY
137
+
end
138
+
139
+
def test_assert_offense_and_no_corrections
140
+
assert_offense(<<~RUBY)
141
+
class FooTest < Minitest::Test
142
+
def test_do_something
143
+
assert_equal(nil, somestuff)
144
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_nil(somestuff)`.
145
+
end
146
+
end
147
+
RUBY
148
+
149
+
assert_no_corrections
150
+
end
151
+
152
+
def test_assert_no_offense
153
+
assert_no_offenses(<<~RUBY)
154
+
class FooTest < Minitest::Test
155
+
def test_do_something
156
+
assert_nil(somestuff)
157
+
end
158
+
end
159
+
RUBY
160
+
end
161
+
162
+
# You can set the `@cop` attribute to override the auto-detected cop and provide configuration options
*[#278](https://github.com/rubocop/rubocop-minitest/pull/278): Allow `RuboCop::Minitest::Test` to be used by consumers of the gem to test custom cops. ([@dougedey][])
0 commit comments