Skip to content

Commit e754787

Browse files
authored
Merge pull request rails#44442 from nvasilevski/fix-some-assertionless-tests
[Active Support] Add explicit assertions to tests with no assertions
2 parents e69620c + 4219696 commit e754787

File tree

9 files changed

+42
-24
lines changed

9 files changed

+42
-24
lines changed

activesupport/lib/active_support/testing/method_call_assertions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def assert_called_with(object, method_name, args, returns: nil, &block)
2828

2929
object.stub(method_name, mock, &block)
3030

31-
mock.verify
31+
assert_mock(mock)
3232
end
3333

3434
def assert_not_called(object, method_name, message = nil, &block)

activesupport/test/cache/stores/file_store_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_clear
4747

4848
def test_clear_without_cache_dir
4949
FileUtils.rm_r(cache_dir)
50-
@cache.clear
50+
assert_nothing_raised { @cache.clear }
5151
end
5252

5353
def test_long_uri_encoded_keys

activesupport/test/cache/stores/null_store_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ def setup
1010
end
1111

1212
def test_clear
13+
@cache.write("name", "value")
1314
@cache.clear
15+
assert_nil @cache.read("name")
1416
end
1517

1618
def test_cleanup
19+
@cache.write("name", "value")
1720
@cache.cleanup
21+
assert_nil @cache.read("name")
1822
end
1923

2024
def test_write
@@ -44,6 +48,7 @@ def test_decrement
4448
def test_delete_matched
4549
@cache.write("name", "value")
4650
@cache.delete_matched(/name/)
51+
assert_nil @cache.read("name")
4752
end
4853

4954
def test_local_store_strategy

activesupport/test/core_ext/kernel_test.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ def test_reraise
4545
end
4646

4747
def test_suppression
48-
suppress(ArgumentError) { raise ArgumentError }
49-
suppress(LoadError) { raise LoadError }
50-
suppress(LoadError, ArgumentError) { raise LoadError }
51-
suppress(LoadError, ArgumentError) { raise ArgumentError }
48+
assert_nothing_raised do
49+
suppress(ArgumentError) { raise ArgumentError }
50+
suppress(LoadError) { raise LoadError }
51+
suppress(LoadError, ArgumentError) { raise LoadError }
52+
suppress(LoadError, ArgumentError) { raise ArgumentError }
53+
end
5254
end
5355
end

activesupport/test/deprecation_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,10 @@ def test_allows_configuration_of_disallowed_warnings
508508
def test_no_disallowed_behavior_with_no_disallowed_messages
509509
resetting_disallowed_deprecation_config do
510510
ActiveSupport::Deprecation.disallowed_behavior = :raise
511-
@dtc.none
512-
@dtc.partially
511+
assert_nothing_raised do
512+
@dtc.none
513+
@dtc.partially
514+
end
513515
end
514516
end
515517

@@ -518,7 +520,7 @@ def test_disallowed_behavior_does_not_apply_to_allowed_messages
518520
ActiveSupport::Deprecation.disallowed_behavior = :raise
519521
ActiveSupport::Deprecation.disallowed_warnings = ["foo=nil"]
520522

521-
@dtc.none
523+
assert_nothing_raised { @dtc.none }
522524
end
523525
end
524526

activesupport/test/log_subscriber_test.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ def test_event_attributes
9292
end
9393

9494
def test_does_not_send_the_event_if_it_doesnt_match_the_class
95-
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
96-
instrument "unknown_event.my_log_subscriber"
97-
wait
98-
# If we get here, it means that NoMethodError was not raised.
95+
assert_nothing_raised do
96+
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
97+
instrument "unknown_event.my_log_subscriber"
98+
wait
99+
end
99100
end
100101

101102
def test_does_not_send_the_event_if_logger_is_nil
@@ -108,9 +109,11 @@ def test_does_not_send_the_event_if_logger_is_nil
108109
end
109110

110111
def test_does_not_fail_with_non_namespaced_events
111-
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
112-
instrument "whatever"
113-
wait
112+
assert_nothing_raised do
113+
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
114+
instrument "whatever"
115+
wait
116+
end
114117
end
115118

116119
def test_flushes_loggers

activesupport/test/logger_test.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def test_write_binary_data_to_existing_file
4343
str = +"\x80"
4444
str.force_encoding("ASCII-8BIT")
4545

46-
logger.add Logger::DEBUG, str
46+
assert_nothing_raised do
47+
logger.add Logger::DEBUG, str
48+
end
4749
ensure
4850
logger.close
4951
t.close true
@@ -61,7 +63,9 @@ def test_write_binary_data_create_file
6163
str = +"\x80"
6264
str.force_encoding("ASCII-8BIT")
6365

64-
logger.add Logger::DEBUG, str
66+
assert_nothing_raised do
67+
logger.add Logger::DEBUG, str
68+
end
6569
ensure
6670
logger.close
6771
File.unlink fname

activesupport/test/metadata/shared_metadata_tests.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def test_encryption_and_decryption_with_same_purpose
1414
end
1515

1616
def test_verifies_array_when_purpose_matches
17-
unless null_serializing?
18-
data = [ "credit_card_no: 5012-6748-9087-5678", { "card_holder" => "Donald", "issued_on" => Time.local(2017) }, 12345 ]
19-
assert_equal data, parse(generate(data, purpose: :registration), purpose: :registration)
20-
end
17+
skip if null_serializing?
18+
19+
data = [ "credit_card_no: 5012-6748-9087-5678", { "card_holder" => "Donald", "issued_on" => Time.local(2017) }, 12345 ]
20+
assert_equal data, parse(generate(data, purpose: :registration), purpose: :registration)
2121
end
2222

2323
def test_encryption_and_decryption_with_different_purposes_returns_nil

activesupport/test/notifications_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,10 @@ def test_subscribing_to_instrumentation_while_inside_it
185185

186186
ActiveSupport::Notifications.subscribe("foo", TestSubscriber.new)
187187

188-
ActiveSupport::Notifications.instrument("foo") do
189-
ActiveSupport::Notifications.subscribe("foo") { }
188+
assert_nothing_raised do
189+
ActiveSupport::Notifications.instrument("foo") do
190+
ActiveSupport::Notifications.subscribe("foo") { }
191+
end
190192
end
191193
ensure
192194
ActiveSupport::Notifications.notifier = old_notifier

0 commit comments

Comments
 (0)