Skip to content

Commit

Permalink
Extract assert_deprecation_warning_location method
Browse files Browse the repository at this point in the history
In `LooseKeywordArgumentMatchingTest` to make tests _slightly_ more
readable.
  • Loading branch information
floehopper committed Jan 3, 2025
1 parent c78baef commit b7919fd
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions test/acceptance/loose_keyword_argument_matching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ def test_should_match_hash_parameter_with_keyword_args
end
end
if Mocha::RUBY_V27_PLUS
assert_deprecation_warning_location(test_result, execution_point)
assert_deprecation_warning(
test_result,
"Expectation defined at #{execution_point.location} " \
'expected keyword arguments (key: 42), but received positional hash ({key: 42})'
test_result, 'expected keyword arguments (key: 42), but received positional hash ({key: 42})'
)
end
assert_passed(test_result)
Expand All @@ -47,10 +46,9 @@ def test_should_match_hash_parameter_with_splatted_keyword_args
end
end
if Mocha::RUBY_V27_PLUS
assert_deprecation_warning_location(test_result, execution_point)
assert_deprecation_warning(
test_result,
"Expectation defined at #{execution_point.location} " \
'expected keyword arguments (key: 42), but received positional hash ({key: 42})'
test_result, 'expected keyword arguments (key: 42), but received positional hash ({key: 42})'
)
end
assert_passed(test_result)
Expand All @@ -66,10 +64,9 @@ def test_should_match_positional_and_keyword_args_with_last_positional_hash
end
end
if Mocha::RUBY_V27_PLUS
assert_deprecation_warning_location(test_result, execution_point)
assert_deprecation_warning(
test_result,
"Expectation defined at #{execution_point.location} " \
'expected positional hash ({key: 42}), but received keyword arguments (key: 42)'
test_result, 'expected positional hash ({key: 42}), but received keyword arguments (key: 42)'
)
end
assert_passed(test_result)
Expand All @@ -85,10 +82,9 @@ def test_should_match_last_positional_hash_with_keyword_args
end
end
if Mocha::RUBY_V27_PLUS
assert_deprecation_warning_location(test_result, execution_point)
assert_deprecation_warning(
test_result,
"Expectation defined at #{execution_point.location} " \
'expected keyword arguments (key: 42), but received positional hash ({key: 42})'
test_result, 'expected keyword arguments (key: 42), but received positional hash ({key: 42})'
)
end
assert_passed(test_result)
Expand All @@ -99,4 +95,9 @@ def test_should_match_last_positional_hash_with_keyword_args
def assert_deprecation_warning(test_result, expected_warning)
assert_includes test_result.last_deprecation_warning, expected_warning
end

def assert_deprecation_warning_location(test_result, execution_point)
expected_location = "Expectation defined at #{execution_point.location}"
assert_deprecation_warning test_result, expected_location
end
end

0 comments on commit b7919fd

Please sign in to comment.