Skip to content

Commit

Permalink
adding tests for Bank::BIC and making valid_format? return a boolean …
Browse files Browse the repository at this point in the history
…instead of an integer|nil
  • Loading branch information
Daniel Mueller committed Apr 16, 2014
1 parent 9f3d0db commit 65de3a8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bank/bic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def valid_length?
end

def valid_format?
@code =~ /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/
!!(@code =~ /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/)
end

def valid_location_code?
Expand Down
64 changes: 64 additions & 0 deletions spec/bic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'spec_helper'


describe Bank::BIC do
before do
@bic = Bank::BIC.new('ABNACHZ8XXX')
end

it 'returns the right bank code' do
@bic.bank_code.must_equal 'ABNA'
end

it 'returns the right country code' do
@bic.country_code.must_equal 'CH'
end

it 'returns the right location code' do
@bic.location_code.must_equal 'Z8'
end

it 'returns the right branch code' do
@bic.branch_code.must_equal 'XXX'
end

[ 8, 11 ].each do |len|
describe 'x'*len do
it "has a valid length" do
Bank::BIC.new('x'*len).valid_length?.must_equal true
end
end
end

1.upto(20) do |len|
if len != 8 && len != 11
describe 'x'*len do
it "has a valid length" do
Bank::BIC.new('x'*len).valid_length?.must_equal false
end
end
end
end

[ 'UCJAES2MXXX',
'ABAGATWWXXX',
'UCJAES2MXXX'
].each do |code|
describe code do
it "has a valid format" do
Bank::BIC.new(code).valid_format?.must_equal true
end
end
end

[
'12341234'
].each do |code|
describe code do
it "has an invalid format" do
Bank::BIC.new(code).valid_format?.must_equal false
end
end
end

end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

require 'active_model'
require 'bank/iban'
require 'bank/bic'

0 comments on commit 65de3a8

Please sign in to comment.