diff --git a/.gitignore b/.gitignore index 86339a0..0f5f57c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.gem \ No newline at end of file +*.gem +.idea \ No newline at end of file diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..77d6822 --- /dev/null +++ b/.rspec @@ -0,0 +1,5 @@ +--color +--require spec_helper +--format documentation + + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a597b11 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in ibantools.gemspec +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..844bef5 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/Rakefile b/Rakefile index ea75822..b7e9ed5 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/iban-tools.gemspec b/iban-tools.gemspec index 1585f80..416b923 100644 --- a/iban-tools.gemspec +++ b/iban-tools.gemspec @@ -6,13 +6,12 @@ Gem::Specification.new do |s| s.authors = ["Iulian Dogariu"] s.email = ["code@iuliandogariu.com"] 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 diff --git a/lib/iban-tools/rules.yml b/lib/iban-tools/rules.yml index 8d4152b..9ca1b00 100644 --- a/lib/iban-tools/rules.yml +++ b/lib/iban-tools/rules.yml @@ -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}' + 'CH': # Switzerland length: 21 diff --git a/spec/iban-tools/iban_spec.rb b/spec/iban-tools/iban_spec.rb index c796837..d2698c2 100644 --- a/spec/iban-tools/iban_spec.rb +++ b/spec/iban-tools/iban_spec.rb @@ -1,7 +1,5 @@ # vim:ts=2:sw=2:et: -require 'iban-tools' - module IBANTools describe IBAN do @@ -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 @@ -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] @@ -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/ @@ -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 @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..9563c81 --- /dev/null +++ b/spec/spec_helper.rb @@ -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