ibandit 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ibandit::GermanDetailsConverter do
4
+ shared_examples 'json based fixture' do |json_fixture_file|
5
+ json_fixture(json_fixture_file).each do |convertor|
6
+ context "Rule #{convertor['convertor']}" do
7
+ let(:klass) do
8
+ described_class.const_get("Rule#{convertor['convertor']}")
9
+ end
10
+
11
+ subject { test_subject }
12
+
13
+ before do
14
+ expect_any_instance_of(klass).to receive(:converted_details).
15
+ and_call_original
16
+ end
17
+
18
+ convertor.fetch('valid', []).each do |tuple|
19
+ context "bank code: #{tuple['bank_code']} account number " \
20
+ "#{tuple['account_number']}" do
21
+ let(:bank_code) do
22
+ tuple['bank_code']
23
+ end
24
+ let(:account_number) do
25
+ tuple['account_number']
26
+ end
27
+ let(:converted_bank_code) do
28
+ tuple['converted_bank_code'] || bank_code
29
+ end
30
+ let(:converted_account_number) do
31
+ tuple['converted_account_number'] || account_number
32
+ end
33
+ it do
34
+ is_expected.to eq(
35
+ bank_code: converted_bank_code,
36
+ account_number: converted_account_number)
37
+ end
38
+ end
39
+ end
40
+
41
+ convertor.fetch('invalid', []).each do |tuple|
42
+ context "bank code: #{tuple['bank_code']} account number " \
43
+ "#{tuple['account_number']}" do
44
+ let(:bank_code) { tuple['bank_code'] || '00000000' }
45
+ let(:account_number) { tuple['account_number'] }
46
+ it 'raises UnsupportedAccountDetails' do
47
+ expect { subject }.
48
+ to raise_error(Ibandit::UnsupportedAccountDetails)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ describe 'integration tests' do
57
+ include_examples 'json based fixture', 'germany_integration_test_cases' do
58
+ let(:test_subject) do
59
+ described_class.
60
+ convert(bank_code: bank_code, account_number: account_number)
61
+ end
62
+ end
63
+ end
64
+
65
+ describe 'unit tests' do
66
+ include_examples 'json based fixture', 'germany_unit_test_cases' do
67
+ let(:test_subject) do
68
+ klass.new(bank_code, account_number).converted_details
69
+ end
70
+ end
71
+ end
72
+
73
+ describe Ibandit::GermanDetailsConverter::Rule002002::Check63 do
74
+ subject { described_class.new(account_number) }
75
+
76
+ # Test cases taken from the IBAN Rules definitions document
77
+ valid_account_numbers = %w(
78
+ 38150900 600103660 39101181 5600200 75269100 3700246 6723143
79
+ 5719083 571908300 8007759 800775900 350002200 900004300
80
+ )
81
+
82
+ invalid_account_numbers = %w(
83
+ 370024600 672314300 3500022 9000043 123456700 94012341 94012341
84
+ 5073321010 1234517892 987614325
85
+ )
86
+
87
+ valid_account_numbers.each do |number|
88
+ context "#{number}" do
89
+ let(:account_number) { number }
90
+ it { is_expected.to be_valid }
91
+ end
92
+ end
93
+
94
+ invalid_account_numbers.each do |number|
95
+ context "#{number}" do
96
+ let(:account_number) { number }
97
+ it { is_expected.to_not be_valid }
98
+ end
99
+ end
100
+ end
101
+ end
@@ -167,6 +167,13 @@ describe Ibandit::IBANBuilder do
167
167
  to raise_error(ArgumentError, /account_number is a required field/)
168
168
  end
169
169
  end
170
+
171
+ context 'with a pseudo account number' do
172
+ before { args[:bank_code] = '37080040' }
173
+ before { args[:account_number] = '111' }
174
+
175
+ its(:iban) { is_expected.to eq('DE69370800400215022000') }
176
+ end
170
177
  end
171
178
 
172
179
  context 'with EE as the country_code' do
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require 'ibandit'
2
2
  require 'rspec/its'
3
+ require 'json'
3
4
 
4
5
  RSpec.configure do |config|
5
6
  config.mock_with(:rspec) { |mocks| mocks.verify_partial_doubles = true }
6
7
  config.raise_errors_for_deprecations!
7
8
  end
9
+
10
+ def json_fixture(filename)
11
+ JSON.parse(File.read("spec/fixtures/#{filename}.json"))
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibandit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Baker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -98,19 +98,26 @@ files:
98
98
  - LICENSE
99
99
  - README.md
100
100
  - TODO.md
101
+ - bin/build_german_iban_rules.rb
101
102
  - bin/build_structure_file.rb
102
- - data/IBANSTRUCTURE.xml
103
- - data/IBAN_Registry.txt
104
- - data/structure_additions.yml
103
+ - data/german_iban_rules.yml
104
+ - data/raw/BLZ2.txt
105
+ - data/raw/IBANSTRUCTURE.xml
106
+ - data/raw/IBAN_Registry.txt
107
+ - data/raw/structure_additions.yml
108
+ - data/structures.yml
105
109
  - ibandit.gemspec
106
110
  - lib/ibandit.rb
107
111
  - lib/ibandit/check_digit.rb
108
112
  - lib/ibandit/errors.rb
113
+ - lib/ibandit/german_details_converter.rb
109
114
  - lib/ibandit/iban.rb
110
115
  - lib/ibandit/iban_builder.rb
111
- - lib/ibandit/structures.yml
112
116
  - lib/ibandit/version.rb
117
+ - spec/fixtures/germany_integration_test_cases.json
118
+ - spec/fixtures/germany_unit_test_cases.json
113
119
  - spec/ibandit/check_digit_spec.rb
120
+ - spec/ibandit/german_details_converter_spec.rb
114
121
  - spec/ibandit/iban_builder_spec.rb
115
122
  - spec/ibandit/iban_spec.rb
116
123
  - spec/spec_helper.rb