Skip to content

Commit

Permalink
Merge pull request #44442 from nvasilevski/fix-some-assertionless-tests
Browse files Browse the repository at this point in the history
[Active Support] Add explicit assertions to tests with no assertions
  • Loading branch information
byroot committed Feb 16, 2022
2 parents e69620c + 4219696 commit e754787
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 24 deletions.
Expand Up @@ -28,7 +28,7 @@ def assert_called_with(object, method_name, args, returns: nil, &block)

object.stub(method_name, mock, &block)

mock.verify
assert_mock(mock)
end

def assert_not_called(object, method_name, message = nil, &block)
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/cache/stores/file_store_test.rb
Expand Up @@ -47,7 +47,7 @@ def test_clear

def test_clear_without_cache_dir
FileUtils.rm_r(cache_dir)
@cache.clear
assert_nothing_raised { @cache.clear }
end

def test_long_uri_encoded_keys
Expand Down
5 changes: 5 additions & 0 deletions activesupport/test/cache/stores/null_store_test.rb
Expand Up @@ -10,11 +10,15 @@ def setup
end

def test_clear
@cache.write("name", "value")
@cache.clear
assert_nil @cache.read("name")
end

def test_cleanup
@cache.write("name", "value")
@cache.cleanup
assert_nil @cache.read("name")
end

def test_write
Expand Down Expand Up @@ -44,6 +48,7 @@ def test_decrement
def test_delete_matched
@cache.write("name", "value")
@cache.delete_matched(/name/)
assert_nil @cache.read("name")
end

def test_local_store_strategy
Expand Down
10 changes: 6 additions & 4 deletions activesupport/test/core_ext/kernel_test.rb
Expand Up @@ -45,9 +45,11 @@ def test_reraise
end

def test_suppression
suppress(ArgumentError) { raise ArgumentError }
suppress(LoadError) { raise LoadError }
suppress(LoadError, ArgumentError) { raise LoadError }
suppress(LoadError, ArgumentError) { raise ArgumentError }
assert_nothing_raised do
suppress(ArgumentError) { raise ArgumentError }
suppress(LoadError) { raise LoadError }
suppress(LoadError, ArgumentError) { raise LoadError }
suppress(LoadError, ArgumentError) { raise ArgumentError }
end
end
end
8 changes: 5 additions & 3 deletions activesupport/test/deprecation_test.rb
Expand Up @@ -508,8 +508,10 @@ def test_allows_configuration_of_disallowed_warnings
def test_no_disallowed_behavior_with_no_disallowed_messages
resetting_disallowed_deprecation_config do
ActiveSupport::Deprecation.disallowed_behavior = :raise
@dtc.none
@dtc.partially
assert_nothing_raised do
@dtc.none
@dtc.partially
end
end
end

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

@dtc.none
assert_nothing_raised { @dtc.none }
end
end

Expand Down
17 changes: 10 additions & 7 deletions activesupport/test/log_subscriber_test.rb
Expand Up @@ -92,10 +92,11 @@ def test_event_attributes
end

def test_does_not_send_the_event_if_it_doesnt_match_the_class
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
instrument "unknown_event.my_log_subscriber"
wait
# If we get here, it means that NoMethodError was not raised.
assert_nothing_raised do
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
instrument "unknown_event.my_log_subscriber"
wait
end
end

def test_does_not_send_the_event_if_logger_is_nil
Expand All @@ -108,9 +109,11 @@ def test_does_not_send_the_event_if_logger_is_nil
end

def test_does_not_fail_with_non_namespaced_events
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
instrument "whatever"
wait
assert_nothing_raised do
ActiveSupport::LogSubscriber.attach_to :my_log_subscriber, @log_subscriber
instrument "whatever"
wait
end
end

def test_flushes_loggers
Expand Down
8 changes: 6 additions & 2 deletions activesupport/test/logger_test.rb
Expand Up @@ -43,7 +43,9 @@ def test_write_binary_data_to_existing_file
str = +"\x80"
str.force_encoding("ASCII-8BIT")

logger.add Logger::DEBUG, str
assert_nothing_raised do
logger.add Logger::DEBUG, str
end
ensure
logger.close
t.close true
Expand All @@ -61,7 +63,9 @@ def test_write_binary_data_create_file
str = +"\x80"
str.force_encoding("ASCII-8BIT")

logger.add Logger::DEBUG, str
assert_nothing_raised do
logger.add Logger::DEBUG, str
end
ensure
logger.close
File.unlink fname
Expand Down
8 changes: 4 additions & 4 deletions activesupport/test/metadata/shared_metadata_tests.rb
Expand Up @@ -14,10 +14,10 @@ def test_encryption_and_decryption_with_same_purpose
end

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

data = [ "credit_card_no: 5012-6748-9087-5678", { "card_holder" => "Donald", "issued_on" => Time.local(2017) }, 12345 ]
assert_equal data, parse(generate(data, purpose: :registration), purpose: :registration)
end

def test_encryption_and_decryption_with_different_purposes_returns_nil
Expand Down
6 changes: 4 additions & 2 deletions activesupport/test/notifications_test.rb
Expand Up @@ -185,8 +185,10 @@ def test_subscribing_to_instrumentation_while_inside_it

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

ActiveSupport::Notifications.instrument("foo") do
ActiveSupport::Notifications.subscribe("foo") { }
assert_nothing_raised do
ActiveSupport::Notifications.instrument("foo") do
ActiveSupport::Notifications.subscribe("foo") { }
end
end
ensure
ActiveSupport::Notifications.notifier = old_notifier
Expand Down

0 comments on commit e754787

Please sign in to comment.