currency_coin_converter 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fbacf0f12f980a242f4f6c765c1e7195aeb73a36e92f668a23caf7de23ad0d8
4
- data.tar.gz: dcd21694c722a945656103f084110d5d42bc77143e6f488ddbaf23b2c000e242
3
+ metadata.gz: 9e1acd506bad9c54078c6e93298eb1687f3c98384c40587c0982845e466564cf
4
+ data.tar.gz: 489940cb45f403da132769bb84dcdfc8785633c2f7d18db556332abbda8f2562
5
5
  SHA512:
6
- metadata.gz: 45dee2fb4709e41770c912927d205428aa24b4574d52777c5761e32091afc49f9b5a4d40c81f789276538371433763a03181ad30340e59d1f1e9e1f74f2a7767
7
- data.tar.gz: 0b331d65a475f5eb86d8eca9a5831c60ddfb383e45f03d5c1e916cd0e58a97c52fe644265f4c49592684ac6ddca6bee745d75f8907b0e41da25f92293c73102a
6
+ metadata.gz: 4aedaef1ae1b57836423c9e481153cc0514ae39bcafd303302e6cc46b15248574e95f1bd36f335f0c3dc413159ca710c51103817ea2c039c9f2208e256682f1a
7
+ data.tar.gz: 65d932e61bbf521b30730cc62ad65be1426eba333d2d5f13edfa15696e9612a76e78993d23a3d3d4474a1aff8f43d381808fb12bbe6b81d621a08a80b86a5cad
data/CHANGELOG.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.3.2] - 2024-09-10
3
+ ## [0.3.3] - 2024-09-10
4
4
 
5
5
  - Initial release
@@ -4,7 +4,7 @@ require 'singleton'
4
4
  require 'uri'
5
5
 
6
6
  module CurrencyCoinConverter
7
- VERSION = "0.3.2"
7
+ VERSION = "0.3.3"
8
8
 
9
9
  class Error < StandardError; end
10
10
 
@@ -16,12 +16,12 @@ module CurrencyCoinConverter
16
16
  end
17
17
 
18
18
  def convert(amount, from:, to:, round: 2)
19
- (amount * conversion_rate(from:, to:)).round(round)
19
+ (amount * conversion_rate(from: from, to: to)).round(round)
20
20
  end
21
21
 
22
22
  def conversion_rate(from:, to:)
23
23
  conversion_rate = conversion_rates(from)[to]
24
- return conversion_rate unless conversion_rate.nil?
24
+ return conversion_rate if conversion_rate
25
25
 
26
26
  raise Error, "currency code is invalid: #{to}"
27
27
  end
@@ -64,11 +64,11 @@ module CurrencyCoinConverter
64
64
  end
65
65
 
66
66
  def convert(amount, from:, to:, round: 2)
67
- instance.convert(amount, from:, to:, round: round)
67
+ instance.convert(amount, from: from, to: to, round: round)
68
68
  end
69
69
 
70
70
  def conversion_rate(from:, to:)
71
- instance.conversion_rate(from:, to:)
71
+ instance.conversion_rate(from: from, to: to)
72
72
  end
73
73
 
74
74
  def conversion_rates(base_currency)
@@ -2,7 +2,14 @@ require 'currency_coin_converter'
2
2
 
3
3
  require 'json'
4
4
 
5
+ RSpec.configure do |config|
6
+ config.before(:example, :mock_get => true) do
7
+ allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
8
+ end
9
+ end
10
+
5
11
  RSpec.describe CurrencyCoinConverter::Base do
12
+ let(:response) { JSON.parse(File.read("spec/examples/inr.json")) }
6
13
  before do
7
14
  described_class.api_key = "fake_key"
8
15
  end
@@ -15,24 +22,21 @@ RSpec.describe CurrencyCoinConverter::Base do
15
22
  expect(described_class.api_version).to eq("v6")
16
23
  end
17
24
 
18
- it '#conversion_rates returns the conversion rate for a valid currency code' do
19
- response = JSON.parse(File.read("spec/examples/inr.json"))
20
- allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
25
+ it '#conversion_rates returns the conversion rate for a valid currency code', :mock_get => true do
26
+ # allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
21
27
 
22
28
  expect(described_class.conversion_rates("INR")).to eq(response["conversion_rates"])
23
29
  end
24
30
 
25
- it '#conversion_rate returns the conversion rate for valid currency codes' do
26
- response = JSON.parse(File.read("spec/examples/inr.json"))
27
- allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
31
+ it '#conversion_rate returns the conversion rate for valid currency codes', :mock_get => true do
32
+ # allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
28
33
 
29
34
  expect(described_class.conversion_rate(from: "INR", to: "USD")).to eq(response["conversion_rates"]["USD"])
30
35
  expect { described_class.conversion_rate(from: "INR", to: "US") }.to raise_error CurrencyCoinConverter::Error, "currency code is invalid: US"
31
36
  end
32
37
 
33
- it '#convert returns the converted amount from one currency code to another' do
34
- response = JSON.parse(File.read("spec/examples/inr.json"))
35
- allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
38
+ it '#convert returns the converted amount from one currency code to another', :mock_get => true do
39
+ # allow_any_instance_of(described_class).to receive(:get).with(path: "INR").and_return(response)
36
40
 
37
41
  expect(described_class.convert(130, from: "INR", to: "USD")).to eq(1.55)
38
42
  expect(described_class.convert(130, from: "INR", to: "USD", round: 1)).to eq(1.5)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currency_coin_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernanda de Jesus