currency_switcher 0.0.2 → 0.0.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 +7 -0
- data/.rspec +2 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +44 -0
- data/Manifest +15 -8
- data/README.md +4 -4
- data/Rakefile +2 -2
- data/currency_switcher.gemspec +18 -17
- data/lib/currency_switcher.rb +33 -23
- data/spec/currency_switcher_spec.rb +64 -0
- data/spec/spec_helper.rb +41 -0
- data/{test → spec/support}/html/eur_to_usd.html +0 -0
- data/{test → spec/support}/html/usd_to_gbp.html +0 -0
- metadata +50 -66
- data/test/helper.rb +0 -26
- data/test/test_currency_switcher.rb +0 -79
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a47ea06217ab261863b50b7c863a61134cd8a6c
|
4
|
+
data.tar.gz: 0a86943cff1e33cea8f8e7e81912aba7837ad936
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a3f3ad66df51c619b7e8940f2eaa04ce0576f3d6d75b4bec23d03735c1f6cca0df4a47a1c7185eb4bc632ae804a9fdfd2f40fd780cc6e26e8287cfee3be58eb
|
7
|
+
data.tar.gz: ca07d7128613604e2fc316f9f50fe39e3b294cd9961c428770bfb32c1cc0a8d4a289d9c7518b7300552cff19f1ccd0a05a909e2c5585e3f44bb68f70addda33f
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
allison (2.0.3)
|
5
|
+
diff-lcs (1.2.5)
|
6
|
+
echoe (4.6.6)
|
7
|
+
allison (>= 2.0.3)
|
8
|
+
rake (>= 0.9.2)
|
9
|
+
rdoc (>= 2.5.11)
|
10
|
+
rubyforge (>= 2.0.4)
|
11
|
+
fakeweb (1.3.0)
|
12
|
+
json (1.8.1)
|
13
|
+
json_pure (1.8.1)
|
14
|
+
mini_portile (0.6.2)
|
15
|
+
nokogiri (1.6.5)
|
16
|
+
mini_portile (~> 0.6.0)
|
17
|
+
rake (10.4.2)
|
18
|
+
rdoc (4.2.0)
|
19
|
+
json (~> 1.4)
|
20
|
+
rspec (3.1.0)
|
21
|
+
rspec-core (~> 3.1.0)
|
22
|
+
rspec-expectations (~> 3.1.0)
|
23
|
+
rspec-mocks (~> 3.1.0)
|
24
|
+
rspec-core (3.1.7)
|
25
|
+
rspec-support (~> 3.1.0)
|
26
|
+
rspec-expectations (3.1.2)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.1.0)
|
29
|
+
rspec-mocks (3.1.3)
|
30
|
+
rspec-support (~> 3.1.0)
|
31
|
+
rspec-support (3.1.2)
|
32
|
+
rubyforge (2.0.4)
|
33
|
+
json_pure (>= 1.1.7)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
echoe
|
40
|
+
fakeweb
|
41
|
+
nokogiri
|
42
|
+
rake
|
43
|
+
rspec
|
44
|
+
rspec-mocks
|
data/Manifest
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
lib/currency_switcher
|
1
|
+
.rspec
|
2
|
+
Gemfile
|
3
|
+
Gemfile.lock
|
4
|
+
lib/currency_switcher
|
5
5
|
lib/currency_switcher/currencies.rb
|
6
|
+
lib/currency_switcher/ext
|
6
7
|
lib/currency_switcher/ext/fixnum.rb
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
lib/currency_switcher.rb
|
9
|
+
Manifest
|
10
|
+
Rakefile
|
11
|
+
README.md
|
12
|
+
spec/currency_switcher_spec.rb
|
13
|
+
spec/spec_helper.rb
|
14
|
+
spec/support
|
15
|
+
spec/support/html
|
16
|
+
spec/support/html/eur_to_usd.html
|
17
|
+
spec/support/html/usd_to_gbp.html
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ This is a small library that converts currencies using exchange rates from http:
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
gem install currency_switcher
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
@@ -30,10 +30,10 @@ For example:
|
|
30
30
|
|
31
31
|
For example:
|
32
32
|
|
33
|
-
|
33
|
+
require 'currency_switcher'
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
# Convert 3 US Dollars to British Pounds
|
36
|
+
3.exchange("usd", "gbp")
|
37
37
|
|
38
38
|
## Available Currencies
|
39
39
|
|
data/Rakefile
CHANGED
@@ -2,11 +2,11 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('currency_switcher', '0.0.
|
5
|
+
Echoe.new('currency_switcher', '0.0.3') do |p|
|
6
6
|
p.description = "Convert currencies using exchange rates from http://exchange-rates.org"
|
7
7
|
p.url = "http://github.com/staskie/currency_switcher"
|
8
8
|
p.author = "Dominik Staskiewicz"
|
9
9
|
p.email = "stadominik@gmail.com"
|
10
10
|
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
-
p.development_dependencies = []
|
11
|
+
p.development_dependencies = ['nokogiri']
|
12
12
|
end
|
data/currency_switcher.gemspec
CHANGED
@@ -1,32 +1,33 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: currency_switcher 0.0.3 ruby lib
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.0.
|
5
|
+
s.name = "currency_switcher"
|
6
|
+
s.version = "0.0.3"
|
6
7
|
|
7
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Dominik Staskiewicz"]
|
9
|
-
s.cert_chain = ["/Users/dominik/Documents/keys/gem-public_cert.pem"]
|
10
|
-
s.date = %q{2011-10-09}
|
11
|
-
s.description = %q{Convert currencies using exchange rates from http://exchange-rates.org}
|
12
|
-
s.email = %q{stadominik@gmail.com}
|
13
|
-
s.extra_rdoc_files = ["README.md", "lib/currency_switcher.rb", "lib/currency_switcher/currencies.rb", "lib/currency_switcher/ext/fixnum.rb"]
|
14
|
-
s.files = ["Manifest", "README.md", "Rakefile", "lib/currency_switcher.rb", "lib/currency_switcher/currencies.rb", "lib/currency_switcher/ext/fixnum.rb", "test/helper.rb", "test/html/eur_to_usd.html", "test/html/usd_to_gbp.html", "test/test_currency_switcher.rb", "currency_switcher.gemspec"]
|
15
|
-
s.homepage = %q{http://github.com/staskie/currency_switcher}
|
16
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Currency_switcher", "--main", "README.md"]
|
17
9
|
s.require_paths = ["lib"]
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
s.
|
22
|
-
s.
|
10
|
+
s.authors = ["Dominik Staskiewicz"]
|
11
|
+
s.date = "2015-01-07"
|
12
|
+
s.description = "Convert currencies using exchange rates from http://exchange-rates.org"
|
13
|
+
s.email = "stadominik@gmail.com"
|
14
|
+
s.extra_rdoc_files = ["lib/currency_switcher", "lib/currency_switcher/currencies.rb", "lib/currency_switcher/ext", "lib/currency_switcher/ext/fixnum.rb", "lib/currency_switcher.rb", "README.md"]
|
15
|
+
s.files = [".rspec", "Gemfile", "Gemfile.lock", "Manifest", "README.md", "Rakefile", "currency_switcher.gemspec", "lib/currency_switcher", "lib/currency_switcher.rb", "lib/currency_switcher/currencies.rb", "lib/currency_switcher/ext", "lib/currency_switcher/ext/fixnum.rb", "spec/currency_switcher_spec.rb", "spec/spec_helper.rb", "spec/support", "spec/support/html", "spec/support/html/eur_to_usd.html", "spec/support/html/usd_to_gbp.html"]
|
16
|
+
s.homepage = "http://github.com/staskie/currency_switcher"
|
17
|
+
s.rdoc_options = ["--line-numbers", "--title", "Currency_switcher", "--main", "README.md"]
|
18
|
+
s.rubyforge_project = "currency_switcher"
|
19
|
+
s.rubygems_version = "2.2.2"
|
20
|
+
s.summary = "Convert currencies using exchange rates from http://exchange-rates.org"
|
23
21
|
|
24
22
|
if s.respond_to? :specification_version then
|
25
|
-
s.specification_version =
|
23
|
+
s.specification_version = 4
|
26
24
|
|
27
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<nokogiri>, [">= 0"])
|
28
27
|
else
|
28
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
29
29
|
end
|
30
30
|
else
|
31
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
31
32
|
end
|
32
33
|
end
|
data/lib/currency_switcher.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'open-uri'
|
3
|
+
require 'zlib'
|
3
4
|
|
4
5
|
$:.unshift(File.join(File.dirname(__FILE__), 'currency_switcher'))
|
5
6
|
|
@@ -10,19 +11,19 @@ module CurrencySwitcher
|
|
10
11
|
|
11
12
|
# URL for working out the exchange rate
|
12
13
|
URL = "http://exchange-rates.org/converter"
|
13
|
-
|
14
|
+
|
14
15
|
class << self
|
15
16
|
# Get 'from' currency
|
16
17
|
#
|
17
18
|
# Returns the Symbol of 'from' currency
|
18
19
|
attr_reader :from_currency
|
19
|
-
|
20
|
+
|
20
21
|
# Get 'to' currency
|
21
22
|
#
|
22
23
|
# Returns the Symbol of 'to' currency
|
23
24
|
attr_reader :to_currency
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
# Validates if a method called on Fixnum is a currency
|
27
28
|
# exchange method
|
28
29
|
#
|
@@ -42,7 +43,7 @@ module CurrencySwitcher
|
|
42
43
|
@from_currency = $1.to_sym
|
43
44
|
@to_currency = $2.to_sym
|
44
45
|
@method = method
|
45
|
-
|
46
|
+
|
46
47
|
both_currencies_valid? ? true : false
|
47
48
|
end
|
48
49
|
end
|
@@ -91,48 +92,57 @@ module CurrencySwitcher
|
|
91
92
|
def self.calculate_value(fixnum)
|
92
93
|
ex_rate = exchange_rate
|
93
94
|
raise StandardError, "Could not work out the result" if ex_rate.nil?
|
94
|
-
|
95
|
-
|
96
|
-
|
95
|
+
|
96
|
+
if ex_rate
|
97
|
+
value = "%.2f" % (ex_rate * fixnum)
|
98
|
+
value.to_f
|
99
|
+
end
|
97
100
|
end
|
98
|
-
|
101
|
+
|
99
102
|
# Work out the exchange rate for a given URL.
|
100
103
|
# Parse the response and extract the value
|
101
104
|
#
|
102
105
|
# Returns the Float value of exchange rate or nil
|
103
106
|
def self.exchange_rate
|
104
|
-
|
107
|
+
stream = open(self.link, 'Accept-Encoding' => 'gzip')
|
108
|
+
|
109
|
+
if (stream.content_encoding.empty?)
|
110
|
+
body = stream.read
|
111
|
+
else
|
112
|
+
body = Zlib::GzipReader.new(stream).read
|
113
|
+
end
|
114
|
+
|
115
|
+
doc = Nokogiri::HTML(body)
|
105
116
|
doc.css('#ctl00_M_lblToAmount').text.to_f
|
106
|
-
rescue
|
107
117
|
end
|
108
|
-
|
118
|
+
|
109
119
|
# Create a customized URL for 'from' and 'to' currencies
|
110
120
|
#
|
111
121
|
# Returns the String representing a valid URL
|
112
122
|
def self.link
|
113
123
|
"#{URL}/#{from_currency.to_s.upcase}/#{to_currency.to_s.upcase}/1"
|
114
124
|
end
|
115
|
-
|
125
|
+
|
116
126
|
# Print the available list of currencies
|
117
127
|
#
|
118
128
|
# Returns the String with all the currencies
|
119
129
|
def self.currencies
|
120
130
|
CURRENCIES.keys.sort.each { |symbol| puts "#{symbol} => #{CURRENCIES[symbol]}"}
|
121
131
|
end
|
122
|
-
|
132
|
+
|
123
133
|
private
|
124
|
-
|
134
|
+
|
125
135
|
# Check if from currency if valid
|
126
136
|
#
|
127
137
|
# Returns true if from currency if valid
|
128
138
|
def self.from_currency_valid?
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
139
|
+
CURRENCIES.has_key?(from_currency)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Check if to currency is valid
|
143
|
+
#
|
144
|
+
# Returns true if to currency is valid
|
145
|
+
def self.to_currency_valid?
|
146
|
+
CURRENCIES.has_key?(to_currency)
|
147
|
+
end
|
138
148
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurrencySwitcher do
|
4
|
+
before :all do
|
5
|
+
FakeWeb.register_uri(:get, 'http://exchange-rates.org/converter/EUR/USD/1', :body => mock_eur_to_usd)
|
6
|
+
FakeWeb.register_uri(:get, 'http://exchange-rates.org/converter/USD/GBP/1', :body => mock_usd_to_gbp)
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'when exchanging USD to GBP' do
|
10
|
+
describe '#exchange_rate' do
|
11
|
+
it 'works out the exchange rate' do
|
12
|
+
allow(CurrencySwitcher).to receive_messages(from_currency: :usd)
|
13
|
+
allow(CurrencySwitcher).to receive_messages(to_currency: :gbp)
|
14
|
+
|
15
|
+
expect(CurrencySwitcher.exchange_rate).to eq 0.64539
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'dynamic method for conversion' do
|
20
|
+
it 'works out the result' do
|
21
|
+
expect(2.usd_to_gbp).to eq 1.29
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#exchange_method' do
|
26
|
+
it 'works out the result' do
|
27
|
+
expect( 2.exchange('usd', 'gbp') ).to eq 1.29
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'exceptions' do
|
32
|
+
context 'when invalid currency is used' do
|
33
|
+
it 'raises an exception' do
|
34
|
+
expect { 2.exchange('usd', 'fake_currency') }.to raise_error(StandardError, 'To currency fake_currency is invalid')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when parsing goes wrong' do
|
39
|
+
it 'raises an exception' do
|
40
|
+
allow(Nokogiri).to receive_messages(:HTML => nil)
|
41
|
+
expect { 2.eur_to_usd }.to raise_error(StandardError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when number of arguments is incorrect' do
|
46
|
+
it 'raises an exception' do
|
47
|
+
expect { 2.exchange('usd') }.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when dynamic method building is incorrectly used' do
|
52
|
+
it 'raises an exception' do
|
53
|
+
expect { 2.usd_to_something }.to raise_error(NoMethodError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when an unknown method is called on integer' do
|
58
|
+
it 'passes a method_missing to parent' do
|
59
|
+
expect { 2.unknown_method }.to raise_error(NoMethodError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
$:.unshift(File.join(File.dirname(__FILE__), '../lib'))
|
5
|
+
|
6
|
+
require 'currency_switcher'
|
7
|
+
|
8
|
+
def mock_usd_to_gbp
|
9
|
+
File.open(File.join(File.dirname(__FILE__), 'support/html/usd_to_gbp.html')).read
|
10
|
+
end
|
11
|
+
|
12
|
+
def mock_eur_to_usd
|
13
|
+
File.open(File.join(File.dirname(__FILE__), 'support/html/eur_to_usd.html')).read
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# rspec-expectations config goes here. You can use an alternate
|
18
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
19
|
+
# assertions if you prefer.
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
22
|
+
# and `failure_message` of custom matchers include text for helper methods
|
23
|
+
# defined using `chain`, e.g.:
|
24
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
25
|
+
# # => "be bigger than 2 and smaller than 4"
|
26
|
+
# ...rather than:
|
27
|
+
# # => "be bigger than 2"
|
28
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
32
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
33
|
+
config.mock_with :rspec do |mocks|
|
34
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
35
|
+
# a real object. This is generally recommended, and will default to
|
36
|
+
# `true` in RSpec 4.
|
37
|
+
mocks.verify_partial_doubles = true
|
38
|
+
end
|
39
|
+
|
40
|
+
config.raise_errors_for_deprecations!
|
41
|
+
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,95 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency_switcher
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Dominik Staskiewicz
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
|
-
cert_chain:
|
12
|
-
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
/
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
sLbM5rx6cDa/JpbFFfC9utxnZw94j4kNl1WdGSycMem7Jxwd8iPUFKi3UfASNl+F
|
29
|
-
oJmkjDyU4j4l/MwEsateO3jaJBHfR55jeBc/PposKqEFnGaiBMd+NMLXf50L1hI9
|
30
|
-
SS3CfZyfUqCUm+6aSsicRklnvAJ8S74To2JkO3qp+av0CQkLQ1VWpl79nNhZJN5M
|
31
|
-
wYwJN5o4GnGcdg==
|
32
|
-
-----END CERTIFICATE-----
|
33
|
-
|
34
|
-
date: 2011-10-09 00:00:00 +02:00
|
35
|
-
default_executable:
|
36
|
-
dependencies: []
|
37
|
-
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
38
27
|
description: Convert currencies using exchange rates from http://exchange-rates.org
|
39
28
|
email: stadominik@gmail.com
|
40
29
|
executables: []
|
41
|
-
|
42
30
|
extensions: []
|
43
|
-
|
44
|
-
extra_rdoc_files:
|
45
|
-
- README.md
|
46
|
-
- lib/currency_switcher.rb
|
31
|
+
extra_rdoc_files:
|
47
32
|
- lib/currency_switcher/currencies.rb
|
48
33
|
- lib/currency_switcher/ext/fixnum.rb
|
49
|
-
|
34
|
+
- lib/currency_switcher.rb
|
35
|
+
- README.md
|
36
|
+
files:
|
37
|
+
- ".rspec"
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
50
40
|
- Manifest
|
51
41
|
- README.md
|
52
42
|
- Rakefile
|
43
|
+
- currency_switcher.gemspec
|
53
44
|
- lib/currency_switcher.rb
|
54
45
|
- lib/currency_switcher/currencies.rb
|
55
46
|
- lib/currency_switcher/ext/fixnum.rb
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
- currency_switcher.gemspec
|
61
|
-
has_rdoc: true
|
47
|
+
- spec/currency_switcher_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/support/html/eur_to_usd.html
|
50
|
+
- spec/support/html/usd_to_gbp.html
|
62
51
|
homepage: http://github.com/staskie/currency_switcher
|
63
52
|
licenses: []
|
64
|
-
|
53
|
+
metadata: {}
|
65
54
|
post_install_message:
|
66
|
-
rdoc_options:
|
67
|
-
- --line-numbers
|
68
|
-
- --
|
69
|
-
- --title
|
55
|
+
rdoc_options:
|
56
|
+
- "--line-numbers"
|
57
|
+
- "--title"
|
70
58
|
- Currency_switcher
|
71
|
-
- --main
|
59
|
+
- "--main"
|
72
60
|
- README.md
|
73
|
-
require_paths:
|
61
|
+
require_paths:
|
74
62
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
|
77
|
-
requirements:
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
78
65
|
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version:
|
81
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
|
83
|
-
requirements:
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
84
70
|
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version:
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '1.2'
|
87
73
|
requirements: []
|
88
|
-
|
89
74
|
rubyforge_project: currency_switcher
|
90
|
-
rubygems_version:
|
75
|
+
rubygems_version: 2.2.2
|
91
76
|
signing_key:
|
92
|
-
specification_version:
|
77
|
+
specification_version: 4
|
93
78
|
summary: Convert currencies using exchange rates from http://exchange-rates.org
|
94
|
-
test_files:
|
95
|
-
- test/test_currency_switcher.rb
|
79
|
+
test_files: []
|
data/test/helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'mocha'
|
3
|
-
require 'fakeweb'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
$:.unshift(File.join(File.dirname(__FILE__), '../lib'))
|
7
|
-
|
8
|
-
require 'currency_switcher'
|
9
|
-
|
10
|
-
def mock_usd_to_gbp
|
11
|
-
File.open('html/usd_to_gbp.html').read
|
12
|
-
end
|
13
|
-
|
14
|
-
def mock_eur_to_usd
|
15
|
-
File.open('html/eur_to_usd.html').read
|
16
|
-
end
|
17
|
-
|
18
|
-
def output
|
19
|
-
stdout_org = $stdout
|
20
|
-
new_stdout = StringIO.new
|
21
|
-
$stdout = new_stdout
|
22
|
-
|
23
|
-
yield if block_given?
|
24
|
-
$stdout = stdout_org
|
25
|
-
new_stdout.string
|
26
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestCurrencySwitcher < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
FakeWeb.register_uri(:get, 'http://exchange-rates.org/converter/EUR/USD/1', :body => mock_eur_to_usd)
|
7
|
-
FakeWeb.register_uri(:get, 'http://exchange-rates.org/converter/USD/GBP/1', :body => mock_usd_to_gbp)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_method_missing
|
11
|
-
assert_raise(NoMethodError) { 2.fake_method }
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_usd_to_not_defined_currency
|
15
|
-
assert_raise(NoMethodError) { 2.usd_to_fakemethod }
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_not_defined_currency_to_usd
|
19
|
-
assert_raise(NoMethodError) { 2.fakemethod_to_usd }
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_usd_to_euro_valid_method
|
23
|
-
assert_nothing_raised(NoMethodError) { 2.eur_to_usd }
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_link_for_usd_and_gbp
|
27
|
-
CurrencySwitcher.stubs(:from_currency).returns(:usd)
|
28
|
-
CurrencySwitcher.stubs(:to_currency).returns(:gbp)
|
29
|
-
assert_equal("http://exchange-rates.org/converter/USD/GBP/1", CurrencySwitcher.link)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_link_for_eur_and_usd
|
33
|
-
CurrencySwitcher.stubs(:from_currency).returns(:eur)
|
34
|
-
CurrencySwitcher.stubs(:to_currency).returns(:usd)
|
35
|
-
assert_equal("http://exchange-rates.org/converter/EUR/USD/1", CurrencySwitcher.link)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_exchange_rate
|
39
|
-
CurrencySwitcher.stubs(:from_currency).returns(:usd)
|
40
|
-
CurrencySwitcher.stubs(:to_currency).returns(:gbp)
|
41
|
-
|
42
|
-
assert_equal(0.64539, CurrencySwitcher.exchange_rate)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_usd_to_gbp
|
46
|
-
assert_equal(format(2, 0.64539), 2.usd_to_gbp)
|
47
|
-
assert_equal(format(2, 0.64539), 2.exchange("usd","gbp"))
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
def test_eur_to_usd
|
52
|
-
assert_equal(format(3, 1.3171), 3.eur_to_usd)
|
53
|
-
assert_equal(format(3, 1.3171), 3.exchange("eur","usd"))
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_invalid_currency_error
|
57
|
-
assert_raise(StandardError) { 2.exchange("usd","invalid_currency") }
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_argument_error_for_exchange
|
61
|
-
assert_raise(ArgumentError) { 2.exchange("usd") }
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_exchange_rate_error
|
65
|
-
Nokogiri.stubs(:HTML).returns(nil)
|
66
|
-
assert_raise(StandardError) { 2.eur_to_usd }
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_listing_currencies
|
70
|
-
out = output { CurrencySwitcher.currencies }
|
71
|
-
assert_match(/eur => Euro/, out)
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
def format(fixnum, rate)
|
77
|
-
("%.2f" % (fixnum * rate)).to_f
|
78
|
-
end
|
79
|
-
end
|
data.tar.gz.sig
DELETED
Binary file
|
metadata.gz.sig
DELETED
Binary file
|