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

Convert to keyword arguments #605

Closed

Conversation

supremebeing7
Copy link

This would resolve #603.

The only two I didn't convert to kwargs was Internet.fix_umlauts and Lorem.characters because those both have a single argument that seemed obvious.

I also didn't touch Finance because there was no documentation or tests for it, so wasn't sure if it is even being used. I can open an issue for that if you want that added. Could probably throw some time towards that next week.

@supremebeing7
Copy link
Author

Hmm, I'm seeing some sporadic test failures that I don't think are related to my work (though they could be.

===============================================================================
Failure:
  Expected <= "2038-01-01 00:00:00 -0800", but got 2038-01-01 20:03:45 -0800.
  <false> is not true.
test_between_with_time_parameters(TestFakerTime)
/Users/marklehman/Desktop/Code/faker/test/test_faker_time.rb:18:in `block in test_between_with_time_parameters'
/Users/marklehman/Desktop/Code/faker/test/test_faker_time.rb:15:in `times'
/Users/marklehman/Desktop/Code/faker/test/test_faker_time.rb:15:in `test_between_with_time_parameters'
     12:     from = Time.at(0)
     13:     to   = Time.at(2145945600)
     14: 
  => 15:     100.times do
     16:       random_time = @tester.between(from: from, to: to)
     17:       assert random_time >= from, "Expected >= \"#{from}\", but got #{random_time}"
     18:       assert random_time <= to  , "Expected <= \"#{to}\", but got #{random_time}"
===============================================================================
===============================================================================
Error: test_vin(TestFakerVehicle)
  NoMethodError: undefined method `match' for 5:Fixnum
/Users/marklehman/Desktop/Code/faker/lib/faker.rb:93:in `fetch'
/Users/marklehman/Desktop/Code/faker/lib/faker/vehicle.rb:15:in `vin'
/Users/marklehman/Desktop/Code/faker/test/test_faker_vehicle.rb:12:in `test_vin'
      9:   end
     10: 
     11:   def test_vin
  => 12:     vin = @tester.vin
     13:     checksum = vin_checksum(vin)
     14: 
     15:     assert vin.length == 17
===============================================================================

The test_vin one in particular is odd, because I didn't touch that file or test, which is what makes me think these sporadic failures are on master. However, I ran tests on master about a dozen times and didn't get these failures, so I'm at a loss. Any thoughts?

@supremebeing7
Copy link
Author

Interesting, travis is failing for ruby 2.0 because it doesn't seem to be respecting the kwargs in one of the files. Not sure what's going on there, I'll get ruby2.0.0 running locally and dive into it this evening.

@supremebeing7
Copy link
Author

I guess this was my lack of knowledge of the keyword arguments feature evolution in ruby. Apparently in 2.0 it raises a syntax error for method definitions like def some_method(first:, second:) such that you have to explicitly give it a default def some_method(first: nil, second: nil). Ruby >= 2.1 has no such problem with the first syntax.

I have updated the few method definitions that were failing with explicit defaults. I have made those defaults raise(ArgumentError) so that the user gets a uniform error for any faker method that they try to invoke with missing required arguments. Let me know if you don't think that's sensible.

I can write a few tests for that behavior as well.

This is needed for Ruby 2.0.0 because it does not allow keyword args with no default
@supremebeing7
Copy link
Author

Tests added, and build is green. Let me know what you think @stympy.

@stympy stympy added this to the 2.0 milestone Dec 24, 2016
@stympy
Copy link
Contributor

stympy commented Dec 24, 2016

I added to the 2.0 milestone since these are BC-breaking changes.

@vbrazo
Copy link
Member

vbrazo commented Oct 19, 2018

Since we're migrating the objects to namespaces #1318, we'll change the arguments to keywords while adding the namespaces. I think it'd be a better idea to concentrate all the changes in this transition instead of doing things separately. Thanks for opening this PR and suggesting this change.

@vbrazo vbrazo closed this Oct 19, 2018
@supremebeing7
Copy link
Author

@vbrazo That makes sense, although looking through some of the comments and PRs linked on #1318 I am not seeing keyword arguments implemented, or even any mention of that they should be. We'll definitely want to make sure contributors are aware of that plan so they can implement their PRs accordingly.

@vbrazo
Copy link
Member

vbrazo commented Oct 19, 2018

@supremebeing7 you're talking about the lorem PR? I'm still working on this PR, and I'll include the keyword arguments :) I'll make sure to ask contributors to add the keyword arguments.

@vbrazo
Copy link
Member

vbrazo commented Oct 19, 2018

I just checked our master branch out and we only have a few namespaces and their methods don't have parameters.

@supremebeing7
Copy link
Author

Sounds good. Thanks for all your hard work.

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.

Suggestion: Convert parameters to keyword arguments
3 participants