diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 8b397899e8..aa44b36d9e 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -177,9 +177,11 @@ def test_get_post_request_switch end def test_string_constraint - with_routing do |set| - set.draw do - get "photos", to: "action_pack_assertions#nothing", constraints: { subdomain: "admin" } + assert_nothing_raised do + with_routing do |set| + set.draw do + get "photos", to: "action_pack_assertions#nothing", constraints: { subdomain: "admin" } + end end end end diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index d197951255..f9c50f6c38 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -310,7 +310,9 @@ def test_setting_flash_does_not_raise_in_following_requests with_test_route_set do env = { "action_dispatch.request.flash_hash" => ActionDispatch::Flash::FlashHash.new } get "/set_flash", env: env - get "/set_flash", env: env + assert_nothing_raised do + get "/set_flash", env: env + end end end @@ -318,7 +320,9 @@ def test_setting_flash_now_does_not_raise_in_following_requests with_test_route_set do env = { "action_dispatch.request.flash_hash" => ActionDispatch::Flash::FlashHash.new } get "/set_flash_now", env: env - get "/set_flash_now", env: env + assert_nothing_raised do + get "/set_flash_now", env: env + end end end diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb index 8c61e4b2d2..2168ea669b 100644 --- a/actionpack/test/controller/live_stream_test.rb +++ b/actionpack/test/controller/live_stream_test.rb @@ -430,6 +430,7 @@ def test_delayed_autoload_after_write_within_interlock_hook res = get :write_sleep_autoload res.each { } ActiveSupport::Dependencies.interlock.done_running + pass end def test_async_stream diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index a210d4a2b6..ed36cd7f5a 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1000,6 +1000,7 @@ def test_live_head_ok @response.stream.on_error { flunk "action should not raise any errors" } sleep 0.2 + pass end end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 2635743c54..119a40e273 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -508,9 +508,11 @@ def setup_for_named_route(options = {}) end def test_named_route_without_hash - rs.draw do - ActionDispatch.deprecator.silence do - get ":controller/:action/:id", as: "normal" + assert_nothing_raised do + rs.draw do + ActionDispatch.deprecator.silence do + get ":controller/:action/:id", as: "normal" + end end end end diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index e2aa8942e7..27ac248318 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -36,7 +36,9 @@ def asts end def test_initialize - Mapper.new FakeSet.new + assert_nothing_raised do + Mapper.new FakeSet.new + end end def test_scope_raises_on_anchor diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 1b2e367b5b..b13b12a030 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -159,6 +159,7 @@ def teardown fixture = FIXTURE_PATH + "/ruby_on_rails.jpg" params = { uploaded_data: fixture_file_upload(fixture, "image/jpeg") } post "/read", params: params + assert_equal Encoding::ASCII_8BIT, response.body.encoding end end diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 28ba2c010c..52629c7fef 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -1152,7 +1152,9 @@ class RequestParameters < BaseRequestTest request = stub_request("QUERY_STRING" => "foo=%81E") ActionDispatch::Request::Utils.stub(:set_binary_encoding, { "foo" => "\x81E".b }) do - request.parameters + assert_nothing_raised do + request.parameters + end end end @@ -1166,7 +1168,9 @@ class RequestParameters < BaseRequestTest ) ActionDispatch::Request::Utils.stub(:set_binary_encoding, { "foo" => "\x81E".b }) do - request.parameters + assert_nothing_raised do + request.parameters + end end end diff --git a/actionpack/test/dispatch/system_testing/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb index 1f340264c4..410934a305 100644 --- a/actionpack/test/dispatch/system_testing/driver_test.rb +++ b/actionpack/test/dispatch/system_testing/driver_test.rb @@ -30,8 +30,10 @@ class DriverTest < ActiveSupport::TestCase test "initializing the driver with a headless chrome and custom path" do original_driver_path = ::Selenium::WebDriver::Chrome::Service.driver_path - ::Selenium::WebDriver::Chrome::Service.driver_path = "bin/test" - ActionDispatch::SystemTesting::Driver.new(:selenium, using: :headless_chrome, screen_size: [1400, 1400]) + assert_nothing_raised do + ::Selenium::WebDriver::Chrome::Service.driver_path = "bin/test" + ActionDispatch::SystemTesting::Driver.new(:selenium, using: :headless_chrome, screen_size: [1400, 1400]) + end ensure ::Selenium::WebDriver::Chrome::Service.driver_path = original_driver_path end @@ -47,8 +49,10 @@ class DriverTest < ActiveSupport::TestCase test "initializing the driver with a headless firefox and custom path" do original_driver_path = ::Selenium::WebDriver::Firefox::Service.driver_path - ::Selenium::WebDriver::Firefox::Service.driver_path = "bin/test" - ActionDispatch::SystemTesting::Driver.new(:selenium, using: :headless_firefox, screen_size: [1400, 1400]) + assert_nothing_raised do + ::Selenium::WebDriver::Firefox::Service.driver_path = "bin/test" + ActionDispatch::SystemTesting::Driver.new(:selenium, using: :headless_firefox, screen_size: [1400, 1400]) + end ensure ::Selenium::WebDriver::Firefox::Service.driver_path = original_driver_path end diff --git a/actiontext/test/unit/strict_loading_test.rb b/actiontext/test/unit/strict_loading_test.rb index f7e8b69ba6..7b6482ba43 100644 --- a/actiontext/test/unit/strict_loading_test.rb +++ b/actiontext/test/unit/strict_loading_test.rb @@ -28,7 +28,9 @@ class MessageWithFooter < MessageWithStrictLoading records = MessageWithStrictLoading.with_rich_text_strict_loading_content.all - records.map(&:strict_loading_content) + assert_nothing_raised do + records.map(&:strict_loading_content) + end end test "has_rich_text accepts strict_loading: overrides" do @@ -36,6 +38,8 @@ class MessageWithFooter < MessageWithStrictLoading records = MessageWithFooter.all - records.map(&:footer) + assert_nothing_raised do + records.map(&:footer) + end end end diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb index bbeb54f4ec..3cae7b1668 100644 --- a/actionview/test/template/date_helper_test.rb +++ b/actionview/test/template/date_helper_test.rb @@ -2848,13 +2848,17 @@ def test_datetime_select_with_separators def test_datetime_select_with_integer @post = Post.new @post.updated_at = 3 - datetime_select("post", "updated_at") + assert_nothing_raised do + datetime_select("post", "updated_at") + end end def test_datetime_select_with_infinity # Float @post = Post.new @post.updated_at = (-1.0 / 0) - datetime_select("post", "updated_at") + assert_nothing_raised do + datetime_select("post", "updated_at") + end end def test_datetime_select_with_default_prompt diff --git a/actionview/test/template/template_test.rb b/actionview/test/template/template_test.rb index ad4dcfe74d..6df34f829a 100644 --- a/actionview/test/template/template_test.rb +++ b/actionview/test/template/template_test.rb @@ -229,7 +229,9 @@ def test_extra_locals_raises_error def test_rails_injected_locals_does_not_raise_error_if_not_passed @template = new_template("<%# locals: (message:) -%>") - render(message: "Hi", message_counter: 1, message_iteration: 1, implicit_locals: %i[message_counter message_iteration]) + assert_nothing_raised do + render(message: "Hi", message_counter: 1, message_iteration: 1, implicit_locals: %i[message_counter message_iteration]) + end end def test_rails_injected_locals_can_be_specified diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index 41bc430c32..b422e2bee9 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -538,7 +538,9 @@ def test_reset_cycle end def test_reset_unknown_cycle - reset_cycle("colors") + assert_nothing_raised do + reset_cycle("colors") + end end def test_reset_named_cycle diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index dba3841708..ca235e6e2c 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -270,7 +270,9 @@ def test_enqueue_at_log_when_enqueue_error_is_set def test_for_tagged_logger_support_is_consistent set_logger ::Logger.new(nil) - OverriddenLoggingJob.perform_later "Dummy" + assert_nothing_raised do + OverriddenLoggingJob.perform_later "Dummy" + end end def test_job_error_logging diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb index cfb3e1d8af..69f5ed457f 100644 --- a/activejob/test/cases/queuing_test.rb +++ b/activejob/test/cases/queuing_test.rb @@ -26,6 +26,7 @@ class QueuingTest < ActiveSupport::TestCase result = HelloJob.set(wait_until: 1.second.ago).perform_later "Jamie" assert result rescue NotImplementedError + pass end test "job returned by enqueue has the arguments available" do @@ -37,6 +38,7 @@ class QueuingTest < ActiveSupport::TestCase job = HelloJob.set(wait_until: Time.utc(2014, 1, 1)).perform_later assert_equal Time.utc(2014, 1, 1), job.scheduled_at rescue NotImplementedError + pass end test "job is yielded to block after enqueue with successfully_enqueued property set" do @@ -80,6 +82,7 @@ class QueuingTest < ActiveSupport::TestCase ActiveJob.perform_all_later(scheduled_job_1, scheduled_job_2) assert_equal ["Scheduled 2014 says hello", "Scheduled 2015 says hello"], JobBuffer.values.sort rescue NotImplementedError + pass end test "perform_all_later instrumentation" do diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb index 1c9c886eae..cc658959b7 100644 --- a/activejob/test/integration/queuing_test.rb +++ b/activejob/test/integration/queuing_test.rb @@ -67,6 +67,7 @@ class QueuingTest < ActiveSupport::TestCase wait_for_jobs_to_finish_for(5.seconds) assert_job_not_executed rescue NotImplementedError + pass end test "should run job enqueued in the future at the specified time" do @@ -76,6 +77,7 @@ class QueuingTest < ActiveSupport::TestCase wait_for_jobs_to_finish_for(10.seconds) assert_job_executed rescue NotImplementedError + pass end test "should run job bulk enqueued in the future at the specified time" do @@ -85,6 +87,7 @@ class QueuingTest < ActiveSupport::TestCase wait_for_jobs_to_finish_for(10.seconds) assert_job_executed rescue NotImplementedError + pass end if adapter_is?(:async, :delayed_job, :sidekiq, :queue_classic) diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb index 3e5e70cf14..aa7a7bd550 100644 --- a/activemodel/test/cases/helper.rb +++ b/activemodel/test/cases/helper.rb @@ -15,14 +15,6 @@ class ActiveModel::TestCase < ActiveSupport::TestCase include ActiveSupport::Testing::MethodCallAssertions - - class AssertionlessTest < StandardError; end - - def after_teardown - super - - raise AssertionlessTest, "No assertions made." if passed? && assertions.zero? - end end require_relative "../../../tools/test_common" diff --git a/activerecord/test/cases/adapter_prevent_writes_test.rb b/activerecord/test/cases/adapter_prevent_writes_test.rb index b1048588f4..e3b93ca786 100644 --- a/activerecord/test/cases/adapter_prevent_writes_test.rb +++ b/activerecord/test/cases/adapter_prevent_writes_test.rb @@ -65,7 +65,9 @@ def test_doesnt_error_when_a_select_query_has_encoding_errors else def test_doesnt_error_when_a_select_query_has_encoding_errors ActiveRecord::Base.while_preventing_writes do - @connection.select_all("SELECT '\xC8'") + assert_nothing_raised do + @connection.select_all("SELECT '\xC8'") + end end end end diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 75c949c467..e8ea3cff3b 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -121,6 +121,8 @@ def test_remove_index_when_name_and_wrong_column_name_specified_positional_argum def test_current_database if @connection.respond_to?(:current_database) assert_equal ARTest.test_configuration_hashes["arunit"]["database"], @connection.current_database + else + skip end end @@ -887,6 +889,7 @@ class AdapterThreadSafetyTest < ActiveRecord::TestCase threads(2, 25) { @connection.disconnect! } join + pass end test "#verify! is synchronized" do @@ -894,6 +897,7 @@ class AdapterThreadSafetyTest < ActiveRecord::TestCase threads(2, 25) { @connection.disconnect! } join + pass end end diff --git a/activerecord/test/cases/adapters/abstract_mysql_adapter/schema_test.rb b/activerecord/test/cases/adapters/abstract_mysql_adapter/schema_test.rb index 4a011399ef..4fd188f3ec 100644 --- a/activerecord/test/cases/adapters/abstract_mysql_adapter/schema_test.rb +++ b/activerecord/test/cases/adapters/abstract_mysql_adapter/schema_test.rb @@ -96,9 +96,11 @@ def test_dump_indexes def test_drop_temporary_table @connection.transaction do @connection.create_table(:temp_table, temporary: true) - # if it doesn't properly say DROP TEMPORARY TABLE, the transaction commit - # will complain that no transaction is active - @connection.drop_table(:temp_table, temporary: true) + assert_nothing_raised do + # if it doesn't properly say DROP TEMPORARY TABLE, the transaction commit + # will complain that no transaction is active + @connection.drop_table(:temp_table, temporary: true) + end end end end diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb index aa7adf4a36..7692aa3ea0 100644 --- a/activerecord/test/cases/adapters/postgresql/connection_test.rb +++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb @@ -167,14 +167,18 @@ def test_set_session_variable_false def test_set_session_variable_nil run_without_connection do |orig_connection| # This should be a no-op that does not raise an error - ActiveRecord::Base.establish_connection(orig_connection.deep_merge(variables: { debug_print_plan: nil })) + assert_nothing_raised do + ActiveRecord::Base.establish_connection(orig_connection.deep_merge(variables: { debug_print_plan: nil })) + end end end def test_set_session_variable_default run_without_connection do |orig_connection| # This should execute a query that does not raise an error - ActiveRecord::Base.establish_connection(orig_connection.deep_merge(variables: { debug_print_plan: :default })) + assert_nothing_raised do + ActiveRecord::Base.establish_connection(orig_connection.deep_merge(variables: { debug_print_plan: :default })) + end end end diff --git a/activerecord/test/cases/adapters/postgresql/schema_test.rb b/activerecord/test/cases/adapters/postgresql/schema_test.rb index 87bf65cb65..cacb8394bb 100644 --- a/activerecord/test/cases/adapters/postgresql/schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/schema_test.rb @@ -184,10 +184,13 @@ def test_raise_wrapped_exception_on_bad_prepare if ActiveRecord::Base.lease_connection.prepared_statements def test_schema_change_with_prepared_stmt altered = false - @connection.exec_query "select * from developers where id = $1", "sql", [bind_param(1)] - @connection.exec_query "alter table developers add column zomg int", "sql", [] - altered = true - @connection.exec_query "select * from developers where id = $1", "sql", [bind_param(1)] + assert_nothing_raised do + @connection.exec_query "select * from developers where id = $1", "sql", [bind_param(1)] + @connection.exec_query "alter table developers add column zomg int", "sql", [] + altered = true + @connection.exec_query "select * from developers where id = $1", "sql", [bind_param(1)] + end + pass ensure # We are not using DROP COLUMN IF EXISTS because that syntax is only # supported by pg 9.X diff --git a/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb b/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb index 215c35c9a1..8938aba2cf 100644 --- a/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb +++ b/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb @@ -82,7 +82,8 @@ def test_schema_dumping end def test_build_fixture_sql - ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :virtual_columns) + fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :virtual_columns).first + assert_equal 2, fixtures.size end end end diff --git a/activerecord/test/cases/adapters/sqlite3/virtual_column_test.rb b/activerecord/test/cases/adapters/sqlite3/virtual_column_test.rb index f4c6d327d8..d29a1f099f 100644 --- a/activerecord/test/cases/adapters/sqlite3/virtual_column_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/virtual_column_test.rb @@ -97,7 +97,8 @@ def test_schema_dumping end def test_build_fixture_sql - ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :virtual_columns) + fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :virtual_columns).first + assert_equal 2, fixtures.size end end end diff --git a/activerecord/test/cases/arel/visitors/dot_test.rb b/activerecord/test/cases/arel/visitors/dot_test.rb index fd5f25e610..e148cf791a 100644 --- a/activerecord/test/cases/arel/visitors/dot_test.rb +++ b/activerecord/test/cases/arel/visitors/dot_test.rb @@ -25,12 +25,14 @@ def assert_edge(edge_name, dot_string) define_method("test_#{klass.name.gsub('::', '_')}") do op = klass.new(:a, "z") @visitor.accept op, Collectors::PlainString.new + pass end end def test_named_function func = Nodes::NamedFunction.new "omg", "omg" @visitor.accept func, Collectors::PlainString.new + pass end # unary ops @@ -48,6 +50,7 @@ def test_named_function define_method("test_#{klass.name.gsub('::', '_')}") do op = klass.new(:a) @visitor.accept op, Collectors::PlainString.new + pass end end @@ -73,6 +76,7 @@ def test_named_function define_method("test_#{klass.name.gsub('::', '_')}") do binary = klass.new(:a, :b) @visitor.accept binary, Collectors::PlainString.new + pass end end @@ -84,6 +88,7 @@ def test_named_function define_method("test_#{klass.name.gsub('::', '_')}") do binary = klass.new([:a, :b]) @visitor.accept binary, Collectors::PlainString.new + pass end end diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 86cc88c884..44c9d5480e 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -1159,8 +1159,10 @@ def test_belongs_to_proxy_should_not_respond_to_private_methods end def test_belongs_to_proxy_should_respond_to_private_methods_via_send - companies(:first_firm).send(:private_method) - companies(:second_client).firm.send(:private_method) + assert_nothing_raised do + companies(:first_firm).send(:private_method) + companies(:second_client).firm.send(:private_method) + end end def test_save_of_record_with_loaded_belongs_to diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index e84fa8b7bc..96b6a1df70 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -572,7 +572,7 @@ def test_string_id_column_joins Subscription.create!(subscriber_id: "PL", book_id: b.id) s.reload - s.book_ids = s.book_ids + assert_equal [b.id], s.book_ids end def test_eager_load_has_many_through_with_string_keys @@ -816,7 +816,8 @@ def test_eager_association_loading_with_habtm end def test_eager_with_inheritance - SpecialPost.all.merge!(includes: [ :comments ]).to_a + posts = SpecialPost.all.merge!(includes: [ :comments ]).to_a + assert_equal 1, posts.size end def test_eager_has_one_with_association_inheritance diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 663749cbd2..1c005fe818 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -3201,10 +3201,12 @@ def test_invalid_key_raises_with_message_including_all_default_options end def test_key_ensuring_owner_was_is_valid_when_dependent_option_is_destroy_async - Class.new(ActiveRecord::Base) do - self.destroy_association_async_job = Class.new + assert_nothing_raised do + Class.new(ActiveRecord::Base) do + self.destroy_association_async_job = Class.new - has_many :books, dependent: :destroy_async, ensuring_owner_was: :destroyed? + has_many :books, dependent: :destroy_async, ensuring_owner_was: :destroyed? + end end end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index f2c4468482..c83c3b697b 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -1253,7 +1253,9 @@ def test_primary_key_option_on_source def test_create_should_not_raise_exception_when_join_record_has_errors repair_validations(Categorization) do Categorization.validate { |r| r.errors.add(:base, "Invalid Categorization") } - Category.create(name: "Fishing", authors: [Author.first]) + assert_nothing_raised do + Category.create(name: "Fishing", authors: [Author.first]) + end end end diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index fa8317fade..3a9687a21d 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -493,8 +493,10 @@ def test_has_one_proxy_should_not_respond_to_private_methods end def test_has_one_proxy_should_respond_to_private_methods_via_send - accounts(:signals37).send(:private_method) - companies(:first_firm).account.send(:private_method) + assert_nothing_raised do + accounts(:signals37).send(:private_method) + companies(:first_firm).account.send(:private_method) + end end def test_save_of_record_with_loaded_has_one diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index 6048443b40..e674bcd5a8 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -245,7 +245,9 @@ def test_has_one_through_proxy_should_not_respond_to_private_methods def test_has_one_through_proxy_should_respond_to_private_methods_via_send clubs(:moustache_club).send(:private_method) - @member.club.send(:private_method) + assert_nothing_raised do + @member.club.send(:private_method) + end end def test_assigning_to_has_one_through_preserves_decorated_join_record diff --git a/activerecord/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb b/activerecord/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb index 100fd53486..702bef1096 100644 --- a/activerecord/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb @@ -285,8 +285,10 @@ def test_can_swap_roles_while_shard_swapping_is_prohibited ActiveRecord::Base.connects_to(shards: { default: { writing: :primary, reading: :primary_replica } }) - ActiveRecord::Base.prohibit_shard_swapping do # no exception - ActiveRecord::Base.connected_to(role: :reading) do + assert_nothing_raised do + ActiveRecord::Base.prohibit_shard_swapping do # no exception + ActiveRecord::Base.connected_to(role: :reading) do + end end end ensure diff --git a/activerecord/test/cases/connection_adapters/schema_cache_test.rb b/activerecord/test/cases/connection_adapters/schema_cache_test.rb index ed0cf27d0e..5344ff459f 100644 --- a/activerecord/test/cases/connection_adapters/schema_cache_test.rb +++ b/activerecord/test/cases/connection_adapters/schema_cache_test.rb @@ -325,7 +325,13 @@ def test_data_source_exist end def test_clear_data_source_cache + # Cache data sources list. + assert @cache.data_source_exists?("courses") + @cache.clear_data_source_cache!("courses") + assert_queries_count(1, include_schema: true) do + @cache.data_source_exists?("courses") + end end test "#columns_hash? is populated by #columns_hash" do diff --git a/activerecord/test/cases/connection_adapters/standalone_connection_test.rb b/activerecord/test/cases/connection_adapters/standalone_connection_test.rb index 565ad81097..e8c2ce0eee 100644 --- a/activerecord/test/cases/connection_adapters/standalone_connection_test.rb +++ b/activerecord/test/cases/connection_adapters/standalone_connection_test.rb @@ -31,6 +31,7 @@ def test_can_throw_away def test_can_close @connection.close + assert_not @connection.active? end end end diff --git a/activerecord/test/cases/custom_locking_test.rb b/activerecord/test/cases/custom_locking_test.rb index cb561b4f2e..0fe7e13159 100644 --- a/activerecord/test/cases/custom_locking_test.rb +++ b/activerecord/test/cases/custom_locking_test.rb @@ -7,8 +7,8 @@ module ActiveRecord class CustomLockingTest < ActiveRecord::TestCase fixtures :people - def test_custom_lock - if current_adapter?(:Mysql2Adapter, :TrilogyAdapter) + if current_adapter?(:Mysql2Adapter, :TrilogyAdapter) + def test_custom_lock assert_match "SHARE MODE", Person.lock("LOCK IN SHARE MODE").to_sql assert_queries_match(/LOCK IN SHARE MODE/) do Person.all.merge!(lock: "LOCK IN SHARE MODE").find(1) diff --git a/activerecord/test/cases/encryption/encryptable_record_api_test.rb b/activerecord/test/cases/encryption/encryptable_record_api_test.rb index ec5af225f9..1f1caffb04 100644 --- a/activerecord/test/cases/encryption/encryptable_record_api_test.rb +++ b/activerecord/test/cases/encryption/encryptable_record_api_test.rb @@ -27,7 +27,9 @@ class ActiveRecord::Encryption::EncryptableRecordApiTest < ActiveRecord::Encrypt end test "encrypt won't fail for classes without attributes to encrypt" do - posts(:welcome).encrypt + assert_nothing_raised do + posts(:welcome).encrypt + end end test "decrypt decrypts encrypted attributes" do diff --git a/activerecord/test/cases/encryption/encryptor_test.rb b/activerecord/test/cases/encryption/encryptor_test.rb index 2d0e683635..583ecaad20 100644 --- a/activerecord/test/cases/encryption/encryptor_test.rb +++ b/activerecord/test/cases/encryption/encryptor_test.rb @@ -70,7 +70,8 @@ class ActiveRecord::Encryption::EncryptorTest < ActiveRecord::EncryptionTestCase encryptor = ActiveRecord::Encryption::Encryptor.new key_provider.stub :decryption_keys, ->(message) { [key] } do - encryptor.decrypt encryptor.encrypt("some text", key_provider: key_provider), key_provider: key_provider + decrypted_text = encryptor.decrypt encryptor.encrypt("some text", key_provider: key_provider), key_provider: key_provider + assert decrypted_text end end diff --git a/activerecord/test/cases/errors_test.rb b/activerecord/test/cases/errors_test.rb index 0d2be944b5..b608c72647 100644 --- a/activerecord/test/cases/errors_test.rb +++ b/activerecord/test/cases/errors_test.rb @@ -7,10 +7,12 @@ def test_can_be_instantiated_with_no_args base = ActiveRecord::ActiveRecordError error_klasses = ObjectSpace.each_object(Class).select { |klass| klass < base } - (error_klasses - [ActiveRecord::AmbiguousSourceReflectionForThroughAssociation]).each do |error_klass| - error_klass.new.inspect - rescue ArgumentError - raise "Instance of #{error_klass} can't be initialized with no arguments" + assert_nothing_raised do + (error_klasses - [ActiveRecord::AmbiguousSourceReflectionForThroughAssociation]).each do |error_klass| + error_klass.new.inspect + rescue ArgumentError + raise "Instance of #{error_klass} can't be initialized with no arguments" + end end end end diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index bedc08b6fa..c40d113ea7 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -34,6 +34,7 @@ require "models/topic" require "models/traffic_light" require "models/treasure" +require "models/tree" require "models/cpk" class FixturesTest < ActiveRecord::TestCase @@ -43,7 +44,7 @@ class FixturesTest < ActiveRecord::TestCase self.use_transactional_tests = false # other_topics fixture should not be included here - fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights + fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights, :trees FIXTURES = %w( accounts binaries companies customers developers developers_projects entrants @@ -550,6 +551,8 @@ def test_yaml_file_with_invalid_column def test_yaml_file_with_symbol_columns ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "trees") + root = Tree.find(1) + assert root end def test_omap_fixtures @@ -820,6 +823,7 @@ def setup end def test_nothing + pass end end @@ -1428,9 +1432,11 @@ def test_supports_polymorphic_belongs_to end def test_only_generates_a_pk_if_necessary - m = Matey.first - m.pirate = pirates(:blackbeard) - m.target = pirates(:redbeard) + assert_nothing_raised do + m = Matey.first + m.pirate = pirates(:blackbeard) + m.target = pirates(:redbeard) + end end def test_supports_sti diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb index 2b64301fce..cdaa749e1f 100644 --- a/activerecord/test/cases/invertible_migration_test.rb +++ b/activerecord/test/cases/invertible_migration_test.rb @@ -475,7 +475,9 @@ def test_migrations_can_handle_foreign_keys_to_specific_tables migration = RevertCustomForeignKeyTable.new InvertibleMigration.migrate(:up) migration.migrate(:up) + assert ActiveRecord::Base.lease_connection.column_exists?(:horses, :owner_id) migration.migrate(:down) + assert_not ActiveRecord::Base.lease_connection.column_exists?(:horses, :owner_id) end # MySQL 5.7 and Oracle do not allow to create duplicate indexes on the same columns diff --git a/activerecord/test/cases/migration/change_schema_test.rb b/activerecord/test/cases/migration/change_schema_test.rb index bc9e529f3b..7468809b69 100644 --- a/activerecord/test/cases/migration/change_schema_test.rb +++ b/activerecord/test/cases/migration/change_schema_test.rb @@ -235,6 +235,7 @@ def test_create_table_with_timestamps_should_create_datetime_columns_with_option def test_create_table_without_a_block connection.create_table table_name + assert connection.table_exists?(table_name) end # SQLite3 will not allow you to add a NOT NULL @@ -359,6 +360,8 @@ def test_change_column_quotes_column_names else connection.execute "insert into testings (#{connection.quote_column_name('select')}) values ('7 chars')" end + + assert_equal 1, connection.select_value("SELECT COUNT(*) FROM testings") end def test_keeping_default_and_notnull_constraints_on_change diff --git a/activerecord/test/cases/migration/check_constraint_test.rb b/activerecord/test/cases/migration/check_constraint_test.rb index 5294902d76..42672a0196 100644 --- a/activerecord/test/cases/migration/check_constraint_test.rb +++ b/activerecord/test/cases/migration/check_constraint_test.rb @@ -319,11 +319,15 @@ class NoForeignKeySupportTest < ActiveRecord::TestCase end def test_add_check_constraint_should_be_noop - @connection.add_check_constraint :products, "discounted_price > 0", name: "discounted_price_check" + assert_nothing_raised do + @connection.add_check_constraint :products, "discounted_price > 0", name: "discounted_price_check" + end end def test_remove_check_constraint_should_be_noop - @connection.remove_check_constraint :products, name: "price_check" + assert_nothing_raised do + @connection.remove_check_constraint :products, name: "price_check" + end end def test_check_constraints_should_raise_not_implemented diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb index 8fb23d38c6..d8b0057fc4 100644 --- a/activerecord/test/cases/migration/index_test.rb +++ b/activerecord/test/cases/migration/index_test.rb @@ -220,7 +220,9 @@ def test_add_index_attribute_length_limit def test_add_index connection.add_index("testings", "last_name") + assert connection.index_exists?("testings", "last_name") connection.remove_index("testings", "last_name") + assert_not connection.index_exists?("testings", "last_name") connection.add_index("testings", ["last_name", "first_name"]) connection.remove_index("testings", column: ["last_name", "first_name"]) diff --git a/activerecord/test/cases/migration/logger_test.rb b/activerecord/test/cases/migration/logger_test.rb index 37a6ee7201..22271aa8f4 100644 --- a/activerecord/test/cases/migration/logger_test.rb +++ b/activerecord/test/cases/migration/logger_test.rb @@ -31,7 +31,9 @@ def test_migration_should_be_run_without_logger previous_logger = ActiveRecord::Base.logger ActiveRecord::Base.logger = nil migrations = [Migration.new("a", 1), Migration.new("b", 2), Migration.new("c", 3)] - ActiveRecord::Migrator.new(:up, migrations, @schema_migration, @internal_metadata).migrate + assert_nothing_raised do + ActiveRecord::Migrator.new(:up, migrations, @schema_migration, @internal_metadata).migrate + end ensure ActiveRecord::Base.logger = previous_logger end diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 9c84eb2934..eb21b9d4f4 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -380,6 +380,7 @@ def test_should_automatically_enable_autosave_on_the_association def test_should_accept_update_only_option @pirate.update(update_only_ship_attributes: { id: @pirate.ship.id, name: "Mayflower" }) + assert_equal "Mayflower", @pirate.reload.ship.name end def test_should_create_new_model_when_nothing_is_there_and_update_only_is_true diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index b11a9dde24..b0d7769135 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -457,15 +457,13 @@ def test_id_predicate_composite end def test_derives_composite_primary_key - def test_primary_key_issues_warning - model = Class.new(ActiveRecord::Base) do - def self.table_name - "uber_barcodes" - end + model = Class.new(ActiveRecord::Base) do + def self.table_name + "uber_barcodes" end - - assert_equal ["region", "code"], model.primary_key end + + assert_equal ["region", "code"], model.primary_key end def test_collectly_dump_composite_primary_key diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb index 0dc9eecfa7..213ec170ea 100644 --- a/activerecord/test/cases/reaper_test.rb +++ b/activerecord/test/cases/reaper_test.rb @@ -118,8 +118,10 @@ def test_reap_flush_on_discarded_pool pool = ConnectionPool.new(pool_config) pool.discard! - pool.reap - pool.flush + assert_nothing_raised do + pool.reap + pool.flush + end end if Process.respond_to?(:fork) diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index ba61785110..5562880724 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -434,10 +434,13 @@ def test_serialized_attribute_can_be_defined_in_abstract_classes end subclass = Class.new(klass) do - self.table_name = "posts" + self.table_name = "topics" end subclass.define_attribute_methods + + topic = subclass.create!(content: { foo: 1 }) + assert_equal [topic], subclass.where(content: { foo: 1 }).to_a end def test_nil_is_always_persisted_as_null diff --git a/activerecord/test/cases/transaction_isolation_test.rb b/activerecord/test/cases/transaction_isolation_test.rb index bfe36a70e5..48d214964b 100644 --- a/activerecord/test/cases/transaction_isolation_test.rb +++ b/activerecord/test/cases/transaction_isolation_test.rb @@ -85,7 +85,9 @@ class Tag2 < ActiveRecord::Base # constraint. test "serializable" do Tag.transaction(isolation: :serializable) do - Tag.create + assert_nothing_raised do + Tag.create + end end end diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index fa633f65c2..2c8f3be0bc 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -469,7 +469,9 @@ def transaction_with_shallow_return def test_add_to_null_transaction topic = Topic.new - topic.send(:add_to_transaction) + assert_nothing_raised do + topic.send(:add_to_transaction) + end end def test_successful_with_return_outside_inner_transaction @@ -1084,7 +1086,7 @@ def test_rollback_when_saving_a_frozen_record end def test_rollback_when_thread_killed - return if in_memory_db? + skip if in_memory_db? queue = Queue.new thread = Thread.new do @@ -1342,41 +1344,41 @@ def test_rollback_for_freshly_persisted_records assert_predicate topic, :persisted?, "persisted" end - def test_sqlite_add_column_in_transaction - return true unless current_adapter?(:SQLite3Adapter) + if current_adapter?(:SQLite3Adapter) + def test_sqlite_add_column_in_transaction + # Test first if column creation/deletion works correctly when no + # transaction is in place. + # + # We go back to the connection for the column queries because + # Topic.columns is cached and won't report changes to the DB - # Test first if column creation/deletion works correctly when no - # transaction is in place. - # - # We go back to the connection for the column queries because - # Topic.columns is cached and won't report changes to the DB - - assert_nothing_raised do - Topic.reset_column_information - Topic.lease_connection.add_column("topics", "stuff", :string) - assert_includes Topic.column_names, "stuff" - - Topic.reset_column_information - Topic.lease_connection.remove_column("topics", "stuff") - assert_not_includes Topic.column_names, "stuff" - end - - if Topic.lease_connection.supports_ddl_transactions? assert_nothing_raised do - Topic.transaction { Topic.lease_connection.add_column("topics", "stuff", :string) } + Topic.reset_column_information + Topic.lease_connection.add_column("topics", "stuff", :string) + assert_includes Topic.column_names, "stuff" + + Topic.reset_column_information + Topic.lease_connection.remove_column("topics", "stuff") + assert_not_includes Topic.column_names, "stuff" end - else - Topic.transaction do - assert_raise(ActiveRecord::StatementInvalid) { Topic.lease_connection.add_column("topics", "stuff", :string) } - raise ActiveRecord::Rollback + + if Topic.lease_connection.supports_ddl_transactions? + assert_nothing_raised do + Topic.transaction { Topic.lease_connection.add_column("topics", "stuff", :string) } + end + else + Topic.transaction do + assert_raise(ActiveRecord::StatementInvalid) { Topic.lease_connection.add_column("topics", "stuff", :string) } + raise ActiveRecord::Rollback + end end - end - ensure - begin - Topic.lease_connection.remove_column("topics", "stuff") - rescue ensure - Topic.reset_column_information + begin + Topic.lease_connection.remove_column("topics", "stuff") + rescue + ensure + Topic.reset_column_information + end end end diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index 8857b4f88e..ab6c6194e3 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -45,7 +45,9 @@ def test_psych_roundtrip_new_object end def test_active_record_relation_serialization - [Topic.all].to_yaml + assert_nothing_raised do + [Topic.all].to_yaml + end end def test_raw_types_are_not_changed_on_round_trip diff --git a/activestorage/test/controllers/disk_controller_test.rb b/activestorage/test/controllers/disk_controller_test.rb index 4c5b24aa28..0f242ce135 100644 --- a/activestorage/test/controllers/disk_controller_test.rb +++ b/activestorage/test/controllers/disk_controller_test.rb @@ -43,6 +43,7 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest blob.delete get blob.url + assert_response :not_found end test "showing blob with invalid key" do diff --git a/activesupport/lib/active_support/testing/strict_warnings.rb b/activesupport/lib/active_support/testing/strict_warnings.rb index 5bc0e55952..b8807eb6ad 100644 --- a/activesupport/lib/active_support/testing/strict_warnings.rb +++ b/activesupport/lib/active_support/testing/strict_warnings.rb @@ -5,6 +5,8 @@ module ActiveSupport module RaiseWarnings # :nodoc: + class WarningError < StandardError; end + PROJECT_ROOT = File.expand_path("../../../../", __dir__) ALLOWED_WARNINGS = Regexp.union( /circular require considered harmful.*delayed_job/, # Bug in delayed job. @@ -34,7 +36,7 @@ def warn(message, ...) return if ALLOWED_WARNINGS.match?(message) return unless ENV["RAILS_STRICT_WARNINGS"] || ENV["BUILDKITE"] - raise message + raise WarningError.new(message) end end end diff --git a/activesupport/lib/active_support/testing/tests_without_assertions.rb b/activesupport/lib/active_support/testing/tests_without_assertions.rb index 86bd1c57da..adfe7d86ff 100644 --- a/activesupport/lib/active_support/testing/tests_without_assertions.rb +++ b/activesupport/lib/active_support/testing/tests_without_assertions.rb @@ -9,12 +9,9 @@ module TestsWithoutAssertions # :nodoc: def after_teardown super - return if skipped? || error? - - if assertions == 0 + if assertions.zero? && !skipped? && !error? file, line = method(name).source_location - message = "Test is missing assertions: `#{name}` #{file}:#{line}" - warn message + warn "Test is missing assertions: `#{name}` #{file}:#{line}" end end end diff --git a/activesupport/test/cache/behaviors/local_cache_behavior.rb b/activesupport/test/cache/behaviors/local_cache_behavior.rb index b20cce4a89..f7ff67e154 100644 --- a/activesupport/test/cache/behaviors/local_cache_behavior.rb +++ b/activesupport/test/cache/behaviors/local_cache_behavior.rb @@ -55,6 +55,7 @@ def test_cleanup_clears_local_cache_but_not_remote_cache begin @cache.cleanup rescue NotImplementedError + pass return # Not implementing cleanup is valid end diff --git a/activesupport/test/cache/stores/redis_cache_store_test.rb b/activesupport/test/cache/stores/redis_cache_store_test.rb index cefb7655e4..1d10c739db 100644 --- a/activesupport/test/cache/stores/redis_cache_store_test.rb +++ b/activesupport/test/cache/stores/redis_cache_store_test.rb @@ -123,7 +123,9 @@ class InitializationTest < ActiveSupport::TestCase end test "instantiating the store doesn't connect to Redis" do - build(url: "redis://localhost:1") + assert_nothing_raised do + build(url: "redis://localhost:1") + end end private diff --git a/activesupport/test/testing/test_without_assertions_test.rb b/activesupport/test/testing/test_without_assertions_test.rb index ab0cd51b51..b8495e6147 100644 --- a/activesupport/test/testing/test_without_assertions_test.rb +++ b/activesupport/test/testing/test_without_assertions_test.rb @@ -14,6 +14,7 @@ module AfterTeardown def after_teardown _out, err = capture_io do super + rescue ActiveSupport::RaiseWarnings::WarningError end assert_match(/Test is missing assertions: `test_without_assertions` .+test_without_assertions_test\.rb:\d+/, err) diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index 40c2b0333d..58491515dd 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -124,6 +124,7 @@ def test_app_update_does_not_generate_unnecessary_bin_files generator = Rails::Generators::AppGenerator.new ["rails"], { api: true, update: true }, { destination_root: destination_root, shell: @shell } quietly { generator.update_bin_files } + pass end private