Skip to content

Commit

Permalink
Add meaningful error message when country code not found (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstebo authored and stympy committed May 23, 2017
1 parent f69e09c commit f5617db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
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

0 comments on commit f5617db

Please sign in to comment.