-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add acceptance tests for keyword arguments
- Loading branch information
1 parent
26c4ae1
commit ddd44a6
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
require File.expand_path('../acceptance_test_helper', __FILE__) | ||
|
||
class KeywordArgumentsTest < Mocha::TestCase | ||
include AcceptanceTest | ||
|
||
def setup | ||
setup_acceptance_test | ||
end | ||
|
||
def teardown | ||
teardown_acceptance_test | ||
end | ||
|
||
def test_should_match_hash_parameter_with_keyword_args | ||
test_result = run_as_test do | ||
mock = mock() | ||
mock.expects(:method).with(:key => 42) | ||
mock.method({ :key => 42 }) | ||
end | ||
assert_passed(test_result) | ||
# with strict keyword matching: | ||
# assert_failed(test_result) | ||
end | ||
|
||
def test_should_match_hash_parameter_with_splatted_keyword_args | ||
test_result = run_as_test do | ||
mock = mock() | ||
mock.expects(:method).with(**{ :key => 42 }) | ||
mock.method({ :key => 42 }) | ||
end | ||
assert_passed(test_result) | ||
# with strict keyword matching: | ||
# assert_failed(test_result) | ||
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) | ||
mock.method(**{ :key => 42 }) | ||
end | ||
assert_passed(test_result) | ||
end | ||
|
||
def test_should_match_splatted_hash_parameter_with_splatted_hash | ||
test_result = run_as_test do | ||
mock = mock() | ||
mock.expects(:method).with(**{ :key => 42 }) | ||
mock.method(**{ :key => 42 }) | ||
end | ||
assert_passed(test_result) | ||
end | ||
|
||
def test_should_match_positional_and_keyword_args_with_last_positional_hash | ||
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) | ||
# with strict keyword matching: | ||
# assert_failed(test_result) | ||
end | ||
|
||
def test_should_match_last_positional_hash_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) | ||
# with strict keyword matching: | ||
# assert_failed(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)) | ||
mock.method(**{ :key => 42 }) | ||
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_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 |