backpack_tf 0.2.1 → 0.5.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.
@@ -2,74 +2,125 @@ require 'spec_helper'
2
2
 
3
3
  module BackpackTF
4
4
  describe 'Client' do
5
- context 'The Client class' do
6
-
7
- it 'has these default options' do
8
- ans = { base_uri: 'http://backpack.tf/api', timeout: 5 }
9
- ans[:default_params] = { key: ENV[Client.env_var] }
10
- expect(Client.default_options).to eq ans
5
+ let(:bp) { Client.new }
6
+
7
+ it 'has these default options' do
8
+ ans = { base_uri: 'http://backpack.tf/api', timeout: 5 }
9
+ ans[:default_params] = { key: ENV[Client.env_var] }
10
+ expect(Client.default_options).to eq ans
11
+ end
12
+
13
+ describe '::api_key' do
14
+ it 'Raises ArgumentError, if key is not a hexadecimal string' do
15
+ fake_key = 'abcdefghijklmnopqrstuvwx'
16
+ expect{Client.api_key(fake_key)}.to raise_error ArgumentError
17
+ end
18
+ it 'Raises ArgumentError, if key is not 24 digits long' do
19
+ fake_key = 'abcdef0987654321'
20
+ expect{Client.api_key(fake_key)}.to raise_error ArgumentError
21
+ end
22
+ it 'lets an otherwise theoretically-valid key, pass through' do
23
+ key = generate_fake_api_key
24
+ expect(Client.api_key(key)).to eq key
11
25
  end
26
+ end
12
27
 
13
- describe '::api_key' do
14
- it 'Raises ArgumentError, if key is not a hexadecimal string' do
15
- fake_key = 'abcdefghijklmnopqrstuvwx'
16
- expect{Client.api_key(fake_key)}.to raise_error ArgumentError
17
- end
18
- it 'Raises ArgumentError, if key is not 24 digits long' do
19
- fake_key = 'abcdef0987654321'
20
- expect{Client.api_key(fake_key)}.to raise_error ArgumentError
21
- end
22
- it 'lets an otherwise theoretically-valid key, pass through' do
23
- key = generate_fake_api_key
24
- expect(Client.api_key(key)).to eq key
25
- end
28
+ describe '::extract_query_string' do
29
+ it 'produces a query parameter string' do
30
+ opts = {:key => Client.api_key, :appid => 440, :format => 'json', :compress => 1, :raw => 2}
31
+ ans = "key=#{Client.api_key}&appid=440&format=json&compress=1&raw=2"
32
+ expect(Client.extract_query_string(opts)).to eq ans
26
33
  end
34
+ end
27
35
 
28
- describe '::extract_query_string' do
29
- it 'produces a query parameter string' do
30
- opts = {:key => Client.api_key, :appid => 440, :format => 'json', :compress => 1, :raw => 2}
31
- ans = "key=#{Client.api_key}&appid=440&format=json&compress=1&raw=2"
32
- expect(Client.extract_query_string(opts)).to eq ans
33
- end
36
+ describe '::build_url_via' do
37
+ it 'returns correct destination url when asking for pricing data' do
38
+ opts = {:key => Client.api_key, :compress => 1}
39
+ expect(Client.build_url_via(:get_prices, opts)).to eq "http://backpack.tf/api/IGetPrices/v4/?key=#{Client.api_key}&compress=1"
40
+ end
41
+ it 'raises an error when asking for any unexpected interface' do
42
+ expect{Client.build_url_via(:foo)}.to raise_error ArgumentError
43
+ end
44
+ end
45
+
46
+ describe '#fetch' do
47
+
48
+ before :each do
49
+ stub_http_response_with('currencies.json')
50
+ end
51
+
52
+ let(:fetched_currencies) {
53
+ bp.fetch(:currencies, {:compress => 1, :appid => 440})
54
+ }
55
+
56
+ it 'fetches JSON from an interface and returns as a Hash object' do
57
+ expect(fetched_currencies).to be_instance_of Hash
58
+ end
59
+ it 'fetched response has these keys' do
60
+ expected_keys = %w(currencies current_time name success url)
61
+ expect(fetched_currencies.keys).to match_array expected_keys
34
62
  end
35
63
 
