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 specs for ENV#clone and #dup #1025

Merged
merged 1 commit into from
May 15, 2023

Conversation

AI-Mozi
Copy link
Contributor

@AI-Mozi AI-Mozi commented May 12, 2023

#1016
[Bug #17767]

Now ENV.clone raises TypeError as well as ENV.dup

@AI-Mozi AI-Mozi changed the title Add specs for ENV#clone and #dup Add specs for ENV#clone and #dup May 12, 2023
@AI-Mozi AI-Mozi marked this pull request as ready for review May 12, 2023 13:04
Copy link
Member

@andrykonchin andrykonchin left a comment

Choose a reason for hiding this comment

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

Could you please use capitalised commit messages?

core/env/clone_spec.rb Outdated Show resolved Hide resolved
core/env/clone_spec.rb Outdated Show resolved Hide resolved
core/env/clone_spec.rb Outdated Show resolved Hide resolved
core/env/clone_spec.rb Show resolved Hide resolved
core/env/dup_spec.rb Outdated Show resolved Hide resolved
@AI-Mozi AI-Mozi force-pushed the add_specs_for_env_clone_dup branch from 9c45917 to 161c43e Compare May 15, 2023 09:30
@andrykonchin
Copy link
Member

andrykonchin commented May 15, 2023

Thank you for the specs!

@andrykonchin andrykonchin merged commit 80c98ae into ruby:master May 15, 2023
}.should raise_error(TypeError, /Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash/)
end
end
end
Copy link
Member

Choose a reason for hiding this comment

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

The existing specs for ENV#clone could be improved in bit.

The previous behaviour was to return self:

# Ruby 3.1.3
ENV.equal? ENV.clone # => => true
ENV.object_id == ENV.clone.object_id # => true

So such a case could be added as well (with version guard ruby_version_is ""..."3.2")

-> {
ENV.clone
}.should raise_error(TypeError, /Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash/)
end
Copy link
Member

Choose a reason for hiding this comment

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

This case could also be improved to check that all the allowed arguments (freeze: nil, freeze: true, freeze: false) lead to the TypeError exception.

}.should raise_error(ArgumentError)
end

it "raises ArgumentError when keyword argument is not 'freeze'" do
Copy link
Member

Choose a reason for hiding this comment

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

suggestion:

it "raises ArgumentError when passed keyword argument other than 'freeze'" do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants