From a9aed2ac94d2e0d1a233a3c193985ae78d7e79e9 Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Fri, 16 Sep 2016 09:44:05 -0700 Subject: improve error message when include assertions fail assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong --- actionpack/test/controller/base_test.rb | 2 +- actionpack/test/controller/flash_test.rb | 2 +- actionpack/test/controller/helper_test.rb | 24 ++++++++++++------------ actionpack/test/controller/render_test.rb | 2 +- actionpack/test/controller/resources_test.rb | 2 +- actionpack/test/dispatch/cookies_test.rb | 6 +++--- actionpack/test/dispatch/header_test.rb | 4 ++-- 7 files changed, 21 insertions(+), 21 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 2edcbc7433..42a5157010 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -194,7 +194,7 @@ class UrlOptionsTest < ActionController::TestCase get "account/overview" end - assert !@controller.class.action_methods.include?("account_overview_path") + assert_not_includes @controller.class.action_methods, "account_overview_path" end end end diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index e5f24f1a3a..dc641c19ab 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -227,7 +227,7 @@ class FlashTest < ActionController::TestCase add_flash_types :foo end subclass_controller_with_no_flash_type = Class.new(test_controller_with_flash_type_foo) - assert subclass_controller_with_no_flash_type._flash_types.include?(:foo) + assert_includes subclass_controller_with_no_flash_type._flash_types, :foo end def test_does_not_add_flash_type_to_parent_class diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 981b67f685..4c6a772062 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -125,13 +125,13 @@ class HelperTest < ActiveSupport::TestCase def test_helper_method assert_nothing_raised { @controller_class.helper_method :delegate_method } - assert master_helper_methods.include?(:delegate_method) + assert_includes master_helper_methods, :delegate_method end def test_helper_attr assert_nothing_raised { @controller_class.helper_attr :delegate_attr } - assert master_helper_methods.include?(:delegate_attr) - assert master_helper_methods.include?(:delegate_attr=) + assert_includes master_helper_methods, :delegate_attr + assert_includes master_helper_methods, :delegate_attr= end def call_controller(klass, action) @@ -168,13 +168,13 @@ class HelperTest < ActiveSupport::TestCase methods = AllHelpersController._helpers.instance_methods # abc_helper.rb - assert methods.include?(:bare_a) + assert_includes methods, :bare_a # fun/games_helper.rb - assert methods.include?(:stratego) + assert_includes methods, :stratego # fun/pdf_helper.rb - assert methods.include?(:foobar) + assert_includes methods, :foobar end def test_all_helpers_with_alternate_helper_dir @@ -185,26 +185,26 @@ class HelperTest < ActiveSupport::TestCase @controller_class.helper :all # helpers/abc_helper.rb should not be included - assert !master_helper_methods.include?(:bare_a) + assert_not_includes master_helper_methods, :bare_a # alternate_helpers/foo_helper.rb - assert master_helper_methods.include?(:baz) + assert_includes master_helper_methods, :baz end def test_helper_proxy methods = AllHelpersController.helpers.methods # Action View - assert methods.include?(:pluralize) + assert_includes methods, :pluralize # abc_helper.rb - assert methods.include?(:bare_a) + assert_includes methods, :bare_a # fun/games_helper.rb - assert methods.include?(:stratego) + assert_includes methods, :stratego # fun/pdf_helper.rb - assert methods.include?(:foobar) + assert_includes methods, :foobar end def test_helper_proxy_in_instance diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 399c7489b7..70e5760764 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -746,7 +746,7 @@ class HeadRenderTest < ActionController::TestCase get :head_with_symbolic_status, params: { status: "no_content" } assert_equal 204, @response.status - assert !@response.headers.include?("Content-Length") + assert_not_includes @response.headers, "Content-Length" assert_response :no_content Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |status, code| diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 29471939d0..b572e7e8d5 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1313,7 +1313,7 @@ class ResourcesTest < ActionController::TestCase def assert_resource_methods(expected, resource, action_method, method) assert_equal expected.length, resource.send("#{action_method}_methods")[method].size, "#{resource.send("#{action_method}_methods")[method].inspect}" expected.each do |action| - assert resource.send("#{action_method}_methods")[method].include?(action), + assert_includes resource.send("#{action_method}_methods")[method], action, "#{method} not in #{action_method} methods: #{resource.send("#{action_method}_methods")[method].inspect}" end end diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index 38cf0a2346..6dcd62572a 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -68,7 +68,7 @@ class CookieJarTest < ActiveSupport::TestCase def test_write_doesnt_set_a_nil_header headers = {} request.cookie_jar.write(headers) - assert !headers.include?("Set-Cookie") + assert_not_includes headers, "Set-Cookie" end end @@ -1115,11 +1115,11 @@ class CookiesTest < ActionController::TestCase assert_equal "david", cookies[:user_name] get :noop - assert !@response.headers.include?("Set-Cookie") + assert_not_includes @response.headers, "Set-Cookie" assert_equal "david", cookies[:user_name] get :noop - assert !@response.headers.include?("Set-Cookie") + assert_not_includes @response.headers, "Set-Cookie" assert_equal "david", cookies[:user_name] end diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 374e618b42..6febd5cb68 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -76,9 +76,9 @@ class HeaderTest < ActiveSupport::TestCase test "key?" do assert @headers.key?("CONTENT_TYPE") - assert @headers.include?("CONTENT_TYPE") + assert_includes @headers, "CONTENT_TYPE" assert @headers.key?("Content-Type") - assert @headers.include?("Content-Type") + assert_includes @headers, "Content-Type" end test "fetch with block" do -- cgit v1.2.3