diff --git a/.gitignore b/.gitignore index d87d4be..9938105 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ spec/reports test/tmp test/version_tmp tmp +.idea +gemfiles/*.lock diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/.travis.yml b/.travis.yml index 65ea71b..2705718 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,15 @@ language: ruby -rvm: - - 2.1.0 +rvm: - 2.0.0 - - 1.9.3 \ No newline at end of file + - 2.1 + - ruby-head + - jruby-19mode # JRuby in 1.9 mode + - rbx-2 +gemfile: + - gemfiles/activemodel_4.0.gemfile + - gemfiles/activemodel_4.1.gemfile + - gemfiles/activemodel_4.2.gemfile +matrix: + allow_failures: + - rvm: ruby-head +bundler_args: --without local_development diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..289da58 --- /dev/null +++ b/Appraisals @@ -0,0 +1,11 @@ +appraise "activemodel-4.0" do + gem "activemodel", "~> 4.0.0" +end + +appraise "activemodel-4.1" do + gem "activemodel", "~> 4.1.0" +end + +appraise "activemodel-4.2" do + gem "activemodel", "~> 4.2.0.beta4" +end diff --git a/Gemfile b/Gemfile index d161c9d..f264083 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,20 @@ source 'https://rubygems.org' # Specify your gem's dependencies in bank.gemspec gemspec + + +group :test do + gem 'simplecov', '>= 0.9.0', :require => false + gem 'coveralls', :require => false +end + +group :local_development do + gem 'terminal-notifier-guard', require: false if RUBY_PLATFORM.downcase.include?('darwin') + gem 'guard-rspec', '>= 4.3.1' ,require: false + gem 'guard-bundler', require: false + gem 'guard-preek', require: false + gem 'guard-rubocop', require: false + gem 'guard-reek', github: 'pericles/guard-reek', require: false + gem 'pry' + gem 'appraisal' +end \ No newline at end of file diff --git a/Rakefile b/Rakefile index 35eb6c0..4c774a2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,6 @@ require 'bundler/gem_tasks' -require 'rake/testtask' +require 'rspec/core/rake_task' -Rake::TestTask.new do |t| - t.pattern = 'spec/**/*_spec.rb' - t.libs << 'spec' -end +RSpec::Core::RakeTask.new(:spec) -desc 'Run tests' -task :default => :test - -desc 'Run console' -task :console do - require 'irb' - require 'irb/completion' - require 'bank/contact' - ARGV.clear - IRB.start -end +task default: :spec diff --git a/bank.gemspec b/bank.gemspec index 7fb9ba6..ed33423 100644 --- a/bank.gemspec +++ b/bank.gemspec @@ -18,8 +18,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 1.5' + spec.add_development_dependency 'bundler' spec.add_development_dependency 'rake' - spec.add_development_dependency 'minitest', '~> 4.2' - spec.add_development_dependency 'activemodel', '~> 4.0.0' + spec.add_development_dependency 'activemodel', '>= 4', '< 5' end diff --git a/gemfiles/activemodel_4.0.gemfile b/gemfiles/activemodel_4.0.gemfile new file mode 100644 index 0000000..8c59b68 --- /dev/null +++ b/gemfiles/activemodel_4.0.gemfile @@ -0,0 +1,23 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activemodel", "~> 4.0.0" + +group :test do + gem "simplecov", ">= 0.9.0", :require => false + gem "coveralls", :require => false +end + +group :local_development do + gem "terminal-notifier-guard", :require => false + gem "guard-rspec", ">= 4.3.1", :require => false + gem "guard-bundler", :require => false + gem "guard-preek", :require => false + gem "guard-rubocop", :require => false + gem "guard-reek", :github => "pericles/guard-reek", :require => false + gem "pry" + gem "appraisal" +end + +gemspec :path => "../" diff --git a/gemfiles/activemodel_4.1.gemfile b/gemfiles/activemodel_4.1.gemfile new file mode 100644 index 0000000..fb5a45f --- /dev/null +++ b/gemfiles/activemodel_4.1.gemfile @@ -0,0 +1,23 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activemodel", "~> 4.1.0" + +group :test do + gem "simplecov", ">= 0.9.0", :require => false + gem "coveralls", :require => false +end + +group :local_development do + gem "terminal-notifier-guard", :require => false + gem "guard-rspec", ">= 4.3.1", :require => false + gem "guard-bundler", :require => false + gem "guard-preek", :require => false + gem "guard-rubocop", :require => false + gem "guard-reek", :github => "pericles/guard-reek", :require => false + gem "pry" + gem "appraisal" +end + +gemspec :path => "../" diff --git a/gemfiles/activemodel_4.2.gemfile b/gemfiles/activemodel_4.2.gemfile new file mode 100644 index 0000000..b6da054 --- /dev/null +++ b/gemfiles/activemodel_4.2.gemfile @@ -0,0 +1,23 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activemodel", "~> 4.2.0.beta4" + +group :test do + gem "simplecov", ">= 0.9.0", :require => false + gem "coveralls", :require => false +end + +group :local_development do + gem "terminal-notifier-guard", :require => false + gem "guard-rspec", ">= 4.3.1", :require => false + gem "guard-bundler", :require => false + gem "guard-preek", :require => false + gem "guard-rubocop", :require => false + gem "guard-reek", :github => "pericles/guard-reek", :require => false + gem "pry" + gem "appraisal" +end + +gemspec :path => "../" diff --git a/spec/activemodel_spec.rb b/spec/activemodel_spec.rb index b3aae4b..53e3631 100644 --- a/spec/activemodel_spec.rb +++ b/spec/activemodel_spec.rb @@ -22,30 +22,28 @@ def persisted? end end -describe IbanValidator do - before { - @model = Company.new - } +RSpec.describe IbanValidator do + let(:model) { ::Company.new } it 'should be valid' do - @model.iban = 'FR1420041010050500013M02606' - @model.valid?.must_equal true + model.iban = 'FR1420041010050500013M02606' + expect(model.valid?).to be_truthy end it 'should not be valid' do - @model.iban = 'FR1420041010050500013' - @model.valid?.must_equal false - @model.errors[:iban].must_include 'is invalid' + model.iban = 'FR1420041010050500013' + expect(model.valid?).to be_falsey + expect(model.errors[:iban]).to include 'is invalid' end it 'should not validate with nil value' do - @model.iban.must_equal nil - @model.valid?.must_equal false + expect(model.iban).to be_nil + expect(model.valid?).to be_falsey end it 'should not use the validator with option allow_nil: true' do - @person = Person.new - @person.iban.must_equal nil - @person.valid?.must_equal true + person = Person.new + expect(person.iban).to be_nil + expect(person.valid?).to be_truthy end end diff --git a/spec/bic_spec.rb b/spec/bic_spec.rb index f357c31..9ac74e6 100644 --- a/spec/bic_spec.rb +++ b/spec/bic_spec.rb @@ -1,52 +1,46 @@ require 'spec_helper' -describe Bank::BIC do - before do - @bic = Bank::BIC.new('ABNACHZ8XXX') - end +RSpec.describe Bank::BIC do + let(:bic) { ::Bank::BIC.new('ABNACHZ8XXX') } it 'returns the right bank code' do - @bic.bank_code.must_equal 'ABNA' + expect(bic.bank_code).to eq 'ABNA' end it 'returns the right country code' do - @bic.country_code.must_equal 'CH' + expect(bic.country_code).to eq 'CH' end it 'returns the right location code' do - @bic.location_code.must_equal 'Z8' + expect(bic.location_code).to eq 'Z8' end it 'returns the right branch code' do - @bic.branch_code.must_equal 'XXX' + expect(bic.branch_code).to eq 'XXX' end [8, 11].each do |len| - describe 'x' * len do + context 'x' * len do it 'has a valid length' do - Bank::BIC.new('x' * len).valid_length?.must_equal true + expect(::Bank::BIC.new('x' * len).valid_length?).to be_truthy end end end 1.upto(20) do |len| if len != 8 && len != 11 - describe 'x' * len do + context 'x' * len do it 'has a valid length' do - Bank::BIC.new('x' * len).valid_length?.must_equal false + expect(::Bank::BIC.new('x' * len).valid_length?).to be_falsey end end end end - [ - 'UCJAES2MXXX', - 'ABAGATWWXXX', - 'UCJAES2MXXX' - ].each do |code| - describe code do + %w(UCJAES2MXXX ABAGATWWXXX UCJAES2MXXX).each do |code| + context code do it 'has a valid format' do - Bank::BIC.new(code).valid_format?.must_equal true + expect(::Bank::BIC.new(code).valid_format?).to be_truthy end end end @@ -54,9 +48,9 @@ [ '12341234' ].each do |code| - describe code do + context code do it 'has an invalid format' do - Bank::BIC.new(code).valid_format?.must_equal false + expect(::Bank::BIC.new(code).valid_format?).to be_falsey end end end diff --git a/spec/contact_spec.rb b/spec/contact_spec.rb index 7837f23..8c1a293 100644 --- a/spec/contact_spec.rb +++ b/spec/contact_spec.rb @@ -2,29 +2,28 @@ require 'bank/contact' -describe Bank::Contact do - before do - @iban = Bank::IBAN.new('FR14 2004 1010 0505 0001 3M026 06') - @bic = Bank::BIC.new('BYLADEM1203') - @contact = Bank::Contact.new(@iban, @bic) - end +RSpec.describe Bank::Contact do + let(:iban) { Bank::IBAN.new('FR14 2004 1010 0505 0001 3M026 06') } + let(:bic) { Bank::BIC.new('BYLADEM1203') } + let(:contact) { Bank::Contact.new(iban, bic) } it 'should validate' do - @contact.valid?.must_equal true + expect(contact.valid?).to be_truthy end it 'should have the right types' do - @contact.iban.must_be_kind_of Bank::IBAN - @contact.bic.must_be_kind_of Bank::BIC + expect(contact.iban).to be_a Bank::IBAN + expect(contact.bic).to be_a Bank::BIC end it 'should export to_h' do - @contact.to_h.must_equal( - iban: 'FR1420041010050500013M02606', - bic: 'BYLADEM1203') + expect(contact.to_h).to eq({ + iban: 'FR1420041010050500013M02606', + bic: 'BYLADEM1203' + }) end it 'should export to_a' do - @contact.to_a.must_equal(['FR1420041010050500013M02606', 'BYLADEM1203']) + expect(contact.to_a).to eq(['FR1420041010050500013M02606', 'BYLADEM1203']) end end diff --git a/spec/iban_spec.rb b/spec/iban_spec.rb index 6b83736..17ac118 100644 --- a/spec/iban_spec.rb +++ b/spec/iban_spec.rb @@ -1,58 +1,56 @@ require 'spec_helper' -describe Bank::IBAN do - before do - @iban = Bank::IBAN.new('FR14 2004 1010 0505 0001 3M026 06') - end +RSpec.describe Bank::IBAN do + let(:iban) { Bank::IBAN.new('FR14 2004 1010 0505 0001 3M026 06') } it 'should valid from class method' do - Bank::IBAN.valid?('FR14 2004 1010 0505 0001 3M026 06').must_equal true + expect(Bank::IBAN.valid?('FR14 2004 1010 0505 0001 3M026 06')).to be_truthy end it 'should load the validation rules' do - Bank.load_specifications(:iban).wont_be :empty? - Bank.load_specifications(:iban).must_be_kind_of Hash + expect(Bank.load_specifications(:iban)).to_not be_empty + expect(Bank.load_specifications(:iban)).to be_a Hash end it 'should return the county code' do - @iban.country_code.must_equal 'FR' + expect(iban.country_code).to eq 'FR' end it 'should return the check digits' do - @iban.check_digits.must_equal '14' + expect(iban.check_digits).to eq '14' end it 'should return the BBAN' do - @iban.bban.must_be_kind_of Bank::BBAN - @iban.bban.to_s.must_equal '20041010050500013M02606' + expect(iban.bban).to be_a Bank::BBAN + expect(iban.bban.to_s).to eq '20041010050500013M02606' end it 'should convert to integer value' do - @iban.to_i.must_equal 200410100505000132202606152714 + expect(iban.to_i).to eq 200410100505000132202606152714 end it 'should convert to string' do - @iban.to_s.must_equal 'FR1420041010050500013M02606' + expect(iban.to_s).to eq 'FR1420041010050500013M02606' end it 'should convert to formatted string' do - @iban.to_s(true).must_equal 'FR14 2004 1010 0505 0001 3M02 606' + expect(iban.to_s(true)).to eq 'FR14 2004 1010 0505 0001 3M02 606' end it 'should respond_to? account_number' do - @iban.respond_to?(:account_number).must_equal true + expect(iban.respond_to?(:account_number)).to be_truthy end it 'should return account_number' do - @iban.account_number.must_equal '0500013M026' + expect(iban.account_number).to eq '0500013M026' end it 'should return bank_identifier' do - @iban.bank_identifier.must_equal '20041' + expect(iban.bank_identifier).to eq '20041' end it 'should return branch_identifier' do - @iban.branch_identifier.must_equal '01005' + expect(iban.branch_identifier).to eq '01005' end [ @@ -140,9 +138,9 @@ 'TR330006100519786457841326', 'AE260211000000230064016' ].each do |code| - describe code do + context code do it 'should be valid' do - Bank::IBAN.new(code).valid?.must_equal true + expect(Bank::IBAN.new(code).valid?).to be_truthy end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ae892d9..0b8c6e1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,14 @@ -# -*- encoding: utf-8 -*- -require 'rubygems' -require 'bundler/setup' - -require 'minitest/autorun' -require 'minitest/spec' -begin; require 'turn/autorun'; rescue LoadError; end +require 'simplecov' +require 'coveralls' +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter +] +SimpleCov.start do + add_filter 'spec' + minimum_coverage(76) +end require 'active_model' require 'bank/iban' -require 'bank/bic' +require 'bank/bic' \ No newline at end of file