Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.gem
*.gem
.idea
5 changes: 5 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--color
--require spec_helper
--format documentation


4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in ibantools.gemspec
gemspec
43 changes: 43 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
PATH
remote: .
specs:
iban-tools (0.0.7)

GEM
remote: https://rubygems.org/
specs:
coderay (1.1.0)
diff-lcs (1.2.5)
method_source (0.8.2)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rake (10.5.0)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.3)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
slop (3.6.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.10)
iban-tools!
pry
rake (~> 10.0)
rspec

BUNDLED WITH
1.10.6
13 changes: 4 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# vim:ts=2:sw=2:et:
require "bundler/gem_tasks"
require "rspec/core/rake_task"

require 'rubygems'
gem 'rspec', '>= 1.2.4'
require 'spec/rake/spectask'

Spec::Rake::SpecTask.new do |t|
t.libs << 'lib'
t.spec_opts = ["--color" ]
end
RSpec::Core::RakeTask.new(:spec)

task :default => :spec
15 changes: 7 additions & 8 deletions iban-tools.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ Gem::Specification.new do |s|
s.authors = ["Iulian Dogariu"]
s.email = ["[email protected]"]
s.requirements << 'none'
s.require_path = 'lib'
s.files = [
"README.md",
"lib/iban-tools.rb",
"lib/iban-tools/iban.rb",
"lib/iban-tools/iban_rules.rb",
"lib/iban-tools/rules.yml"
]
s.description = "Validates IBAN account numbers"
s.require_path = 'lib'

s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
s.add_development_dependency "bundler", "~> 1.10"
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "rspec"
s.add_development_dependency "pry"
end
5 changes: 5 additions & 0 deletions lib/iban-tools/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
length: 22
bban_pattern: '[A-Z]{4}[A-Z0-9]{14}'

'BR':
# Brazil
length: 29
bban_pattern: '[0-9]{23}[0-9A-Z]{2}'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BR has since then already been added, so this may not be needed anymore.


'CH':
# Switzerland
length: 21
Expand Down
15 changes: 7 additions & 8 deletions spec/iban-tools/iban_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# vim:ts=2:sw=2:et:

require 'iban-tools'

module IBANTools
describe IBAN do

Expand All @@ -13,7 +11,7 @@ module IBANTools

it "should validate IBAN code" do
# Using example from http://en.wikipedia.org/wiki/IBAN#Calculating_and_validating_IBAN_checksums
IBAN.valid?( "GB82WEST12345698765432", @rules ).should be_true
IBAN.valid?( "GB82WEST12345698765432", @rules ).should be true
end

it "should reject IBAN code with invalid characters" do
Expand Down Expand Up @@ -42,7 +40,7 @@ module IBANTools
end

it "should reject IBAN code with invalid check digits" do
IBAN.valid?( "GB99 WEST 1234 5698 7654 32", @rules ).should be_false
IBAN.valid?( "GB99 WEST 1234 5698 7654 32", @rules ).should be false

IBAN.new("GB99 WEST 1234 5698 7654 32").validation_errors(@rules).
should == [:bad_check_digits]
Expand Down Expand Up @@ -80,7 +78,7 @@ module IBANTools
IBAN.new("NO9386011117947").bban.should == "86011117947"
end

describe "with default rules" do
describe "with default rules" do

# Rules are loaded from lib/iban-tools/rules.yml
# Samples from http://www.tbg5-finance.org/?ibandocs.shtml/
Expand Down Expand Up @@ -140,10 +138,11 @@ module IBANTools
"SK3112000000198742637541",
"SM86U0322509800000000270100",
"TN5914207207100707129648",
"TR330006100519786457841326"
"TR330006100519786457841326",
"BR8700000000028110000219371C1"
].each do |iban_code|
describe iban_code do
it "should be valid" do
it "should be valid" do
IBAN.new(iban_code).validation_errors.should == []
end
end
Expand All @@ -152,7 +151,7 @@ module IBANTools
it "should fail known pattern violations" do
# This IBAN has valid check digits
# but should fail because of pattern violation
IBAN.valid?("RO7999991B31007593840000").should be_false
IBAN.valid?("RO7999991B31007593840000").should be false
end

end
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'pry'
require 'iban-tools'

RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :should }

config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end