36
- describe '::build_url_via' do
37
- it 'returns correct destination url when asking for pricing data' do
38
- opts = {:key => Client.api_key, :compress => 1}
39
- expect(Client.build_url_via(:get_prices, opts)).to eq "http://backpack.tf/api/IGetPrices/v4/?key=#{Client.api_key}&compress=1"
40
- end
41
- it 'raises an error when asking for any unexpected interface' do
42
- expect{Client.build_url_via(:foo)}.to raise_error ArgumentError
43
- end
44
- end
45
64
  end
46
-
47
- context 'Instances of Client' do
48
- let(:bp) { Client.new }
49
-
50
- describe '#get_data' do
51
-
52
- it 'returns results from archived json file' do
53
- stub_http_response_with('currencies.json')
54
- opts = { :key => Client.api_key, :compress => 1, :appid => 440 }
55
- currencies = bp.get_data(:get_currencies, opts)
56
-
57
- expect(currencies['response']).to have_key('success')
58
- expect(currencies['response']).to have_key('currencies')
59
- expect(currencies['response']).to have_key('name')
60
- expect(currencies['response']).to have_key('url')
61
- expect(currencies['response']).to have_key('current_time')
62
- end
63
65
 
64
- it 'client requests are returned as ruby Hash objects' do
65
- stub_http_response_with('prices.json')
66
- opts = {:app_id => 440, :compress => 1}
67
- expect(bp.get_data(:get_prices, opts)).to be_instance_of Hash
68
- end
66
+ describe '#update' do
67
+ #context "USING rspec/mock, updating another another class' class variable" do
68
+ # before :each do
69
+ # MockResponse = class_double(Response)
70
+ # MockCurrencies = class_double(Currencies)
71
+
72
+ # allow(MockResponse).to receive(:responses) {
73
+ # { MockCurrencies => fetched_currencies }
74
+ # }
75
+ # expect(MockResponse.responses.keys).to eq [MockCurrencies]
76
+
77
+ # allow(MockCurrencies).to receive(:response) {
78
+ # Response.hash_keys_to_sym(MockResponse.responses[MockCurrencies])
79
+ # }
80
+ # expect(MockCurrencies.response.keys).to eq [:success, :currencies, :name, :url, :current_time]
81
+
82
+ # allow(MockCurrencies).to receive(:currencies)
83
+ # #expect(MockCurrencies.response).to be_nil
84
+ # end
69
85
 
86
+ # it 'the client passes its fetched data to Response.response class method' do
87
+ # end
88
+ # it 'the client can pass fetched data to another class so the class can update one of its own class variables' do
89
+ # MockResponse.responses(MockCurrencies => fetched_currencies)
90
+ # MockCurrencies.response
91
+ # expect(MockCurrencies.currencies).not_to be_nil
92
+ # end
93
+ #end
94
+
95
+ before :each do
96
+ stub_http_response_with('currencies.json')
97
+ Response.responses(:reset => :confirm)
98
+ expect(Response.responses).to be_empty
99
+ expect(Currencies.response).to be_nil
100
+ expect(Currencies.currencies).to be_nil
101
+ end
102
+
103
+ let(:fetched_currencies) {
104
+ bp.fetch(:currencies, {:compress => 1, :appid => 440})
105
+ }
106
+
107
+ context 'results on the Currencies.response method' do
108
+ it 'returns this Hash object' do
109
+ bp.update(Currencies, fetched_currencies)
110
+ processed_json = Response.hash_keys_to_sym(fetched_currencies)
111
+ expect(Currencies.response).to eq processed_json
112
+ end
70
113
  end
71
114
 
115
+ context 'results on the Currencies.currencies method' do
116
+ it 'returns this Hash object' do
117
+ bp.update(Currencies, fetched_currencies)
118
+ processed_json = Response.hash_keys_to_sym(fetched_currencies['currencies'])
119
+ expect(Currencies.currencies).to eq processed_json
120
+ end
121
+ end
72
122
 
73
123
  end
124
+
74
125
  end
75
126
  end
@@ -4,42 +4,96 @@ module BackpackTF
4
4
  describe 'Currencies' do
5
5
  let(:bp) { Client.new }
6
6
 
7
- describe 'the class' do
7
+ let(:json_obj) {
8
+ fixture = file_fixture('currencies.json')
9
+ fixture = JSON.parse(fixture)['response']
10
+ Response.hash_keys_to_sym(fixture)
11
+ }
8
12
 
