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

Separate specs for Enumerator#each_with_index and Enumerator#with_index #1168

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

herwinw
Copy link
Member

@herwinw herwinw commented Jun 27, 2024

A couple of them were defined in the wrong file.

Comment on lines 78 to 79
arr.delete_if.with_index { |a,b| a == 1 || b == 1}
arr.should == [3]
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only addition to the moved specs, I wanted to include a small test for the actual behaviour.

Copy link
Member

@andrykonchin andrykonchin Jun 27, 2024

Choose a reason for hiding this comment

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

subjective: with_index { |a,b| true } seems simpler to me (instead of a == 1 || b == 1)

Copy link
Member Author

Choose a reason for hiding this comment

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

And it does make things a bit more consistent as well, I've updated this one.

it "returns the iterator's return value" do
[1,2,3].select.with_index { |a,b| false }.should == []
end

Copy link
Member

@andrykonchin andrykonchin Jun 27, 2024

Choose a reason for hiding this comment

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

Actually #each_with_index behaves in the same way, so it makes sense to have these two cases here as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this one back in, but changed to each_with_index. Added an extra test to check the true-block as well.

Copy link
Member

Choose a reason for hiding this comment

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

Don't you think the second test "passes on the given block's return value" also makes sense to add back?

Copy link
Member Author

Choose a reason for hiding this comment

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

That sound very sensible as well, added that one too.

A couple of them were defined in the wrong file.
@andrykonchin
Copy link
Member

Thank you!

@andrykonchin andrykonchin merged commit 0eb86e1 into ruby:master Jul 1, 2024
14 checks passed
@herwinw herwinw deleted the enumerator_with_index branch July 2, 2024 06:12
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