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 meaningful error message when country code not found #916

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/faker/bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def swift_bic

def iban(bank_country_code="GB")
details = iban_details.find { |country| country["bank_country_code"] == bank_country_code.upcase }
raise ArgumentError, "Could not find iban details for #{bank_country_code}" unless details
bcc = details["bank_country_code"] + 2.times.map{ rand(10) }.join
ilc = (0...details["iban_letter_code"].to_i).map{ (65 + rand(26)).chr }.join
ib = details["iban_digits"].to_i.times.map{ rand(10) }.join
Expand Down
13 changes: 6 additions & 7 deletions test/test_faker_bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ def test_iban_ro; assert @tester.iban("ro").match(/[A-Z]{4}[A-Z0-9]{16}/); end
def test_iban_es; assert @tester.iban("es").match(/\d{20}/); end
def test_iban_se; assert @tester.iban("se").match(/\d{20}/); end
def test_iban_sk; assert @tester.iban("sk").match(/\d{24}/); end
end







def test_iban_invalid
assert_raise ArgumentError.new("Could not find iban details for bad") do
@tester.iban("bad")
end
end
end