9
- it 'has these default attributes' do
10
- expect(Currencies.interface).to eq :IGetCurrencies
13
+ let(:more_json) {
14
+ fixture = file_fixture('currencies_updated.json')
15
+ fixture = JSON.parse(fixture)['response']
16
+ Response.hash_keys_to_sym(fixture)
17
+ }
18
+
19
+ it 'responds to these methods' do
20
+ expect(Currencies).to respond_to :responses, :response, :currencies, :interface, :hash_keys_to_sym
21
+ end
22
+
23
+ it 'has these default attributes' do
24
+ expect(Currencies.interface).to eq :IGetCurrencies
25
+ end
26
+
27
+ describe '::responses' do
28
+
29
+ before :each do
30
+ stub_http_response_with('currencies.json')
31
+ opts = { :app_id => 440, :compress => 1 }
32
+ fetched_currencies = bp.fetch(:currencies, opts)
33
+ Response.responses(Currencies.to_sym => fetched_currencies)
11
34
  end
12
35
 
13
- describe 'accessing the IGetCurrencies interface' do
14
- it 'returns the fixture and sets to @@currencies variable' do
15
- stub_http_response_with('currencies.json')
16
- opts = { :app_id => 440, :compress => 1 }
17
- Currencies.fetch(bp.get_data(:get_currencies, opts)['response'])
18
- expect(Currencies.currencies).not_to be_nil
36
+ context 'access from Response class' do
37
+ it 'Currencies can be accessed by calling the key, Currencies' do
38
+ expect(Response.responses[:'BackpackTF::Currencies']).to eq json_obj
19
39
  end
40
+ end
20
41
 
21
- it 'the response attribute should have these keys' do
22
- expect(Currencies.response.keys).to match_array [:success, :current_time, :currencies, :name, :url]
42
+ context 'access from Currencies class' do
43
+ it 'can access response information via the class method, ::response' do
44
+ expect(Currencies.response).to eq json_obj
23
45
  end
46
+ end
24
47
 
25
- it 'the keys of the response attribute should have these values' do
26
- expect(Currencies.response[:success]).to eq 1
27
- expect(Currencies.response[:message]).to eq nil
28
- expect(Currencies.response[:current_time]).to eq 1430784460
29
- expect(Currencies.response[:name]).to eq 'Team Fortress 2'
30
- expect(Currencies.response[:url]).to eq 'http://backpack.tf'
31
- end
48
+ it 'is the same as calling Currencies.response' do
49
+ expect(Response.responses[:'BackpackTF::Currencies']).to eq Currencies.response
50
+ end
51
+ end
32
52
 
33
- it '@@currencies attribute should be a Hash object' do
34
- expect(Currencies.currencies).to be_instance_of Hash
35
- end
53
+ describe '::response' do
54
+ before :each do
55
+ stub_http_response_with('currencies.json')
56
+ opts = { :app_id => 440, :compress => 1 }
57
+ fetched_currencies = bp.fetch(:currencies, opts)
58
+ Response.responses(':BackpackTF::Currencies' => fetched_currencies)
59
+ end
60
+ it 'the response attribute should have these keys' do
61
+ expect(Currencies.response.keys).to match_array [:success, :current_time, :currencies, :name, :url]
62
+ end
36
63
 
37
- it '@@currencies should have these keys' do
38
- expected_keys = [:metal, :keys, :earbuds, :hat]
39
- expect(Currencies.currencies.keys).to match_array expected_keys
40
- end
64
+ it 'the keys of the response attribute should have these values' do
65
+ expect(Currencies.response[:success]).to eq 1
66
+ expect(Currencies.response[:message]).to eq nil
67
+ expect(Currencies.response[:current_time]).to eq 1430784460
68
+ expect(Currencies.response[:name]).to eq 'Team Fortress 2'
69
+ expect(Currencies.response[:url]).to eq 'http://backpack.tf'
70
+ end
71
+
72
+ end
73
+
74
+ describe '::currencies' do
75
+ before :each do
76
+ Response.responses(:reset => :confirm)
77
+ expect(Response.responses).to be_empty
78
+
79
+ stub_http_response_with('currencies.json')
80
+ opts = { :app_id => 440, :compress => 1 }
81
+ fetched_currencies = bp.fetch(:currencies, opts)
82
+ Response.responses(:'BackpackTF::Currencies' => fetched_currencies)
83
+ end
84
+
85
+ it 'returns the fixture and sets to @@currencies variable' do
86
+ expect(Currencies.currencies).not_to be_nil
41
87
  end
42
88
 
