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 curry_spec #1181

Merged
merged 1 commit into from
Jul 4, 2024
Merged

Fix curry_spec #1181

merged 1 commit into from
Jul 4, 2024

Conversation

herwinw
Copy link
Member

@herwinw herwinw commented Jul 4, 2024

This effectively ran the following code:

    @proc_add = Proc.new {|x,y,z| (x||0) + (y||0) + (z||0) }
    tmp = @proc_add.curry(1)[1,2]
    tmp.curry(3)[3,4,5,6].should == 6

The optional argument to Proc#curry is the arity of the curried proc. In other words: if the curried proc gets called with at least 1 argument, which means the value of tmp in this example will be equal to @proc_add[1,2], the result is an Integer and not a new proc object.

The example with a lambda would raise the error in the curry(1)[1,2] part, so the second test was pretty much the same as the first test.

The old code did pass, because the failing spec was wrapped in a block that should not raise an error. This was indented with a new line after the should_not, which is then seen by Ruby as two separate statements. The block with the failing spec then never gets executed. This looks like the only location in the specs where should or should_not is the last code on a line.

This effectively ran the following code:

    @proc_add = Proc.new {|x,y,z| (x||0) + (y||0) + (z||0) }
    tmp = @proc_add.curry(1)[1,2]
    tmp.curry(3)[3,4,5,6].should == 6

The optional argument to `Proc#curry` is the arity of the curried proc.
In other words: if the curried proc gets called with at least 1
argument, which means the value of `tmp` in this example will be equal
to `@proc_add[1,2]`, the result is an Integer and not a new proc object.

The example with a lambda would raise the error in the `curry(1)[1,2]`
part, so the second test was pretty much the same as the first test.

The old code did pass, because the failing spec was wrapped in a block
that should not raise an error. This was indented with a new line after
the `should_not`, which is then seen by Ruby as two separate statements.
The block with the failing spec then never gets executed. This looks
like the only location in the specs where `should` or `should_not` is
the last code on a line.
@herwinw
Copy link
Member Author

herwinw commented Jul 4, 2024

I split this one from #1180, since this is more than simply reindentation.

@eregon eregon merged commit b43df71 into ruby:master Jul 4, 2024
14 checks passed
@herwinw herwinw deleted the proc_curry branch July 5, 2024 07:01
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