Skip to content

Commit 953bef9

Browse files
committed
Use Minitest#flunk instead of raising an Assertion error:
- ### Problem Using the `assert_recognizes` assertion will throw a warning message saying "the test is missing an assertion". This is because raising a `Minitest::Assertion` error directly (instead of using a built-in Minitest assertion method), doesn't increment the `Test#assertions` count which is later used by the TestsWithoutAssertions feature https://github.com/rails/rails/blob/8e504b017a68981076746c2d19fd23c788e4293e/activesupport/lib/active_support/testing/tests_without_assertions.rb#L8-L12. ### Solution Use `flunk` instead of raising. I don't think it's worth changing the `TestsWithoutAssertions` feature, as I don't see the point of raising a `Minitest:Assertion` error anyway.
1 parent 8e504b0 commit 953bef9

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

actionmailer/test/base_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def welcome
331331
mail body: "yay", from: "[email protected]", to: "[email protected]"
332332

333333
unless attachments.map(&:filename) == ["invoice.pdf"]
334-
raise Minitest::Assertion, "Should allow access to attachments"
334+
flunk("Should allow access to attachments")
335335
end
336336
end
337337
end

actionpack/lib/action_dispatch/testing/assertions/routing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def recognized_request_for(path, extras = {}, msg)
336336
def fail_on(exception_class, message)
337337
yield
338338
rescue exception_class => e
339-
raise Minitest::Assertion, message || e.message
339+
flunk(message || e.message)
340340
end
341341
end
342342
end

activesupport/lib/active_support/testing/error_reporter_assertions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def subscribe
4444
ActiveSupport.error_reporter.subscribe(self)
4545
@subscribed = true
4646
else
47-
raise Minitest::Assertion, "No error reporter is configured"
47+
flunk("No error reporter is configured")
4848
end
4949
end
5050
end

railties/test/test_unit/reporter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def assert_rerun_snippet_count(snippet_count)
180180
def failed_test
181181
ft = Minitest::Result.from(ExampleTest.new(:woot))
182182
ft.failures << begin
183-
raise Minitest::Assertion, "boo"
183+
flunk("boo")
184184
rescue Minitest::Assertion => e
185185
e
186186
end

0 commit comments

Comments
 (0)