89
+ it '@@currencies attribute should be a Hash object' do
90
+ expect(Currencies.currencies).to be_instance_of Hash
91
+ end
92
+
93
+ it '@@currencies should have these keys' do
94
+ expected_keys = [:metal, :keys, :earbuds, :hat]
95
+ expect(Currencies.currencies.keys).to match_array expected_keys
96
+ end
43
97
  end
44
98
 
45
99
  describe 'instance of Currencies' do
@@ -47,7 +101,7 @@ module BackpackTF
47
101
  let (:metal) { Currencies.new(:metal, Currencies.currencies[:metal]) }
48
102
 
49
103
  it 'should respond to these methods' do
50
- expect(metal).to respond_to :quality, :priceindex, :single, :plural, :round, :craftable, :tradable, :defindex, :blanket
104
+ expect(metal).to respond_to(:quality, :priceindex, :single, :plural, :round, :craftable, :tradable, :defindex, :blanket)
51
105
  end
52
106
 
53
107
  it 'should have these values' do
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module BackpackTF
4
+
5
+ class Dummy
6
+ include BackpackTF::Finder
7
+ end
8
+
9
+ shared_examples 'Finder' do
10
+ let(:dummy) { Dummy.new }
11
+
12
+ it 'responds to these inherited class methods' do
13
+ expect(Dummy).to respond_to(:get_item_price, :defindex_to_item_name, :find_item_by_name, :is_item_of_type?, :get_name_of_random_item)
14
+ end
15
+
16
+ end
17
+
18
+ describe Prices do
19
+ it_behaves_like 'Finder'
20
+ end
21
+
22
+ describe Item do
23
+ it_behaves_like 'Finder'
24
+ end
25
+
26
+ describe ItemPrice do
27
+ it_behaves_like 'Finder'
28
+ end
29
+
30
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ module BackpackTF
4
+ describe 'ItemPrice' do
5
+ describe 'instance of ItemPrice' do
6
+ context "A typical item that does NOT have the quality 'Unusual'" do
7
+ let(:item_price_key) { 'Unique_Tradable_Craftable' }
8
+ let(:item_price_attr) { '{"currency":"metal","value":0.05,"last_update":1336410088,"difference":0}' }
9
+ let (:item_price) { ItemPrice.new(item_price_key, item_price_attr) }
10
+
11
+ it 'should respond to these methods' do
12
+ expect(item_price).to respond_to :quality, :tradability, :craftability, :priceindex, :currency, :value, :value_high, :value_raw, :value_high_raw, :last_update, :difference
13
+ end
14
+ it 'should have these values' do
15
+ expect(item_price.quality).to eq :Unique
16
+ expect(item_price.tradability).to eq :Tradable
17
+ expect(item_price.craftability).to eq :Craftable
18
+ expect(item_price.currency).to eq :metal
19
+ expect(item_price.value).to eq 0.05
20
+ expect(item_price.value_high).to be_nil
21
+ expect(item_price.value_raw).to be_nil
22
+ expect(item_price.value_high_raw).to be_nil
23
+ expect(item_price.last_update).to eq 1336410088
24
+ expect(item_price.difference).to eq 0
25
+ expect(item_price.priceindex).to be_nil
26
+ end
27
+ end
28
+
29
+ context "An item with the quality 'Unusual'" do
30
+ # the Unusual item being tested is the 'Barnstormer'
31
+ let(:item_price_key) { 'Unusual_Tradable_Craftable' }
32
+ #let(:item_price_attr) {'{"6":{"currency":"keys","value":18,"last_update":1418795322,"difference":280,"value_high":22}}'}
33
+ let(:item_price_attr) {'{"currency":"keys","value":18,"last_update":1418795322,"difference":280,"value_high":22}'}
34
+ let(:item_price) { ItemPrice.new(item_price_key, item_price_attr, 6) }
35
+
36
+ it 'should respond to these methods' do
37
+ expect(item_price).to respond_to :quality, :tradability, :craftability, :priceindex, :currency, :value, :value_high, :value_raw, :value_high_raw, :last_update, :difference
38
+ end
39
+ it 'should have these values' do
40
+ expect(item_price.quality).to eq :Unusual
41
+ expect(item_price.tradability).to eq :Tradable
42
+ expect(item_price.craftability).to eq :Craftable
43
+ expect(item_price.currency).to eq :keys
44
+ expect(item_price.value).to eq 18
45
+ expect(item_price.value_high).to eq 22
46
+ expect(item_price.value_raw).to be_nil
47
+ expect(item_price.value_high_raw).to be_nil
48
+ expect(item_price.last_update).to eq 1418795322
49
+ expect(item_price.difference).to eq 280
50
+ expect(item_price.priceindex).to eq 6
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -2,24 +2,173 @@ require 'spec_helper'
2
2
 
