Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to rspec3. Not strict depends on activemodel. Multiple activemod... #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ spec/reports
test/tmp
test/version_tmp
tmp
.idea
gemfiles/*.lock
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
language: ruby
rvm:
- 2.1.0
rvm:
- 2.0.0
- 1.9.3
- 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
11 changes: 11 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 3 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions bank.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions gemfiles/activemodel_4.0.gemfile
Original file line number Diff line number Diff line change
@@ -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 => "../"
23 changes: 23 additions & 0 deletions gemfiles/activemodel_4.1.gemfile
Original file line number Diff line number Diff line change
@@ -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 => "../"
23 changes: 23 additions & 0 deletions gemfiles/activemodel_4.2.gemfile
Original file line number Diff line number Diff line change
@@ -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 => "../"
26 changes: 12 additions & 14 deletions spec/activemodel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect(model.valid?).to be_falsey
expect(model.errors[:iban]).to include 'is invalid'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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
36 changes: 15 additions & 21 deletions spec/bic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,56 @@
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') }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


it 'returns the right bank code' do
@bic.bank_code.must_equal 'ABNA'
expect(bic.bank_code).to eq 'ABNA'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'returns the right country code' do
@bic.country_code.must_equal 'CH'
expect(bic.country_code).to eq 'CH'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'returns the right location code' do
@bic.location_code.must_equal 'Z8'
expect(bic.location_code).to eq 'Z8'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'returns the right branch code' do
@bic.branch_code.must_equal 'XXX'
expect(bic.branch_code).to eq 'XXX'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

[8, 11].each do |len|
describe 'x' * len do
context 'x' * len do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
end
end

1.upto(20) do |len|
if len != 8 && len != 11
describe 'x' * len do
context 'x' * len do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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

[
'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
Expand Down
25 changes: 12 additions & 13 deletions spec/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

let(:bic) { Bank::BIC.new('BYLADEM1203') }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

iban: 'FR1420041010050500013M02606',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

bic: 'BYLADEM1203'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

})
end

it 'should export to_a' do
@contact.to_a.must_equal(['FR1420041010050500013M02606', 'BYLADEM1203'])
expect(contact.to_a).to eq(['FR1420041010050500013M02606', 'BYLADEM1203'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
end
Loading