Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add acceptance tests for keyword arguments #551

Closed

Conversation

wasabigeek
Copy link
Contributor

@wasabigeek wasabigeek commented Sep 16, 2022

Add some acceptance tests for keyword arguments, somewhat adapted from https://github.com/ruby/ruby/blob/4643bf5d55af6f79266dd67b69bb6eb4ff82029a/doc/NEWS-2.7.0#the-spec-of-keyword-arguments-is-changed-towards-30-.

This is in preparation for supporting strict keyword argument matching, as sketched out in #544 and #446 (comment). These tests will be adjusted subsequently when strict keyword matching is enabled.

TODO:

  • test Hash matchers e.g. has_value

@wasabigeek wasabigeek force-pushed the add-keyword-argument-tests branch 2 times, most recently from 6e58cad to dabf62e Compare September 18, 2022 14:07
@wasabigeek wasabigeek marked this pull request as ready for review September 18, 2022 14:38
@wasabigeek
Copy link
Contributor Author

Even with the check for Ruby version > 2, it seems like the parsing fails. We can wait for the 1.9 drop or remove the offending tests first, what do you prefer @floehopper? I personally would prefer the former 😄

419 tests, 801 assertions, 0 failures, 0 errors, 0 skips
/usr/local/bin/ruby -w -I"lib:test" -I"/usr/local/bundle/gems/rake-12.2.1/lib" "/usr/local/bundle/gems/rake-12.2.1/lib/rake/rake_test_loader.rb" "test/acceptance/bug_18914_test.rb" "test/acceptance/bug_21465_test.rb" "test/acceptance/bug_21563_test.rb" "test/acceptance/display_matching_invocations_alongside_expectations_test.rb" "test/acceptance/exception_rescue_test.rb" "test/acceptance/expectations_on_multiple_methods_test.rb" "test/acceptance/expected_invocation_count_test.rb" "test/acceptance/failure_messages_test.rb" "test/acceptance/issue_272_test.rb" "test/acceptance/issue_457_test.rb" "test/acceptance/issue_524_test.rb" "test/acceptance/issue_65_test.rb" "test/acceptance/issue_70_test.rb" "test/acceptance/keyword_arguments_test.rb" "test/acceptance/mocha_example_test.rb" "test/acceptance/mocha_test_result_test.rb" "test/acceptance/mock_built_with_first_argument_type_being_string_test.rb" "test/acceptance/mock_test.rb" "test/acceptance/mocked_methods_dispatch_test.rb" "test/acceptance/multiple_expectations_failure_message_test.rb" "test/acceptance/multiple_yielding_test.rb" "test/acceptance/optional_parameters_test.rb" "test/acceptance/parameter_matcher_test.rb" "test/acceptance/partial_mocks_test.rb" "test/acceptance/prepend_test.rb" "test/acceptance/prevent_use_of_mocha_outside_test_test.rb" "test/acceptance/raise_exception_test.rb" "test/acceptance/return_value_test.rb" "test/acceptance/sequence_test.rb" "test/acceptance/states_test.rb" "test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb" "test/acceptance/stub_any_instance_method_test.rb" "test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb" "test/acceptance/stub_class_method_defined_on_class_test.rb" "test/acceptance/stub_class_method_defined_on_module_test.rb" "test/acceptance/stub_class_method_defined_on_superclass_test.rb" "test/acceptance/stub_everything_test.rb" "test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb" "test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb" "test/acceptance/stub_instance_method_defined_on_class_test.rb" "test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb" "test/acceptance/stub_instance_method_defined_on_module_test.rb" "test/acceptance/stub_instance_method_defined_on_object_class_test.rb" "test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb" "test/acceptance/stub_instance_method_defined_on_superclass_test.rb" "test/acceptance/stub_method_defined_on_module_and_aliased_test.rb" "test/acceptance/stub_module_method_test.rb" "test/acceptance/stub_test.rb" "test/acceptance/stubba_example_test.rb" "test/acceptance/stubba_test_result_test.rb" "test/acceptance/stubbing_error_backtrace_test.rb" "test/acceptance/stubbing_frozen_object_test.rb" "test/acceptance/stubbing_method_accepting_block_parameter_test.rb" "test/acceptance/stubbing_method_unnecessarily_test.rb" "test/acceptance/stubbing_nil_test.rb" "test/acceptance/stubbing_non_existent_any_instance_method_test.rb" "test/acceptance/stubbing_non_existent_class_method_test.rb" "test/acceptance/stubbing_non_existent_instance_method_test.rb" "test/acceptance/stubbing_non_public_any_instance_method_test.rb" "test/acceptance/stubbing_non_public_class_method_test.rb" "test/acceptance/stubbing_non_public_instance_method_test.rb" "test/acceptance/stubbing_on_non_mock_object_test.rb" "test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb" "test/acceptance/throw_test.rb" "test/acceptance/unexpected_invocation_test.rb" "test/acceptance/unstubbing_test.rb" "test/acceptance/yielding_test.rb" 
Detected MiniTest version: 2.5.1
Mocha deprecation warning at /root/project/test/acceptance/acceptance_test_helper.rb:8:in `require': Versions of minitest earlier than v3.3.0 will not be supported in future versions of Mocha.
Applying monkey patch for MiniTest gem >= v2.3.0 <= v2.10.1
/root/project/test/acceptance/keyword_arguments_test.rb:54: warning: mismatched indentations at 'end' with 'def' at 46
/root/project/test/acceptance/keyword_arguments_test.rb:105: warning: mismatched indentations at 'end' with 'def' at 97
/root/project/test/acceptance/keyword_arguments_test.rb:124: warning: mismatched indentations at 'end' with 'if' at 96
/usr/local/bundle/gems/rake-12.2.1/lib/rake/rake_test_loader.rb:17:in `require': /root/project/test/acceptance/keyword_arguments_test.rb:29: syntax error, unexpected tPOW, expecting ')' (SyntaxError)
        mock.expects(:method).with(**{ :key => 42 })
                                     ^