3
3
  module BackpackTF
4
4
  describe 'Item' do
5
- it 'The Prices class returns the fixture and sets to its @@items variable' do
6
- stub_http_response_with('prices.json')
7
- opts = { :app_id => 440, :compress => 1 }
8
- Prices.fetch(Client.new.get_data(:get_prices, opts)['response'])
9
- expect(Prices.items).not_to be_nil
5
+ let(:expected_keys) do
6
+ ["Strange_Tradable_Craftable", "Collector's_Tradable_Craftable", "Vintage_Tradable_Craftable", "Unique_Tradable_Craftable", "Unique_Tradable_Non-Craftable"]
7
+ end
8
+
9
+ xdescribe '::generate_price_keys' do
10
+ it 'includes these keys' do
11
+ keys = Item.generate_price_keys(stub)
12
+ keys.each{ |key| expect(expected_keys).to include(key) }
13
+ end
14
+ it 'produces all of these keys' do
15
+ keys = Item.generate_price_keys(stub['prices'])
16
+ expect(keys).to match_array expected_keys
17
+ end
10
18
  end
11
19
 
12
20
  describe 'instance of Item' do
21
+ context 'a typical game item, which does not have any item qualities of Unusual' do
22
+ let(:item_name) { 'Kritzkrieg' }
23
+ let(:stub) do
24
+ JSON.parse '{"defindex":[35],"prices":{"11":{"Tradable":{"Craftable":[{"currency":"keys","value":18,"last_update":1430665867,"difference":-18.495}]}},"14":{"Tradable":{"Craftable":[{"currency":"keys","value":9,"last_update":1416841372,"difference":11.385}]}},"3":{"Tradable":{"Craftable":[{"currency":"metal","value":0.66,"last_update":1426439779,"difference":0.33}]}},"6":{"Tradable":{"Craftable":[{"currency":"metal","value":0.05,"last_update":1336410088,"difference":0}],"Non-Craftable":[{"currency":"metal","value":0.05,"last_update":1362791812,"difference":0.03}]}}}}'
25
+ end
26
+ let(:item) { Item.new(item_name, stub) }
27
+ let(:prices_hash) { item.gen_prices_hash(stub) }
28
+
29
+ it 'should respond to these methods' do
30
+ expect(item).to respond_to :item_name, :defindex, :prices, :gen_prices_hash
31
+ end
32
+
33
+ it 'should have these values' do
34
+ expect(item.item_name).to eq 'Kritzkrieg'
35
+ expect(item.defindex).to eq 35
36
+ end
37
+
38
+ describe '#gen_prices_hash' do
39
+ it 'generates a Hash' do
40
+ expect(prices_hash).to be_instance_of Hash
41
+ end
42
+ it 'each key is a String' do
43
+ expect(prices_hash.keys).to all be_a String
44
+ end
45
+ it 'includes these keys' do
46
+ prices_hash.keys.each{ |key| expect(expected_keys).to include(key) }
47
+ end
48
+ it 'value of each key is an ItemPrice object' do
49
+ expect(prices_hash.values).to all be_an ItemPrice
50
+ end
51
+ end
52
+
53
+ describe 'the @prices instance variable' do
54
+ it 'is a Hash' do
55
+ expect(item.prices).to be_a Hash
56
+ end
57
+ it 'include these keys' do
58
+ item.prices.keys.each{|key| expect(expected_keys).to include(key)}
59
+ end
60
+ xit 'has all of these keys' do
61
+ expect(item.prices.keys).to eq expected_keys
62
+ end
63
+ it 'each value is an ItemPrice object' do
64
+ expect(item.prices.values).to all be_an ItemPrice
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'an item with a quality of Unusual' do
70
+ let(:item_name) { 'Barnstormer' }
71
+ let(:stub) { JSON.parse(file_fixture('item_unusual.json')) }
72
+ let(:item) { Item.new(item_name, stub) }
73
+ let(:prices_hash) { item.gen_prices_hash(stub) }
74
+
75
+ it 'should respond to these methods' do
76
+ expect(item).to respond_to :item_name, :defindex, :prices, :gen_prices_hash
77
+ end
78
+ it 'should have these values' do
79
+ expect(item.item_name).to eq 'Barnstormer'
80
+ expect(item.defindex).to eq 988
81
+ end
82
+
83
+ describe '#gen_prices_hash' do
84
+ it 'generates a Hash' do
85
+ expect(prices_hash).to be_instance_of Hash
86
+ end
87
+ it 'each key is a String' do
88
+ expect(prices_hash.keys).to all be_a String
89
+ end
90
+ it 'value of each key is an ItemPrice object' do
91
+ expect(prices_hash.values).to all be_an ItemPrice
92
+ end
93
+ end
94
+ describe 'the @prices instance variable' do
95
+ it 'is a Hash' do
96
+ expect(item.prices).to be_a Hash
97
+ end
98
+ it 'each value is an ItemPrice object' do
99
+ expect(item.prices.values).to all be_an ItemPrice
100
+ end
101
+ end
102
+ end
103
+
104
+ context 'an item with an unconventional structure' do
105
+ let(:item_name) { 'Aqua Summer 2013 Coolor' }
106
+ let(:stub) { JSON.parse(file_fixture('item_with_unconventional_structure.json')) }
107
+ let(:item) { Item.new(item_name, stub) }
108
+ let(:prices_hash) { item.gen_prices_hash(stub) }
13
109
 
