1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
# frozen_string_literal: true
require File.expand_path('../acceptance_test_helper', __FILE__)
class KeywordArgumentMatchingTest < Mocha::TestCase
include AcceptanceTestHelper
def setup
setup_acceptance_test
end
def teardown
teardown_acceptance_test
end
def test_should_match_splatted_hash_parameter_with_keyword_args
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(key: 42)
kwargs = { key: 42 }
mock.method(**kwargs)
end
assert_passed(test_result)
end
def test_should_match_splatted_hash_parameter_with_splatted_hash
test_result = run_as_test do
mock = mock()
kwargs = { key: 42 }
mock.expects(:method).with(**kwargs)
mock.method(**kwargs)
end
assert_passed(test_result)
end
def test_should_match_positional_and_keyword_args_with_keyword_args
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(1, key: 42)
mock.method(1, key: 42)
end
assert_passed(test_result)
end
def test_should_match_hash_parameter_with_hash_matcher
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(has_key(:key))
mock.method({ key: 42 })
end
assert_passed(test_result)
end
def test_should_match_splatted_hash_parameter_with_hash_matcher
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(has_key(:key))
kwargs = { key: 42 }
mock.method(**kwargs)
end
assert_passed(test_result)
end
def test_should_match_positional_and_keyword_args_with_hash_matcher
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(1, has_key(:key))
mock.method(1, key: 42)
end
assert_passed(test_result)
end
def test_should_match_keyword_args_with_nested_matcher
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(key: is_a(Integer))
mock.method(key: 42)
end
assert_passed(test_result)
end
def test_should_match_keyword_args_with_matcher_built_using_keyword_args
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(has_entry(:k1, k2: 'v2'))
mock.method(k1: { k2: 'v2' })
end
assert_passed(test_result)
end
def test_should_not_match_keyword_args_with_matcher_built_using_keyword_args
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(has_entry(:k1, k2: 'v2'))
mock.method(k1: { k2: 'v2', k3: 'v3' })
end
assert_failed(test_result)
end
def test_should_match_last_positional_hash_with_hash_matcher
test_result = run_as_test do
mock = mock()
mock.expects(:method).with(1, has_key(:key))
mock.method(1, { key: 42 })
end
assert_passed(test_result)
end
end
|