currency_switcher 0.0.1
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.
- data.tar.gz.sig +2 -0
- data/Manifest +10 -0
- data/README.md +143 -0
- data/Rakefile +12 -0
- data/currency_switcher.gemspec +33 -0
- data/lib/currency_switcher.rb +101 -0
- data/lib/currency_switcher/currencies.rb +124 -0
- data/lib/currency_switcher/ext/fixnum.rb +23 -0
- data/test/helper.rb +26 -0
- data/test/html/eur_to_usd.html +413 -0
- data/test/html/usd_to_gbp.html +413 -0
- data/test/test_currency_switcher.rb +68 -0
- metadata +104 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,68 @@
|
|
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
|
+
end
|
48
|
+
|
49
|
+
def test_eur_to_usd
|
50
|
+
assert_equal(format(3, 1.3171), 3.eur_to_usd)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_exchange_rate_error
|
54
|
+
Nokogiri.stubs(:HTML).returns(nil)
|
55
|
+
assert_raise(StandardError) { 2.eur_to_usd }
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_listing_currencies
|
59
|
+
out = output { CurrencySwitcher.currencies }
|
60
|
+
assert_match(/eur => Euro/, out)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def format(fixnum, rate)
|
66
|
+
("%.2f" % (fixnum * rate)).to_f
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: currency_switcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dominik Staskiewicz
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
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0DLfUt4
|
32
|
+
sLbM5rx6cDa/JpbFFfC9utxnZw94j4kNl1WdGSycMem7Jxwd8iPUFKi3UfASNl+F
|
33
|
+
oJmkjDyU4j4l/MwEsateO3jaJBHfR55jeBc/PposKqEFnGaiBMd+NMLXf50L1hI9
|
34
|
+
SS3CfZyfUqCUm+6aSsicRklnvAJ8S74To2JkO3qp+av0CQkLQ1VWpl79nNhZJN5M
|
35
|
+
wYwJN5o4GnGcdg==
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
|
38
|
+
date: 2011-01-07 00:00:00 +01:00
|
39
|
+
default_executable:
|
40
|
+
dependencies: []
|
41
|
+
|
42
|
+
description: Convert currencies using exchange rates from http://exchange-rates.org
|
43
|
+
email: stadominik@gmail.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- README.md
|
50
|
+
- lib/currency_switcher.rb
|
51
|
+
- lib/currency_switcher/currencies.rb
|
52
|
+
- lib/currency_switcher/ext/fixnum.rb
|
53
|
+
files:
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/currency_switcher.rb
|
57
|
+
- lib/currency_switcher/currencies.rb
|
58
|
+
- lib/currency_switcher/ext/fixnum.rb
|
59
|
+
- test/helper.rb
|
60
|
+
- test/html/eur_to_usd.html
|
61
|
+
- test/html/usd_to_gbp.html
|
62
|
+
- test/test_currency_switcher.rb
|
63
|
+
- Manifest
|
64
|
+
- currency_switcher.gemspec
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/staskie/currency_switcher
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --line-numbers
|
72
|
+
- --inline-source
|
73
|
+
- --title
|
74
|
+
- Currency_switcher
|
75
|
+
- --main
|
76
|
+
- README.md
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 1
|
94
|
+
- 2
|
95
|
+
version: "1.2"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project: currency_switcher
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Convert currencies using exchange rates from http://exchange-rates.org
|
103
|
+
test_files:
|
104
|
+
- test/test_currency_switcher.rb
|
metadata.gz.sig
ADDED
Binary file
|