Skip to content

Commit 1d11c76

Browse files
authored
Merge pull request rails#49628 from Shopify/enable-minitest-assert-predicate-rubocop-rule
[Tests only] Enable `Minitest/AssertPredicate` rule
2 parents 41a5604 + 19f8ab2 commit 1d11c76

File tree

115 files changed

+427
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+427
-424
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ Performance/RedundantStringChars:
353353
Performance/StringInclude:
354354
Enabled: true
355355

356+
Minitest/AssertPredicate:
357+
Enabled: true
358+
356359
Minitest/AssertRaisesWithRegexpArgument:
357360
Enabled: true
358361

actioncable/test/channel/test_case_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_no_subscribe
4444
def test_subscribe
4545
subscribe
4646

47-
assert subscription.confirmed?
47+
assert_predicate subscription, :confirmed?
4848
assert_not subscription.rejected?
4949
assert_equal 1, connection.transmissions.size
5050
assert_equal ActionCable::INTERNAL[:message_types][:confirmation],
@@ -77,7 +77,7 @@ def test_rejection
7777
subscribe
7878

7979
assert_not subscription.confirmed?
80-
assert subscription.rejected?
80+
assert_predicate subscription, :rejected?
8181
assert_equal 1, connection.transmissions.size
8282
assert_equal ActionCable::INTERNAL[:message_types][:rejection],
8383
connection.transmissions.last["type"]

actioncable/test/client_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def test_remote_disconnect_client
325325
assert_equal({ "type" => "disconnect", "reason" => "remote", "reconnect" => true }, c.read_message)
326326

327327
c.wait_for_close
328-
assert(c.closed?)
328+
assert_predicate(c, :closed?)
329329
end
330330
end
331331

@@ -342,7 +342,7 @@ def test_remote_disconnect_client_with_reconnect
342342
assert_equal({ "type" => "disconnect", "reason" => "remote", "reconnect" => false }, c.read_message)
343343

344344
c.wait_for_close
345-
assert(c.closed?)
345+
assert_predicate(c, :closed?)
346346
end
347347
end
348348

actioncable/test/subscription_adapter/postgresql_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def active?
6262

6363
ActiveRecord::Base.connection_handler.clear_reloadable_connections!
6464

65-
assert adapter.active?
65+
assert_predicate adapter, :active?
6666
end
6767

6868
def test_default_subscription_connection_identifier

actionmailbox/test/unit/mailbox/bouncing_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase
3131
BouncingWithReplyMailbox.receive @inbound_email
3232
end
3333

34-
assert @inbound_email.bounced?
34+
assert_predicate @inbound_email, :bounced?
3535
assert_emails 1
3636

3737
mail = ActionMailer::Base.deliveries.last
@@ -44,7 +44,7 @@ class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase
4444
BouncingWithImmediateReplyMailbox.receive @inbound_email
4545
end
4646

47-
assert @inbound_email.bounced?
47+
assert_predicate @inbound_email, :bounced?
4848
assert_emails 1
4949

5050
mail = ActionMailer::Base.deliveries.last

actionmailbox/test/unit/mailbox/callbacks_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ class ActionMailbox::Base::CallbacksTest < ActiveSupport::TestCase
6161

6262
test "bouncing in a callback terminates processing" do
6363
BouncingCallbackMailbox.receive @inbound_email
64-
assert @inbound_email.bounced?
64+
assert_predicate @inbound_email, :bounced?
6565
assert_equal [ "Pre-bounce", "Bounce" ], $before_processing
6666
assert_not $processed
6767
assert_not $after_processing
6868
end
6969

7070
test "marking the inbound email as delivered in a callback terminates processing" do
7171
DiscardingCallbackMailbox.receive @inbound_email
72-
assert @inbound_email.delivered?
72+
assert_predicate @inbound_email, :delivered?
7373
assert_equal [ "Pre-discard", "Discard" ], $before_processing
7474
assert_not $processed
7575
assert_not $after_processing

actionmailbox/test/unit/mailbox/state_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ class ActionMailbox::Base::StateTest < ActiveSupport::TestCase
3333

3434
test "successful mailbox processing leaves inbound email in delivered state" do
3535
SuccessfulMailbox.receive @inbound_email
36-
assert @inbound_email.delivered?
36+
assert_predicate @inbound_email, :delivered?
3737
assert_equal "I was processed", $processed
3838
end
3939

4040
test "unsuccessful mailbox processing leaves inbound email in failed state" do
4141
UnsuccessfulMailbox.receive @inbound_email
42-
assert @inbound_email.failed?
42+
assert_predicate @inbound_email, :failed?
4343
assert_equal :failure, $processed
4444
end
4545

4646
test "bounced inbound emails are not delivered" do
4747
BouncingMailbox.receive @inbound_email
48-
assert @inbound_email.bounced?
48+
assert_predicate @inbound_email, :bounced?
4949
assert_equal :bounced, $processed
5050
end
5151
end

actionmailbox/test/unit/relayer_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RelayerTest < ActiveSupport::TestCase
1919
result = @relayer.relay(file_fixture("welcome.eml").read)
2020
assert_equal "2.0.0", result.status_code
2121
assert_equal "Successfully relayed message to ingress", result.message
22-
assert result.success?
22+
assert_predicate result, :success?
2323
assert_not result.failure?
2424

2525
assert_requested :post, URL, body: file_fixture("welcome.eml").read,
@@ -34,7 +34,7 @@ class RelayerTest < ActiveSupport::TestCase
3434
assert_equal "4.7.0", result.status_code
3535
assert_equal "Invalid credentials for ingress", result.message
3636
assert_not result.success?
37-
assert result.failure?
37+
assert_predicate result, :failure?
3838
end
3939

4040
test "unsuccessfully relaying due to an unspecified server error" do
@@ -44,7 +44,7 @@ class RelayerTest < ActiveSupport::TestCase
4444
assert_equal "4.0.0", result.status_code
4545
assert_equal "HTTP 500", result.message
4646
assert_not result.success?
47-
assert result.failure?
47+
assert_predicate result, :failure?
4848
end
4949

5050
test "unsuccessfully relaying due to a gateway timeout" do
@@ -54,7 +54,7 @@ class RelayerTest < ActiveSupport::TestCase
5454
assert_equal "4.0.0", result.status_code
5555
assert_equal "HTTP 504", result.message
5656
assert_not result.success?
57-
assert result.failure?
57+
assert_predicate result, :failure?
5858
end
5959

6060
test "unsuccessfully relaying due to ECONNRESET" do
@@ -64,7 +64,7 @@ class RelayerTest < ActiveSupport::TestCase
6464
assert_equal "4.4.2", result.status_code
6565
assert_equal "Network error relaying to ingress: Connection reset by peer", result.message
6666
assert_not result.success?
67-
assert result.failure?
67+
assert_predicate result, :failure?
6868
end
6969

7070
test "unsuccessfully relaying due to connection failure" do
@@ -74,7 +74,7 @@ class RelayerTest < ActiveSupport::TestCase
7474
assert_equal "4.4.2", result.status_code
7575
assert_equal "Network error relaying to ingress: Failed to open TCP connection to example.com:443", result.message
7676
assert_not result.success?
77-
assert result.failure?
77+
assert_predicate result, :failure?
7878
end
7979

8080
test "unsuccessfully relaying due to client-side timeout" do
@@ -84,7 +84,7 @@ class RelayerTest < ActiveSupport::TestCase
8484
assert_equal "4.4.2", result.status_code
8585
assert_equal "Timed out relaying to ingress", result.message
8686
assert_not result.success?
87-
assert result.failure?
87+
assert_predicate result, :failure?
8888
end
8989

9090
test "unsuccessfully relaying due to an unhandled exception" do
@@ -94,7 +94,7 @@ class RelayerTest < ActiveSupport::TestCase
9494
assert_equal "4.0.0", result.status_code
9595
assert_equal "Error relaying to ingress: Something went wrong", result.message
9696
assert_not result.success?
97-
assert result.failure?
97+
assert_predicate result, :failure?
9898
end
9999
end
100100
end

actionmailbox/test/unit/router_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class RouterTest < ActiveSupport::TestCase
136136
assert_raises(ActionMailbox::Router::RoutingError) do
137137
@router.route inbound_email
138138
end
139-
assert inbound_email.bounced?
139+
assert_predicate inbound_email, :bounced?
140140
end
141141

142142
test "invalid address" do

actionpack/test/controller/live_stream_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ def ignore_client_disconnect
324324
tests TestController
325325

326326
def assert_stream_closed
327-
assert response.stream.closed?, "stream should be closed"
328-
assert response.committed?, "response should be committed"
329-
assert response.sent?, "response should be sent"
327+
assert_predicate response.stream, :closed?, "stream should be closed"
328+
assert_predicate response, :committed?, "response should be committed"
329+
assert_predicate response, :sent?, "response should be sent"
330330
end
331331

332332
def capture_log_output

0 commit comments

Comments
 (0)