-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 warn for positional arguments when using Faker 2.0 #1698
Add warn for positional arguments when using Faker 2.0 #1698
Conversation
5344312
to
eec6a11
Compare
This PR fixes an argument for test_faker_stripe.rb. This change was hidden by the same `ArgumentError` in different messages. ## Expected error ```console Faker::Stripe.valid_card(card_type: Faker::Lorem.word) # => ArgumentError: Valid credit cards argument can be left blank or include # visa, visa_debit, mc, mc_2_series, mc_debit, mc_prepaid, amex, amex_2, # discover, discover_2, diners_club, diners_club_2, jcb # from # /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:13:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(card_error: Faker::Lorem.word) # => ArgumentError: Invalid credit cards argument can be left blank or # include addressZipFail, addressFail, zipFail, addressZipUnavailable, # cvcFail, customerChargeFail, successWithReview, declineCard, # declineFraudulentCard, declineIncorrectCvc, declineExpired, # declineProcessingError, declineIncorrectNumber # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:43:in # `invalid_card' ``` ## Actual error ```console Faker::Stripe.valid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:6:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:36:in # `invalid_card' ``` This was found by running the test with faker-ruby#1698. ```console % bundle exec rake test Loaded suite /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.1/lib/rake/rake_test_loader Started (snip) /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:38: Passing `card_error` with the 1st argument of `Stripe.invalid_card` is deprecated. Use keyword argument like `Stripe.invalid_card(card_error: ...)` instead. /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:16: Passing `card_type` with the 1st argument of `Stripe.valid_card` is deprecated. Use keyword argument like `Stripe.valid_card(card_type: ...)` instead. ```
This PR fixes an argument for test_faker_stripe.rb. This change was hidden by the same `ArgumentError` in different messages. ## Expected error ```console Faker::Stripe.valid_card(card_type: Faker::Lorem.word) # => ArgumentError: Valid credit cards argument can be left blank or include # visa, visa_debit, mc, mc_2_series, mc_debit, mc_prepaid, amex, amex_2, # discover, discover_2, diners_club, diners_club_2, jcb # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:13:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(card_error: Faker::Lorem.word) # => ArgumentError: Invalid credit cards argument can be left blank or # include addressZipFail, addressFail, zipFail, addressZipUnavailable, # cvcFail, customerChargeFail, successWithReview, declineCard, # declineFraudulentCard, declineIncorrectCvc, declineExpired, # declineProcessingError, declineIncorrectNumber # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:43:in # `invalid_card' ``` ## Actual error ```console Faker::Stripe.valid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:6:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:36:in # `invalid_card' ``` This was found by running the test with faker-ruby#1698. ```console % bundle exec rake test Loaded suite /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.1/lib/rake/rake_test_loader Started (snip) /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:38: Passing `card_error` with the 1st argument of `Stripe.invalid_card` is deprecated. Use keyword argument like `Stripe.invalid_card(card_error: ...)` instead. /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:16: Passing `card_type` with the 1st argument of `Stripe.valid_card` is deprecated. Use keyword argument like `Stripe.valid_card(card_type: ...)` instead. ```
This PR fixes an argument for test_faker_stripe.rb. This change was hidden by the same `ArgumentError` in different messages. ## Expected error ```console Faker::Stripe.valid_card(card_type: Faker::Lorem.word) # => ArgumentError: Valid credit cards argument can be left blank or include # visa, visa_debit, mc, mc_2_series, mc_debit, mc_prepaid, amex, amex_2, # discover, discover_2, diners_club, diners_club_2, jcb # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:13:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(card_error: Faker::Lorem.word) # => ArgumentError: Invalid credit cards argument can be left blank or # include addressZipFail, addressFail, zipFail, addressZipUnavailable, # cvcFail, customerChargeFail, successWithReview, declineCard, # declineFraudulentCard, declineIncorrectCvc, declineExpired, # declineProcessingError, declineIncorrectNumber # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:43:in # `invalid_card' ``` ## Actual error ```console Faker::Stripe.valid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:6:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:36:in # `invalid_card' ``` This was found by running the test with faker-ruby#1698. ```console % bundle exec rake test Loaded suite /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.1/lib/rake/rake_test_loader Started (snip) /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:38: Passing `card_error` with the 1st argument of `Stripe.invalid_card` is deprecated. Use keyword argument like `Stripe.invalid_card(card_error: ...)` instead. /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:16: Passing `card_type` with the 1st argument of `Stripe.valid_card` is deprecated. Use keyword argument like `Stripe.valid_card(card_type: ...)` instead. ```
This PR fixes an argument for test_faker_stripe.rb. This change was hidden by the same `ArgumentError` in different messages. ## Expected error ```console Faker::Stripe.valid_card(card_type: Faker::Lorem.word) # => ArgumentError: Valid credit cards argument can be left blank or include # visa, visa_debit, mc, mc_2_series, mc_debit, mc_prepaid, amex, amex_2, # discover, discover_2, diners_club, diners_club_2, jcb # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:13:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(card_error: Faker::Lorem.word) # => ArgumentError: Invalid credit cards argument can be left blank or # include addressZipFail, addressFail, zipFail, addressZipUnavailable, # cvcFail, customerChargeFail, successWithReview, declineCard, # declineFraudulentCard, declineIncorrectCvc, declineExpired, # declineProcessingError, declineIncorrectNumber # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:43:in # `invalid_card' ``` ## Actual error ```console Faker::Stripe.valid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:6:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:36:in # `invalid_card' ``` This was found by running the test with #1698. ```console % bundle exec rake test Loaded suite /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.1/lib/rake/rake_test_loader Started (snip) /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:38: Passing `card_error` with the 1st argument of `Stripe.invalid_card` is deprecated. Use keyword argument like `Stripe.invalid_card(card_error: ...)` instead. /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:16: Passing `card_type` with the 1st argument of `Stripe.valid_card` is deprecated. Use keyword argument like `Stripe.valid_card(card_type: ...)` instead. ```
## Summary An `ArgumentError` occurred when upgrading to Faker 2.0. I didn't know what argument to change until I arrived at the changelog. https://github.com/faker-ruby/faker/blob/v2.1.2/CHANGELOG.md#important-note This PR will warn users what keyword arguments should be changed when positional arguments is used. This reduces users pain and makes upgrades easier. The following is an example. ```console % cat example.rb require 'faker' Faker::Address.zip_code('NY') ``` ### Before ```console % bundle exec ruby example.rb Traceback (most recent call last): 1: from example.rb:3:in `<main>' /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/address.rb:32:in `zip_code': wrong number of arguments (given 1, expected 0) (ArgumentError) ``` ### After ```console % bundle exec ruby example.rb example.rb:3: Passing `state_abbreviation` with the 1st argument of `Address.zip_code` is deprecated. Use keyword argument like `Address.zip_code(state_abbreviation: ...)` instead. ``` ## Other Information The `uplevel` keyword argument of `warn` method is a feature from Ruby 2.5. Faker supports Ruby 2.3 orh higehr, so it is emulated with `warn_with_uplevel` method.
eec6a11
to
b9494f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. We should've added these deprecation messages before. Thanks for working on this PR 👍
def quote(legacy_character = NOT_GIVEN, character: nil) | ||
if legacy_character != NOT_GIVEN | ||
warn_with_uplevel 'Passing `character` with the 1st argument of `Dune.quote` is deprecated. Use keyword argument like `Dune.quote(character: ...)` instead.', uplevel: 1 | ||
character = legacy_character |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also notify them that the legacy_character
and the other legacy parameters may be removed in Faker 3.0?
Passing `character` with the 1st argument of `Dune.quote` is deprecated and will be removed in Faker v3.0.0. Use keyword argument like `Dune.quote(character: ...)` instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to refrain from stating the removal because as the discussion in #1692 has not converged.
This PR is intended to ease the upgrade.
How about changing the message in the future based on the discussion in #1692? I think the focus will probably be on removing or leaving the first argument.
What do you think about this? Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Let's change the message in the next iteration @koic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably remove the first argument as they suggested in the issue. I've been using v2, and I believe it makes sense.
This PR fixes an argument for test_faker_stripe.rb. This change was hidden by the same `ArgumentError` in different messages. ## Expected error ```console Faker::Stripe.valid_card(card_type: Faker::Lorem.word) # => ArgumentError: Valid credit cards argument can be left blank or include # visa, visa_debit, mc, mc_2_series, mc_debit, mc_prepaid, amex, amex_2, # discover, discover_2, diners_club, diners_club_2, jcb # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:13:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(card_error: Faker::Lorem.word) # => ArgumentError: Invalid credit cards argument can be left blank or # include addressZipFail, addressFail, zipFail, addressZipUnavailable, # cvcFail, customerChargeFail, successWithReview, declineCard, # declineFraudulentCard, declineIncorrectCvc, declineExpired, # declineProcessingError, declineIncorrectNumber # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:43:in # `invalid_card' ``` ## Actual error ```console Faker::Stripe.valid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:6:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:36:in # `invalid_card' ``` This was found by running the test with faker-ruby#1698. ```console % bundle exec rake test Loaded suite /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.1/lib/rake/rake_test_loader Started (snip) /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:38: Passing `card_error` with the 1st argument of `Stripe.invalid_card` is deprecated. Use keyword argument like `Stripe.invalid_card(card_error: ...)` instead. /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:16: Passing `card_type` with the 1st argument of `Stripe.valid_card` is deprecated. Use keyword argument like `Stripe.valid_card(card_type: ...)` instead. ```
## Summary An `ArgumentError` occurred when upgrading to Faker 2.0. I didn't know what argument to change until I arrived at the changelog. https://github.com/faker-ruby/faker/blob/v2.1.2/CHANGELOG.md#important-note This PR will warn users what keyword arguments should be changed when positional arguments is used. This reduces users pain and makes upgrades easier. The following is an example. ```console % cat example.rb require 'faker' Faker::Address.zip_code('NY') ``` ### Before ```console % bundle exec ruby example.rb Traceback (most recent call last): 1: from example.rb:3:in `<main>' /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/address.rb:32:in `zip_code': wrong number of arguments (given 1, expected 0) (ArgumentError) ``` ### After ```console % bundle exec ruby example.rb example.rb:3: Passing `state_abbreviation` with the 1st argument of `Address.zip_code` is deprecated. Use keyword argument like `Address.zip_code(state_abbreviation: ...)` instead. ``` ## Other Information The `uplevel` keyword argument of `warn` method is a feature from Ruby 2.5. Faker supports Ruby 2.3 orh higehr, so it is emulated with `warn_with_uplevel` method.
This PR fixes an argument for test_faker_stripe.rb. This change was hidden by the same `ArgumentError` in different messages. ## Expected error ```console Faker::Stripe.valid_card(card_type: Faker::Lorem.word) # => ArgumentError: Valid credit cards argument can be left blank or include # visa, visa_debit, mc, mc_2_series, mc_debit, mc_prepaid, amex, amex_2, # discover, discover_2, diners_club, diners_club_2, jcb # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:13:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(card_error: Faker::Lorem.word) # => ArgumentError: Invalid credit cards argument can be left blank or # include addressZipFail, addressFail, zipFail, addressZipUnavailable, # cvcFail, customerChargeFail, successWithReview, declineCard, # declineFraudulentCard, declineIncorrectCvc, declineExpired, # declineProcessingError, declineIncorrectNumber # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:43:in # `invalid_card' ``` ## Actual error ```console Faker::Stripe.valid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:6:in # `valid_card' ``` ```console Faker::Stripe.invalid_card(Faker::Lorem.word) # => ArgumentError: wrong number of arguments (given 1, expected 0) # from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/stripe.rb:36:in # `invalid_card' ``` This was found by running the test with faker-ruby#1698. ```console % bundle exec rake test Loaded suite /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.1/lib/rake/rake_test_loader Started (snip) /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:38: Passing `card_error` with the 1st argument of `Stripe.invalid_card` is deprecated. Use keyword argument like `Stripe.invalid_card(card_error: ...)` instead. /Users/koic/src/github.com/faker-ruby/faker/test/faker/default/test_faker_stripe.rb:16: Passing `card_type` with the 1st argument of `Stripe.valid_card` is deprecated. Use keyword argument like `Stripe.valid_card(card_type: ...)` instead. ```
## Summary An `ArgumentError` occurred when upgrading to Faker 2.0. I didn't know what argument to change until I arrived at the changelog. https://github.com/faker-ruby/faker/blob/v2.1.2/CHANGELOG.md#important-note This PR will warn users what keyword arguments should be changed when positional arguments is used. This reduces users pain and makes upgrades easier. The following is an example. ```console % cat example.rb require 'faker' Faker::Address.zip_code('NY') ``` ### Before ```console % bundle exec ruby example.rb Traceback (most recent call last): 1: from example.rb:3:in `<main>' /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faker-2.1.2/lib/faker/default/address.rb:32:in `zip_code': wrong number of arguments (given 1, expected 0) (ArgumentError) ``` ### After ```console % bundle exec ruby example.rb example.rb:3: Passing `state_abbreviation` with the 1st argument of `Address.zip_code` is deprecated. Use keyword argument like `Address.zip_code(state_abbreviation: ...)` instead. ``` ## Other Information The `uplevel` keyword argument of `warn` method is a feature from Ruby 2.5. Faker supports Ruby 2.3 orh higehr, so it is emulated with `warn_with_uplevel` method.
Co-authored-by: mauromorales <[email protected]> Co-authored-by: chimpanstache <[email protected]>
Co-authored-by: mauromorales <[email protected]> Co-authored-by: chimpanstache <[email protected]>
Summary
An
ArgumentError
occurred when upgrading to Faker 2.0.I didn't know what argument to change until I arrived at the changelog.
https://github.com/faker-ruby/faker/blob/v2.1.2/CHANGELOG.md#important-note
This PR will warn users what keyword arguments should be changed when positional arguments is used.
This reduces users pain and makes upgrades easier.
The following is an example.
Before
After
Other Information
The
uplevel
keyword argument ofwarn
method is a feature from Ruby 2.5. Faker supports Ruby 2.3 orh higehr, so it is emulated withwarn_with_uplevel
method.