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

fix spec: Use a hash for a positoinal argument rather than keywords #17

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

nekketsuuu
Copy link
Contributor

With Ruby >= 3.0 and rspec-mocks gem >= 3.10.3, some test cases fail due to improper use of keyword arguments. This patch fixes it and ensures the success of those test cases.

Failure example:

1) BarbequeClient::Client#create_execution when barbeque is alive enqueues a job to barbeque
   Failure/Error: result = garage_client.post('/v2/job_executions', params)
     #<InstanceDouble(GarageClient::Client) (anonymous)> received :post with unexpected arguments
       expected: ("/v2/job_executions", {:application=>"cookpad", :delay_seconds=>nil, :job=>"NotifyAuthor", :message=>{:user_id=>1}, :queue=>"main"}) (keyword arguments)
            got: ("/v2/job_executions", {:application=>"cookpad", :delay_seconds=>nil, :job=>"NotifyAuthor", :message=>{:user_id=>1}, :queue=>"main"}) (options hash)
   # ./lib/barbeque_client/client.rb:27:in `create_execution'
   # ./spec/barbeque/client_spec.rb:28:in `block (4 levels) in <top (required)>'
   # ./spec/spec_helper.rb:12:in `block (2 levels) in <top (required)>'

References:

https://github.com/cookpad/garage_client/blob/af78afb3505c449d57734dede3b946e708ad31be/lib/garage_client/request.rb#L13
https://github.com/rspec/rspec-mocks/blob/103475e20b0e77df866f9c0574f360337f90aaec/Changelog.md#3103--2022-01-28

@cookpad/infra Would you please review this?

The second argument of GarageClient::Client#post should be a hash rather than keywords
since it expects three positional parameters.

Before this fix, the following error may happen with Ruby >= 3.0 and rspec-mocks >= 3.10.3

```
1) BarbequeClient::Client#create_execution when barbeque is alive enqueues a job to barbeque
   Failure/Error: result = garage_client.post('/v2/job_executions', params)
     #<InstanceDouble(GarageClient::Client) (anonymous)> received :post with unexpected arguments
       expected: ("/v2/job_executions", {:application=>"cookpad", :delay_seconds=>nil, :job=>"NotifyAuthor", :message=>{:user_id=>1}, :queue=>"main"}) (keyword arguments)
            got: ("/v2/job_executions", {:application=>"cookpad", :delay_seconds=>nil, :job=>"NotifyAuthor", :message=>{:user_id=>1}, :queue=>"main"}) (options hash)
   # ./lib/barbeque_client/client.rb:27:in `create_execution'
   # ./spec/barbeque/client_spec.rb:28:in `block (4 levels) in <top (required)>'
   # ./spec/spec_helper.rb:12:in `block (2 levels) in <top (required)>'
```
@nekketsuuu
Copy link
Contributor Author

Thanks!

@nekketsuuu nekketsuuu merged commit bf54842 into master Jan 18, 2024
12 checks passed
@nekketsuuu nekketsuuu deleted the nekketsuuu-fix-body-hash branch January 18, 2024 10:34
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