14
- let (:item) { Item.new('Kritzkrieg', Prices.items['Kritzkrieg']) }
110
+ it 'should respond to these methods' do
111
+ expect(item).to respond_to :item_name, :defindex, :prices, :gen_prices_hash
112
+ end
113
+ it 'should have these values' do
114
+ expect(item.item_name).to eq 'Aqua Summer 2013 Coolor'
115
+ expect(item.defindex).to eq 5650
116
+ end
15
117
 
16
- it 'should respond to these methods' do
17
- expect(item).to respond_to :item_name, :defindex, :prices
118
+ describe '#gen_prices_hash' do
119
+ it 'generates a Hash' do
120
+ expect(prices_hash).to be_instance_of Hash
121
+ end
122
+ it 'each key is a String' do
123
+ expect(prices_hash.keys).to all be_a String
124
+ end
125
+ it 'value of each key is an ItemPrice object' do
126
+ expect(prices_hash.values).to all be_an ItemPrice
127
+ end
128
+ end
129
+ describe 'the @prices instance variable' do
130
+ it 'is a Hash' do
131
+ expect(item.prices).to be_a Hash
132
+ end
133
+ it 'each value is an ItemPrice object' do
134
+ expect(item.prices.values).to all be_an ItemPrice
135
+ end
136
+ end
18
137
  end
19
138
 
20
- it 'should have these values' do
21
- expect(item.item_name).to eq 'Kritzkrieg'
22
- expect(item.defindex).to eq 35
139
+ context 'an item that has no `defindex` or has a negative `defindex`' do
140
+ let(:item_name) { 'Strange Part: Fires Survived' }
141
+ let(:stub) { JSON.parse(file_fixture('item_without_defindex.json')) }
142
+ let(:item) { Item.new(item_name, stub) }
143
+ let(:prices_hash) { item.gen_prices_hash(stub) }
144
+
145
+ it 'should respond to these methods' do
146
+ expect(item).to respond_to :item_name, :defindex, :prices, :gen_prices_hash
147
+ end
148
+ it 'should have these values' do
149
+ expect(item.item_name).to eq 'Strange Part: Fires Survived'
150
+ expect(item.defindex).to eq nil
151
+ end
152
+
153
+ describe '#gen_prices_hash' do
154
+ it 'generates a Hash' do
155
+ expect(prices_hash).to be_instance_of Hash
156
+ end
157
+ it 'each key is a String' do
158
+ expect(prices_hash.keys).to all be_a String
159
+ end
160
+ it 'value of each key is an ItemPrice object' do
161
+ expect(prices_hash.values).to all be_an ItemPrice
162
+ end
163
+ end
164
+ describe 'the @prices instance variable' do
165
+ it 'is a Hash' do
166
+ expect(item.prices).to be_a Hash
167
+ end
168
+ it 'each value is an ItemPrice object' do
169
+ expect(item.prices.values).to all be_an ItemPrice
170
+ end
171
+ end
23
172
  end
24
173
 
25
174
  end