EGP_Rates 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/egp_rates.rb +9 -0
- data/lib/egp_rates/aaib.rb +5 -6
- data/lib/egp_rates/al_ahli_bank_of_kuwait.rb +61 -0
- data/lib/egp_rates/al_baraka_bank.rb +84 -0
- data/lib/egp_rates/bank.rb +36 -0
- data/lib/egp_rates/banque_du_caire.rb +66 -0
- data/lib/egp_rates/banque_misr.rb +69 -0
- data/lib/egp_rates/cae.rb +62 -0
- data/lib/egp_rates/cbe.rb +1 -20
- data/lib/egp_rates/cib.rb +2 -1
- data/lib/egp_rates/midb.rb +60 -0
- data/lib/egp_rates/nbe.rb +1 -2
- data/lib/egp_rates/saib.rb +62 -0
- data/lib/egp_rates/suez_canal_bank.rb +80 -0
- data/lib/egp_rates/ube.rb +59 -0
- data/spec/cassettes/AlAhliBankOfKuwait.yml +1379 -0
- data/spec/cassettes/AlBarakaBank.yml +308 -0
- data/spec/cassettes/BanqueDuCaire.yml +1475 -0
- data/spec/cassettes/BanqueMisr.yml +1327 -0
- data/spec/cassettes/CAE.yml +6098 -0
- data/spec/cassettes/MIDB.yml +507 -0
- data/spec/cassettes/SAIB.yml +567 -0
- data/spec/cassettes/SuezCanalBank.yml +1399 -0
- data/spec/cassettes/UBE.yml +69 -0
- data/spec/egp_rates/aaib_spec.rb +4 -4
- data/spec/egp_rates/al_ahli_bank_of_kuwait_spec.rb +76 -0
- data/spec/egp_rates/al_baraka_bank_spec.rb +89 -0
- data/spec/egp_rates/banque_du_caire_spec.rb +111 -0
- data/spec/egp_rates/banque_misr_spec.rb +119 -0
- data/spec/egp_rates/cae_spec.rb +93 -0
- data/spec/egp_rates/cbe_spec.rb +4 -4
- data/spec/egp_rates/cib_spec.rb +3 -3
- data/spec/egp_rates/midb_spec.rb +73 -0
- data/spec/egp_rates/nbe_spec.rb +3 -3
- data/spec/egp_rates/saib_spec.rb +77 -0
- data/spec/egp_rates/suez_canal_bank_spec.rb +102 -0
- data/spec/egp_rates/ube_spec.rb +71 -0
- data/spec/egp_rates_spec.rb +2 -0
- metadata +30 -3
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::CAE do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 17
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 17
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :CAE
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates' do
|
19
|
+
it 'calls #parse with #raw_exchange_rates' do
|
20
|
+
expect(bank).to receive(:raw_exchange_rates)
|
21
|
+
expect(bank).to receive(:parse)
|
22
|
+
bank.exchange_rates
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#raw_exchange_rates' do
|
27
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
28
|
+
stub_request(:get, /.*ca-egypt.*/).to_return(body: '', status: 500)
|
29
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
30
|
+
EGPRates::ResponseError, '500'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
34
|
+
stub_request(:get, /.*ca-egypt.*/).to_return(body: '', status: 200)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns <#Enumerator::Lazy> of 17 rows', vcr: { cassette_name: :CAE } do
|
40
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
41
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
42
|
+
expect(lazy_enumerator.size).to eq 17
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#parse', vcr: { cassette_name: :CAE } do
|
47
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
48
|
+
|
49
|
+
it 'returns sell: hash of selling prices' do
|
50
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
51
|
+
AED: 4.8869,
|
52
|
+
AUD: 13.3153,
|
53
|
+
BHD: 47.6102,
|
54
|
+
CAD: 13.3032,
|
55
|
+
CHF: 17.8412,
|
56
|
+
DKK: 2.5677,
|
57
|
+
EUR: 19.1024,
|
58
|
+
GBP: 22.3226,
|
59
|
+
JOD: 25.2817,
|
60
|
+
JPY: 0.1635,
|
61
|
+
KWD: 58.8718,
|
62
|
+
NOK: 2.102,
|
63
|
+
OMR: 46.6222,
|
64
|
+
QAR: 4.9294,
|
65
|
+
SAR: 4.7864,
|
66
|
+
SEK: 1.9455,
|
67
|
+
USD: 17.95
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns buy: hash of buying prices' do
|
72
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
73
|
+
AED: 4.6962,
|
74
|
+
AUD: 12.646,
|
75
|
+
BHD: 45.7317,
|
76
|
+
CAD: 12.7175,
|
77
|
+
CHF: 17.0387,
|
78
|
+
DKK: 2.4507,
|
79
|
+
EUR: 18.2333,
|
80
|
+
GBP: 21.2227,
|
81
|
+
JOD: 24.2958,
|
82
|
+
JPY: 0.1555,
|
83
|
+
KWD: 56.5759,
|
84
|
+
NOK: 2.0022,
|
85
|
+
OMR: 44.8017,
|
86
|
+
QAR: 4.7367,
|
87
|
+
SAR: 4.5989,
|
88
|
+
SEK: 1.8584,
|
89
|
+
USD: 17.25
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/spec/egp_rates/cbe_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe EGPRates::CBE do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe '#exchange_rates'
|
18
|
+
describe '#exchange_rates' do
|
19
19
|
it 'calls #parse with #raw_exchange_rates' do
|
20
20
|
expect(bank).to receive(:raw_exchange_rates)
|
21
21
|
expect(bank).to receive(:parse)
|
@@ -44,7 +44,7 @@ describe EGPRates::CBE do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
describe '#currency_symbol' do
|
47
|
-
%
|
47
|
+
%W(#{'US Dollar'} Euro Sterling Swiss Japanese Saudi Kuwait UAE Chinese)\
|
48
48
|
.each do |currency|
|
49
49
|
it "returns currency :SYM for #{currency}" do
|
50
50
|
symbols = %i(USD EUR GBP CHF JPY SAR KWD AED CNY)
|
@@ -62,7 +62,7 @@ describe EGPRates::CBE do
|
|
62
62
|
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
63
63
|
|
64
64
|
it 'returns sell: hash of selling prices' do
|
65
|
-
expect(bank.send(:parse, raw_data)[:sell]).to
|
65
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
66
66
|
AED: 4.6524,
|
67
67
|
CHF: 17.3096,
|
68
68
|
CNY: 2.5138,
|
@@ -76,7 +76,7 @@ describe EGPRates::CBE do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'returns buy: hash of buying prices' do
|
79
|
-
expect(bank.send(:parse, raw_data)[:buy]).to
|
79
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
80
80
|
AED: 4.4518,
|
81
81
|
CHF: 16.551,
|
82
82
|
CNY: 2.4052,
|
data/spec/egp_rates/cib_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe EGPRates::CIB do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe '#exchange_rates'
|
18
|
+
describe '#exchange_rates' do
|
19
19
|
it 'calls #parse with #raw_exchange_rates' do
|
20
20
|
expect(bank).to receive(:raw_exchange_rates)
|
21
21
|
expect(bank).to receive(:parse)
|
@@ -68,7 +68,7 @@ describe EGPRates::CIB do
|
|
68
68
|
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
69
69
|
|
70
70
|
it 'returns sell: hash of selling prices' do
|
71
|
-
expect(bank.send(:parse, raw_data)[:sell]).to
|
71
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
72
72
|
CHF: 16.3176,
|
73
73
|
EUR: 17.5234,
|
74
74
|
GBP: 20.292,
|
@@ -79,7 +79,7 @@ describe EGPRates::CIB do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'returns buy: hash of buying prices' do
|
82
|
-
expect(bank.send(:parse, raw_data)[:buy]).to
|
82
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
83
83
|
CHF: 16.0433,
|
84
84
|
EUR: 17.1904,
|
85
85
|
GBP: 19.9359,
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::MIDB do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 7
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 7
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :MIDB
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates' do
|
19
|
+
it 'calls #parse with #raw_exchange_rates' do
|
20
|
+
expect(bank).to receive(:raw_exchange_rates)
|
21
|
+
expect(bank).to receive(:parse)
|
22
|
+
bank.exchange_rates
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#raw_exchange_rates' do
|
27
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
28
|
+
stub_request(:get, /.*midb.*/).to_return(body: '', status: 500)
|
29
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
30
|
+
EGPRates::ResponseError, '500'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
34
|
+
stub_request(:get, /.*midb.*/).to_return(body: '', status: 200)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns <#Enumerator::Lazy> of 7 rows', vcr: { cassette_name: :MIDB } do
|
40
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
41
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
42
|
+
expect(lazy_enumerator.size).to eq 7
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#parse', vcr: { cassette_name: :MIDB } do
|
47
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
48
|
+
|
49
|
+
it 'returns sell: hash of selling prices' do
|
50
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
51
|
+
AED: 4.7835,
|
52
|
+
CHF: 17.4063,
|
53
|
+
EUR: 18.5978,
|
54
|
+
GBP: 21.6866,
|
55
|
+
JPY: 15.8416,
|
56
|
+
SAR: 4.6847,
|
57
|
+
USD: 17.5
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns buy: hash of buying prices' do
|
62
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
63
|
+
AED: 4.5491,
|
64
|
+
CHF: 16.8574,
|
65
|
+
EUR: 18.0113,
|
66
|
+
GBP: 21.0027,
|
67
|
+
JPY: 15.342,
|
68
|
+
SAR: 4.4551,
|
69
|
+
USD: 17.05
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/egp_rates/nbe_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe EGPRates::NBE do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe '#exchange_rates'
|
18
|
+
describe '#exchange_rates' do
|
19
19
|
it 'calls #parse with #raw_exchange_rates' do
|
20
20
|
expect(bank).to receive(:raw_exchange_rates)
|
21
21
|
expect(bank).to receive(:parse)
|
@@ -47,7 +47,7 @@ describe EGPRates::NBE do
|
|
47
47
|
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
48
48
|
|
49
49
|
it 'returns sell: hash of selling prices' do
|
50
|
-
expect(bank.send(:parse, raw_data)[:sell]).to
|
50
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
51
51
|
AED: 4.3697,
|
52
52
|
AUD: 12.2445,
|
53
53
|
BAD: 42.5854,
|
@@ -69,7 +69,7 @@ describe EGPRates::NBE do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'returns buy: hash of buying prices' do
|
72
|
-
expect(bank.send(:parse, raw_data)[:buy]).to
|
72
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
73
73
|
AED: 4.3288,
|
74
74
|
AUD: 11.9663,
|
75
75
|
BAD: 42.1538,
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::SAIB do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 6
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 6
|
9
|
+
expect(bank.exchange_rates[:buy].keys).to include(
|
10
|
+
:CHF, :EUR, :GBP, :KWD, :SAR, :USD
|
11
|
+
)
|
12
|
+
expect(bank.exchange_rates[:sell].keys).to include(
|
13
|
+
:CHF, :EUR, :GBP, :KWD, :SAR, :USD
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.new' do
|
18
|
+
it 'initialize instance variables' do
|
19
|
+
expect(bank.sym).to eq :SAIB
|
20
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#exchange_rates' do
|
25
|
+
it 'calls #parse with #raw_exchange_rates' do
|
26
|
+
expect(bank).to receive(:raw_exchange_rates)
|
27
|
+
expect(bank).to receive(:parse)
|
28
|
+
bank.exchange_rates
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#raw_exchange_rates' do
|
33
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
34
|
+
stub_request(:get, /.*saib.*/).to_return(body: '', status: 500)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, '500'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
40
|
+
stub_request(:get, /.*saib.*/).to_return(body: '', status: 200)
|
41
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
42
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns <#Enumerator::Lazy> of 6 rows', vcr: { cassette_name: :SAIB } do
|
46
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
47
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
48
|
+
expect(lazy_enumerator.size).to eq 6
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#parse', vcr: { cassette_name: :SAIB } do
|
53
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
54
|
+
|
55
|
+
it 'returns sell: hash of selling prices' do
|
56
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
57
|
+
CHF: 16.51,
|
58
|
+
EUR: 17.73,
|
59
|
+
GBP: 20.67,
|
60
|
+
KWD: 54.26,
|
61
|
+
SAR: 4.46,
|
62
|
+
USD: 16.75
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns buy: hash of buying prices' do
|
67
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
68
|
+
CHF: 15.74,
|
69
|
+
EUR: 16.98,
|
70
|
+
GBP: 19.8,
|
71
|
+
KWD: 51.9,
|
72
|
+
SAR: 4.27,
|
73
|
+
USD: 16.05
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::SuezCanalBank do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 13
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 13
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :SuezCanalBank
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates' do
|
19
|
+
it 'calls #parse with #raw_exchange_rates' do
|
20
|
+
expect(bank).to receive(:raw_exchange_rates)
|
21
|
+
expect(bank).to receive(:parse)
|
22
|
+
bank.exchange_rates
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#raw_exchange_rates' do
|
27
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
28
|
+
stub_request(:get, /.*scbank.*/).to_return(body: '', status: 500)
|
29
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
30
|
+
EGPRates::ResponseError, '500'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
34
|
+
stub_request(:get, /.*scbank.*/).to_return(body: '', status: 200)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns <#Enumerator::Lazy> of 13 rows',
|
40
|
+
vcr: { cassette_name: :SuezCanalBank } do
|
41
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
42
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
43
|
+
expect(lazy_enumerator.size).to eq 13
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#currency_symbol' do
|
48
|
+
%W(#{'UAE Dirham'} Australian Canadian Swedish Danish EUR YEN Swiss
|
49
|
+
Sterling Kuwaiti Norwegian Saudi #{'US Dollar'})
|
50
|
+
.each do |currency|
|
51
|
+
it "returns currency :SYM for #{currency}" do
|
52
|
+
symbols = %i(USD AUD GBP CAD DKK AED EUR CHF SEK JPY NOK SAR KWD)
|
53
|
+
expect(symbols).to include(bank.send(:currency_symbol, currency))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'raises ResponseError when Unknown Currency' do
|
58
|
+
expect { bank.send(:currency_symbol, 'Egyptian Pound') }.to raise_error\
|
59
|
+
EGPRates::ResponseError, 'Unknown currency Egyptian Pound'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#parse', vcr: { cassette_name: :SuezCanalBank } do
|
64
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
65
|
+
|
66
|
+
it 'returns sell: hash of selling prices' do
|
67
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
68
|
+
AED: 0.0,
|
69
|
+
AUD: 0.0,
|
70
|
+
CAD: 0.0,
|
71
|
+
CHF: 16.1144,
|
72
|
+
DKK: 0.0,
|
73
|
+
EUR: 17.3056,
|
74
|
+
GBP: 20.0448,
|
75
|
+
JPY: 0.0,
|
76
|
+
KWD: 0.0,
|
77
|
+
NOK: 0.0,
|
78
|
+
SAR: 4.2664,
|
79
|
+
SEK: 0.0,
|
80
|
+
USD: 15.8
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns buy: hash of buying prices' do
|
85
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
86
|
+
AED: 0.0,
|
87
|
+
AUD: 0.0,
|
88
|
+
CAD: 0.0,
|
89
|
+
CHF: 14.9665,
|
90
|
+
DKK: 0.0,
|
91
|
+
EUR: 16.0503,
|
92
|
+
GBP: 18.5933,
|
93
|
+
JPY: 0.0,
|
94
|
+
KWD: 0.0,
|
95
|
+
NOK: 0.0,
|
96
|
+
SAR: 3.9856,
|
97
|
+
SEK: 0.0,
|
98
|
+
USD: 15.15
|
99
|
+
)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::UBE do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 6
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 6
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :UBE
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates' do
|
19
|
+
it 'calls #parse with #raw_exchange_rates' do
|
20
|
+
expect(bank).to receive(:raw_exchange_rates)
|
21
|
+
expect(bank).to receive(:parse)
|
22
|
+
bank.exchange_rates
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#raw_exchange_rates' do
|
27
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
28
|
+
stub_request(:get, /.*theubeg.*/).to_return(body: '', status: 500)
|
29
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
30
|
+
EGPRates::ResponseError, '500'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
34
|
+
stub_request(:get, /.*theubeg.*/).to_return(body: '', status: 200)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns <#Enumerator::Lazy> of 6 rows', vcr: { cassette_name: :UBE } do
|
40
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
41
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
42
|
+
expect(lazy_enumerator.size).to eq 6
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#parse', vcr: { cassette_name: :UBE } do
|
47
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
48
|
+
|
49
|
+
it 'returns sell: hash of selling prices' do
|
50
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
51
|
+
AED: 4.778,
|
52
|
+
EUR: 18.6644,
|
53
|
+
GBP: 21.662,
|
54
|
+
KWD: 57.5599,
|
55
|
+
SAR: 4.6798,
|
56
|
+
USD: 17.55
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns buy: hash of buying prices' do
|
61
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
62
|
+
AED: 4.7046,
|
63
|
+
EUR: 18.265,
|
64
|
+
GBP: 21.346,
|
65
|
+
KWD: 56.6929,
|
66
|
+
SAR: 4.5836,
|
67
|
+
USD: 17.28
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|