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 numeric step kw args #3356

Merged
merged 17 commits into from Apr 6, 2016
Merged

Conversation

fmfdias
Copy link
Contributor

@fmfdias fmfdias commented Mar 12, 2015

Hi guys,

This PR adds support for keyword arguments on Numeric#step method.
Since this method spec and implementation were changed during the implementation of #3320, these changes were made over that to avoid conflicts. Because of this, this PR should only be merged after #3320.

Thank you!

@yorickpeterse
Copy link
Contributor

With #3320 being merged, could you rebase according to the master branch? That should get rid of the enum commits from this PR.

@fmfdias
Copy link
Contributor Author

fmfdias commented Mar 12, 2015

Rebase done!

@yorickpeterse
Copy link
Contributor

Looking at this, is this based on recent changes in MRI? If so, is there any link to the commit(s)/NEWS file detailing these changes?


describe :numeric_step, :shared => true do

def get_args(*args)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this was already present before (bit hard to grok based on the diff), but if not then this should be moved into a fixture file of sorts. Doing so keeps the spec files clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The get_args method is new and it's specific to step method specs with kw arguments. It allows to run the tests with different argument passing strategies.
My idea would be to move it into a into a specific helper file. What do you think?

@fmfdias
Copy link
Contributor Author

fmfdias commented Mar 12, 2015

This is based on MRI 2.1.
Here's the NEWS lines https://github.com/ruby/ruby/blob/v2_1_0/NEWS#L102-L106

@fmfdias
Copy link
Contributor Author

fmfdias commented Mar 13, 2015

Hi @yorickpeterse,

Moved the get_args method to a helper file, but I'm still not sure if it's the best place for it.
Should it go to the numeric helper on mspec?

Thanks

@yorickpeterse
Copy link
Contributor

@fmfdias We might not need it at all to begin with, but I'll have to dig through the specs myself to see if that is the case. I'll try to take a look at it this weekend.

@fmfdias
Copy link
Contributor Author

fmfdias commented Mar 13, 2015

Ok :) Let me know of any changes needed!

end
end

raise ArgumentError, "step cannot be 0" if step == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This error is still raised in case of the following:

10.step(100, 0).to_a => ArgumentError: step can't be 0

Is this now taken care of somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic moved to the mirror since to allow it to be shared with the part where the enumerator size is calculated.
You can see it in Rubinius::Mirror::Numeric#step_fetch_args.

@yorickpeterse
Copy link
Contributor

Regarding some of the comments I made: I know part of these specs were copied over from the existing file, but I think now is a good time to clean them up properly. In general these specs really need to be broken up into separate it blocks and a few more describe blocks to clean things up, right now it's a bit messy with the amount of expectations going on at times.

@fmfdias
Copy link
Contributor Author

fmfdias commented Mar 15, 2015

Hi @yorickpeterse

Thanks for the review :)
I replied to some of your comments.

About the spec cleaning, I'll gladly help clearing out this specs.
My main objective was to introduce specs for the new behavior without changing too much of specs that don't need to change to fulfill the purpose. I will continue to proceed this way unless you guys ask for it, like in this case :)

Thank you!
Have a nice Sunday!

@fmfdias
Copy link
Contributor Author

fmfdias commented Mar 18, 2015

Hi @yorickpeterse,

Started the spec cleanup/reorganization.

  • Removed the specs that were testing implementations details
  • Reorganized the test into groups with similar properties
  • Tried to improve their texts (I think they may still need some improvement)
  • Changed from be_kind_of to be_an_instance_of

In terms of the "step as string" argument error specs, I think the idea behind the tests that are being made is to check that even when the strings are numeric representations, the exception is raise. Having this is mind I reorganized them in a slightly different way, but if you think they don't make send, I'll act accordingly :)

While doing this I fixed some specs that could result in false positives (they were using == instead of eql) and fixed one issue that wasn't being caught because of this.

About the ruby_bug guards, should I remove them too?

Don't worry about the commits, I'll rebase this in the end.
Thank you!

@yorickpeterse
Copy link
Contributor

About the ruby_bug guards, should I remove them too?

Yeah, they can be removed. I'll take a closer look at the rest this weekend.

@yorickpeterse yorickpeterse self-assigned this Mar 19, 2015
@yorickpeterse
Copy link
Contributor

Having taken another look, I still stand by having to somehow refactor (out) Object#get_args. I'll play around with the changes during the coming week or so to see if I can come up with a nice way to solve this problem.

@fmfdias
Copy link
Contributor Author

fmfdias commented Apr 29, 2015

Hi @yorickpeterse,

Sorry about the late reply. Unfortunately I'm not having too much time lately. Today I had a little, so I tried to come back to this and try a different approach to the last standing issue :)

Instead of using a helper method as a way help share specs between different argument passing types, the shared spec now requires a variable with a Proc/lambda to transform the arguments to the desired argument passing type.
When using the shared spec, a lambda that does the transformation is defined for each of the argument type that we want to test.
Most important, to help understand what's being done I added some comments near the lambdas definitions and a comment on the shared spec definition.

While doing this, I also synced master changes into the branch.

Thanks!

@yorickpeterse
Copy link
Contributor

I'll take a look at this somewhere this week.

One thing I wonder: do we have to duplicate tests for both positional and keyword argument forms? Can we perhaps not write the tests for positional arguments and then a few simple ones to check if keyword arguments are also used? I'm not sure if this would be more rigid, but it would probably simplify the sharing of specs a bit.

@fmfdias
Copy link
Contributor Author

fmfdias commented Apr 29, 2015

Hi @yorickpeterse,

Thanks!
I think I see your point... Since the behavior of the method is the "same" no whatever the argument style is, we may skip repeating it for different form types.
The idea behind this is that they are different arguments that have the same meaning, much like having an alias method. In those cases we also test that the alias method behaves like the original one.
To complicate things a bit, we can mix positional and keyword arguments style and this is also being tested.
An example of why this might come in handy: I ran the test against jruby 9000 pre2 and the test enters in a infinite loop in the shared section.

Note: When using keyword arguments the method accept 0 as step, while the positional argument style doesn't. That's why I placed the same between quotes when I said the behavior of the method is the same.

Thank you!

@fmfdias fmfdias force-pushed the add_numeric_step_kw_args branch 2 times, most recently from 34a4d79 to 8cbd36d Compare June 6, 2015 14:29
@brixen brixen merged commit bd606b5 into rubinius:master Apr 6, 2016
@brixen
Copy link
Member

brixen commented Apr 6, 2016

@fmfdias sorry it took so long to merge this. Thanks for the help!

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

Successfully merging this pull request may close these issues.

None yet

3 participants