/root/project/test/acceptance/keyword_arguments_test.rb:29: syntax error, unexpected ')', expecting keyword_end
/root/project/test/acceptance/keyword_arguments_test.rb:41: syntax error, unexpected tPOW, expecting ')'
        mock.method(**{ :key => 42 })
                      ^
/root/project/test/acceptance/keyword_arguments_test.rb:41: syntax error, unexpected ')', expecting keyword_end
/root/project/test/acceptance/keyword_arguments_test.rb:49: syntax error, unexpected tPOW, expecting ')'
        mock.expects(:method).with(**{ :key => 42 })
                                     ^
/root/project/test/acceptance/keyword_arguments_test.rb:49: syntax error, unexpected ')', expecting keyword_end
/root/project/test/acceptance/keyword_arguments_test.rb:50: syntax error, unexpected tPOW, expecting ')'
        mock.method(**{ :key => 42 })
                      ^
/root/project/test/acceptance/keyword_arguments_test.rb:50: syntax error, unexpected ')', expecting keyword_end
/root/project/test/acceptance/keyword_arguments_test.rb:101: syntax error, unexpected tPOW, expecting ')'
        mock.method(**{ :key => 42 })
                      ^
/root/project/test/acceptance/keyword_arguments_test.rb:101: syntax error, unexpected ')', expecting keyword_end
/root/project/test/acceptance/keyword_arguments_test.rb:124: syntax error, unexpected $end, expecting keyword_end
	from /usr/local/bundle/gems/rake-12.2.1/lib/rake/rake_test_loader.rb:17:in `block in <main>'
	from /usr/local/bundle/gems/rake-12.2.1/lib/rake/rake_test_loader.rb:5:in `select'
	from /usr/local/bundle/gems/rake-12.2.1/lib/rake/rake_test_loader.rb:5:in `<main>'
rake aborted!

@floehopper
Copy link
Member

Even with the check for Ruby version > 2, it seems like the parsing fails. We can wait for the 1.9 drop or remove the offending tests first, what do you prefer @floehopper? I personally would prefer the former 😄

I agree that dropping support for Ruby v1.9 first seems like the most sensible option and I should have some availability to make that happen in the next couple of weeks.

@wasabigeek wasabigeek force-pushed the add-keyword-argument-tests branch from 715fbb5 to ddd44a6 Compare September 25, 2022 13:57
@floehopper floehopper self-assigned this Sep 26, 2022
@floehopper floehopper self-requested a review September 26, 2022 11:41
Copy link
Member

@floehopper floehopper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for all your work on this. It all looks good to me - I particularly appreciate your thoroughness in adding all these test scenarios.

I've added a couple of small requests inline. Also could you add the information from the PR description into the commit note. I prefer the commit notes to stand on their own and not rely on information in the PRs in case the repo is moved away from GitHub at some point.

Style/BracesAroundHashParameters:
Exclude:
# we specifically want to test hash parameters
- 'test/acceptance/keyword_arguments_test.rb'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I think I would prefer this to be disabled in the actual file i.e. around the whole test case if necessary. In my experience, these file-level exclusions tend to get missed/forgotten about over time.

Style/BracesAroundHashParameters:
Exclude:
# we specifically want to test hash parameters
- 'test/acceptance/keyword_arguments_test.rb'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I think I would prefer this to be disabled in the actual file i.e. around the whole test case if necessary. In my experience, these file-level exclusions tend to get missed/forgotten about over time.

Comment on lines +21 to +22
# with strict keyword matching:
# assert_failed(test_result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you've done it, but I would prefer not to commit any of these commented-out lines to main.

Comment on lines +21 to +22
# with strict keyword matching:
# assert_failed(test_result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you've done it, but I would prefer not to commit any of these commented-out lines to main.

@wasabigeek
Copy link
Contributor Author

Combined into #554

@wasabigeek wasabigeek closed this Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants