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

+3
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

+2-2
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

+2-2
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

+1-1
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

+2-2
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

+2-2
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

+3-3
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

+8-8
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

+1-1
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

+3-3
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

actionpack/test/controller/new_base/bare_metal_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class BareTest < ActiveSupport::TestCase
4747
controller.set_response!(BareController.make_response!(controller.request))
4848
controller.index
4949

50-
assert controller.performed?
50+
assert_predicate controller, :performed?
5151
assert_equal ["Hello world"], controller.response_body
5252
end
5353

@@ -56,7 +56,7 @@ class BareTest < ActiveSupport::TestCase
5656
controller.set_request!(ActionDispatch::Request.empty)
5757
controller.assign_response_array
5858

59-
assert controller.performed?
59+
assert_predicate controller, :performed?
6060
assert_equal true, controller.response_body
6161
assert_equal 200, controller.response[0]
6262
assert_equal "text/html", controller.response[1]["content-type"]
@@ -67,7 +67,7 @@ class BareTest < ActiveSupport::TestCase
6767
controller.set_request!(ActionDispatch::Request.empty)
6868
controller.assign_response_object
6969

70-
assert controller.performed?
70+
assert_predicate controller, :performed?
7171
assert_equal true, controller.response_body
7272
assert_equal 200, controller.response.status
7373
assert_equal "text/html", controller.response.headers["content-type"]
@@ -79,10 +79,10 @@ class BareTest < ActiveSupport::TestCase
7979
controller.set_response!(BareController.make_response!(controller.request))
8080
controller.assign_response_body_proc
8181

82-
assert controller.performed?
82+
assert_predicate controller, :performed?
8383
assert controller.response_body.is_a?(Proc)
8484
assert_equal 200, controller.response.status
85-
assert controller.response.headers.empty?
85+
assert_predicate controller.response.headers, :empty?
8686
end
8787

8888
test "connect a request to controller instance without dispatch" do

actionpack/test/controller/parameters/accessors_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
5555

5656
test "each carries permitted status" do
5757
@params.permit!
58-
@params.each { |key, value| assert(value.permitted?) if key == "person" }
58+
@params.each { |key, value| assert_predicate(value, :permitted?) if key == "person" }
5959
end
6060

6161
test "each carries unpermitted status" do
@@ -77,7 +77,7 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
7777

7878
test "each_pair carries permitted status" do
7979
@params.permit!
80-
@params.each_pair { |key, value| assert(value.permitted?) if key == "person" }
80+
@params.each_pair { |key, value| assert_predicate(value, :permitted?) if key == "person" }
8181
end
8282

8383
test "each_pair carries unpermitted status" do

actionpack/test/dispatch/request_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ class RequestFormat < BaseRequestTest
933933
"action_dispatch.logger" => Logger.new(output = StringIO.new)
934934
)
935935
assert request.formats
936-
assert request.format.html?
936+
assert_predicate request.format, :html?
937937

938938
output.rewind && (err = output.read)
939939
assert_match(/Error occurred while parsing request parameters/, err)

actionpack/test/dispatch/routing/route_set_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def call(env)
2020
end
2121

2222
test "not being empty when route is added" do
23-
assert empty?
23+
assert_predicate self, :empty?
2424

2525
draw do
2626
get "foo", to: SimpleApp.new("foo#index")

actionpack/test/dispatch/routing_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -3509,16 +3509,16 @@ def test_trailing_slash
35093509
end
35103510

35113511
get "/streams"
3512-
assert @response.ok?, "route without trailing slash should work"
3512+
assert_predicate @response, :ok?, "route without trailing slash should work"
35133513

35143514
get "/streams/"
3515-
assert @response.ok?, "route with trailing slash should work"
3515+
assert_predicate @response, :ok?, "route with trailing slash should work"
35163516

35173517
get "/streams?foobar"
3518-
assert @response.ok?, "route without trailing slash and with QUERY_STRING should work"
3518+
assert_predicate @response, :ok?, "route without trailing slash and with QUERY_STRING should work"
35193519

35203520
get "/streams/?foobar"
3521-
assert @response.ok?, "route with trailing slash and with QUERY_STRING should work"
3521+
assert_predicate @response, :ok?, "route with trailing slash and with QUERY_STRING should work"
35223522
end
35233523

35243524
def test_route_with_dashes_in_path

actionpack/test/dispatch/uploaded_file_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ def test_delegates_close_to_tempfile
8686
tf = Tempfile.new
8787
uf = Http::UploadedFile.new(tempfile: tf)
8888
uf.close
89-
assert tf.closed?
89+
assert_predicate tf, :closed?
9090
end
9191

9292
def test_close_accepts_parameter
9393
tf = Tempfile.new
9494
uf = Http::UploadedFile.new(tempfile: tf)
9595
uf.close(true)
96-
assert tf.closed?
96+
assert_predicate tf, :closed?
9797
assert_nil tf.path
9898
end
9999

actiontext/test/unit/model_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ class ActionText::ModelTest < ActiveSupport::TestCase
1717

1818
test "without content" do
1919
message = Message.create!(subject: "Greetings")
20-
assert message.content.nil?
21-
assert message.content.blank?
22-
assert message.content.empty?
20+
assert_predicate message.content, :nil?
21+
assert_predicate message.content, :blank?
22+
assert_predicate message.content, :empty?
2323
assert_not message.content?
2424
assert_not message.content.present?
2525
end
2626

2727
test "with blank content" do
2828
message = Message.create!(subject: "Greetings", content: "")
2929
assert_not message.content.nil?
30-
assert message.content.blank?
31-
assert message.content.empty?
30+
assert_predicate message.content, :blank?
31+
assert_predicate message.content, :empty?
3232
assert_not message.content?
3333
assert_not message.content.present?
3434
end

actionview/test/template/partial_iteration_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_has_size_and_index
1212

1313
def test_first_is_true_when_current_is_at_the_first_index
1414
iteration = ActionView::PartialIteration.new 3
15-
assert iteration.first?, "first when current is 0"
15+
assert_predicate iteration, :first?, "first when current is 0"
1616
end
1717

1818
def test_first_is_false_unless_current_is_at_the_first_index
@@ -25,7 +25,7 @@ def test_last_is_true_when_current_is_at_the_last_index
2525
iteration = ActionView::PartialIteration.new 3
2626
iteration.iterate!
2727
iteration.iterate!
28-
assert iteration.last?, "last when current is 2"
28+
assert_predicate iteration, :last?, "last when current is 2"
2929
end
3030

3131
def test_last_is_false_unless_current_is_at_the_last_index

actionview/test/template/tag_helper_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_tag_builder_do_not_modify_html_safe_options
135135
html_safe_str = '"'.html_safe
136136
assert_equal "<p value=\"&quot;\" />", tag("p", value: html_safe_str)
137137
assert_equal '"', html_safe_str
138-
assert html_safe_str.html_safe?
138+
assert_predicate html_safe_str, :html_safe?
139139
end
140140

141141
def test_tag_with_dangerous_name

0 commit comments

Comments
 (0)