diff --git a/lib/mocha/ruby_version.rb b/lib/mocha/ruby_version.rb index 124eb472..8bcf7973 100644 --- a/lib/mocha/ruby_version.rb +++ b/lib/mocha/ruby_version.rb @@ -1,3 +1,4 @@ module Mocha RUBY_V27_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.7') + RUBY_V34_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('3.4') end diff --git a/test/acceptance/keyword_argument_matching_test.rb b/test/acceptance/keyword_argument_matching_test.rb index 8988d390..e3372104 100644 --- a/test/acceptance/keyword_argument_matching_test.rb +++ b/test/acceptance/keyword_argument_matching_test.rb @@ -3,6 +3,7 @@ require 'deprecation_disabler' require 'execution_point' require 'mocha/deprecation' +require 'mocha/ruby_version' class KeywordArgumentMatchingTest < Mocha::TestCase include AcceptanceTest @@ -24,7 +25,8 @@ def test_should_match_hash_parameter_with_keyword_args mock.method({ key: 42 }) # rubocop:disable Style/BracesAroundHashParameters end if Mocha::RUBY_V27_PLUS - location = "#{execution_point.file_name}:#{execution_point.line_number}:in `block in #{test_name}'" + opening_quote = Mocha::RUBY_V34_PLUS ? "'" : '`' + location = "#{execution_point.file_name}:#{execution_point.line_number}:in #{opening_quote}block in #{test_name}'" assert_includes Mocha::Deprecation.messages.last, "Expectation defined at #{location} expected keyword arguments (key: 42)" assert_includes Mocha::Deprecation.messages.last, 'but received positional hash ({:key => 42})' end @@ -54,7 +56,8 @@ def test_should_match_hash_parameter_with_splatted_keyword_args mock.method({ key: 42 }) # rubocop:disable Style/BracesAroundHashParameters end if Mocha::RUBY_V27_PLUS - location = "#{execution_point.file_name}:#{execution_point.line_number}:in `block in #{test_name}'" + opening_quote = Mocha::RUBY_V34_PLUS ? "'" : '`' + location = "#{execution_point.file_name}:#{execution_point.line_number}:in #{opening_quote}block in #{test_name}'" assert_includes Mocha::Deprecation.messages.last, "Expectation defined at #{location} expected keyword arguments (key: 42)" assert_includes Mocha::Deprecation.messages.last, 'but received positional hash ({:key => 42})' end @@ -102,7 +105,8 @@ def test_should_match_positional_and_keyword_args_with_last_positional_hash mock.method(1, key: 42) end if Mocha::RUBY_V27_PLUS - location = "#{execution_point.file_name}:#{execution_point.line_number}:in `block in #{test_name}'" + opening_quote = Mocha::RUBY_V34_PLUS ? "'" : '`' + location = "#{execution_point.file_name}:#{execution_point.line_number}:in #{opening_quote}block in #{test_name}'" assert_includes Mocha::Deprecation.messages.last, "Expectation defined at #{location} expected positional hash ({:key => 42})" assert_includes Mocha::Deprecation.messages.last, 'but received keyword arguments (key: 42)' end @@ -132,7 +136,8 @@ def test_should_match_last_positional_hash_with_keyword_args mock.method(1, { key: 42 }) # rubocop:disable Style/BracesAroundHashParameters end if Mocha::RUBY_V27_PLUS - location = "#{execution_point.file_name}:#{execution_point.line_number}:in `block in #{test_name}'" + opening_quote = Mocha::RUBY_V34_PLUS ? "'" : '`' + location = "#{execution_point.file_name}:#{execution_point.line_number}:in #{opening_quote}block in #{test_name}'" assert_includes Mocha::Deprecation.messages.last, "Expectation defined at #{location} expected keyword arguments (key: 42)" assert_includes Mocha::Deprecation.messages.last, 'but received positional hash ({:key => 42})' end diff --git a/test/unit/parameter_matchers/positional_or_keyword_hash_test.rb b/test/unit/parameter_matchers/positional_or_keyword_hash_test.rb index 591a01b9..dbc874e5 100644 --- a/test/unit/parameter_matchers/positional_or_keyword_hash_test.rb +++ b/test/unit/parameter_matchers/positional_or_keyword_hash_test.rb @@ -6,6 +6,7 @@ require 'mocha/parameter_matchers/instance_methods' require 'mocha/inspect' require 'mocha/expectation' +require 'mocha/ruby_version' class PositionalOrKeywordHashTest < Mocha::TestCase include Mocha::ParameterMatchers @@ -69,7 +70,8 @@ def test_should_match_hash_arg_with_keyword_args_but_display_deprecation_warning return unless Mocha::RUBY_V27_PLUS message = Mocha::Deprecation.messages.last - location = "#{execution_point.file_name}:#{execution_point.line_number}:in `new'" + opening_quote = Mocha::RUBY_V34_PLUS ? "'" : '`' + location = "#{execution_point.file_name}:#{execution_point.line_number}:in #{opening_quote}new'" assert_includes message, "Expectation defined at #{location} expected keyword arguments (key_1: 1, key_2: 2)" assert_includes message, 'but received positional hash ({:key_1 => 1, :key_2 => 2})' assert_includes message, 'These will stop matching when strict keyword argument matching is enabled.' @@ -85,7 +87,8 @@ def test_should_match_keyword_args_with_hash_arg_but_display_deprecation_warning return unless Mocha::RUBY_V27_PLUS message = Mocha::Deprecation.messages.last - location = "#{execution_point.file_name}:#{execution_point.line_number}:in `new'" + opening_quote = Mocha::RUBY_V34_PLUS ? "'" : '`' + location = "#{execution_point.file_name}:#{execution_point.line_number}:in #{opening_quote}new'" assert_includes message, "Expectation defined at #{location} expected positional hash ({:key_1 => 1, :key_2 => 2})" assert_includes message, 'but received keyword arguments (key_1: 1, key_2: 2)' assert_includes message, 'These will stop matching when strict keyword argument matching is enabled.'