backpack_tf 0.5.0 → 0.8.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/backpack_tf/client.rb +9 -12
- data/lib/backpack_tf/{currencies.rb → currency.rb} +1 -1
- data/lib/backpack_tf/item.rb +1 -27
- data/lib/backpack_tf/item_price.rb +35 -29
- data/lib/backpack_tf/price.rb +97 -0
- data/lib/backpack_tf/response.rb +2 -2
- data/lib/backpack_tf/special_item.rb +58 -0
- data/lib/backpack_tf/user.rb +54 -0
- data/lib/backpack_tf/user_listing.rb +60 -0
- data/lib/backpack_tf/version.rb +1 -1
- data/lib/backpack_tf.rb +5 -3
- data/readme.md +53 -13
- data/spec/backpack_tf/client_spec.rb +19 -19
- data/spec/backpack_tf/{currencies_spec.rb → currency_spec.rb} +23 -23
- data/spec/backpack_tf/price_spec.rb +182 -0
- data/spec/backpack_tf/special_item_spec.rb +101 -0
- data/spec/backpack_tf/user_listing_spec.rb +92 -0
- data/spec/backpack_tf/user_spec.rb +94 -0
- data/spec/fixtures/special_items.json +1 -0
- data/spec/fixtures/user_listing.json +1 -0
- data/spec/fixtures/users.json +1 -0
- metadata +14 -7
- data/lib/backpack_tf/finder.rb +0 -87
- data/lib/backpack_tf/prices.rb +0 -49
- data/spec/backpack_tf/finder_spec.rb +0 -30
- data/spec/backpack_tf/prices_spec.rb +0 -130
data/lib/backpack_tf/version.rb
CHANGED
data/lib/backpack_tf.rb
CHANGED
@@ -8,9 +8,11 @@ end
|
|
8
8
|
# IMPORTANT! require the Response module before any other class or module
|
9
9
|
require 'backpack_tf/version'
|
10
10
|
require 'backpack_tf/response'
|
11
|
-
require 'backpack_tf/finder'
|
12
11
|
require 'backpack_tf/client'
|
13
|
-
require 'backpack_tf/
|
12
|
+
require 'backpack_tf/currency'
|
14
13
|
require 'backpack_tf/item'
|
15
14
|
require 'backpack_tf/item_price'
|
16
|
-
require 'backpack_tf/
|
15
|
+
require 'backpack_tf/price'
|
16
|
+
require 'backpack_tf/special_item'
|
17
|
+
require 'backpack_tf/user'
|
18
|
+
require 'backpack_tf/user_listing'
|
data/readme.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
#backpack_tf
|
2
2
|
Backpack.tf is a website for the in-game economies of Team Fortress 2 and Dota 2. This gem is a wrapper for the backpack.tf [API](http://backpack.tf/api). The goal is to capture the results and turn them into Ruby objects for use in your application.
|
3
3
|
|
4
|
-
It is in the
|
4
|
+
It is in the early stages of development. See the [TODO](TODO.md) list if you are interested in contributing.
|
5
5
|
|
6
6
|
###Installation
|
7
|
-
|
7
|
+
#####install any dependencies
|
8
|
+
`bundle install`
|
9
|
+
|
10
|
+
######Install it as a gem:
|
8
11
|
`gem install backpack_tf`
|
9
12
|
|
10
|
-
Or add it to your project's Gemfile:
|
13
|
+
######Or add it to your project's Gemfile:
|
11
14
|
`gem 'backpack_tf'`
|
12
15
|
|
13
16
|
###Usage
|
@@ -17,40 +20,77 @@ Or add it to your project's Gemfile:
|
|
17
20
|
* Load the gem into your project:
|
18
21
|
`require 'backpack_tf'`
|
19
22
|
|
23
|
+
###Examples
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
##### create a new Client object
|
27
|
+
bp = BackpackTF::Client.new
|
28
|
+
|
29
|
+
##### fetch some data
|
30
|
+
fetched_prices = bp.fetch(:prices, { :compress => 1 })
|
31
|
+
fetched_currencies = bp.fetch(:currencies, { :compress => 1 })
|
32
|
+
fetched_special_items = bp.fetch(:special_items, { :compress => 1})
|
33
|
+
fetched_users = bp.fetch(:users, { :steamids => [64_bit_steam_id_of_one_user, 64_bit_steam_id_of_another_user] })
|
34
|
+
fetched_listings = bp.fetch(:user_listings, { :steamid => 64_bit_steam_id_of_one_user })
|
35
|
+
|
36
|
+
##### update a class with the data
|
37
|
+
# *note*: you should send a message from your Client object to the class before
|
38
|
+
# using any of those class' methods.
|
39
|
+
# This does not apply to the `Item` class and the `ItemPrice` class.
|
40
|
+
# Those are updated through the `Price` class.
|
41
|
+
|
42
|
+
bp.update(BackpackTF::Price, fetched_prices)
|
43
|
+
bp.update(BackpackTF::Currency, fetched_currencies)
|
44
|
+
bp.update(BackpackTF::SpecialItem, fetched_special_items)
|
45
|
+
bp.update(BackpackTF::User, fetched_users)
|
46
|
+
bp.update(BackpackTF::UserListing, fetched_listings)
|
47
|
+
|
48
|
+
##### look at prices of a random item
|
49
|
+
random_key = BackpackTF::Price.items.sample
|
50
|
+
BackpackTF::Price.items[random_key]
|
51
|
+
|
52
|
+
```
|
53
|
+
|
20
54
|
##Interfaces
|
21
55
|
|
22
56
|
####IGetPrices
|
23
57
|
* Get pricing data for all priced items
|
24
58
|
* [official doc](http://backpack.tf/api/prices)
|
25
59
|
|
26
|
-
API responses from this
|
60
|
+
API responses from this interface are captured in the `Price` class. The `Price` class is not meant to be instantiated. One of the class attributes is `@@items`, a Hash object. Information on any particular item, ie: 'Eviction Notice', is captured in an instance of the `Item` class. Furthermore, there may be several prices for the same item, ie: an Eviction Notice with the Unique quality has a different price than a Eviction Notice with a Strange quality. Each price is an instance of the `ItemPrice` class, and is stored in the `@prices` hash of that item.
|
27
61
|
|
28
62
|
######a visual
|
29
|
-
* `
|
63
|
+
* `Price` class
|
30
64
|
* `@@items` hash of `Price` class.
|
31
65
|
* `Item` object (ie: 'Beast From Below')
|
32
66
|
* `Item` object (ie: 'Taunt: Rock, Paper Scissors')
|
33
|
-
* `Item` object (ie: '
|
67
|
+
* `Item` object (ie: 'Eviction Notice')
|
34
68
|
* `@prices` hash of an `Item` object
|
35
|
-
* `
|
36
|
-
* `
|
37
|
-
* `
|
69
|
+
* `ItemPrice` object (ie: price for Unique Eviction Notice)
|
70
|
+
* `ItemPrice` object (ie: price for Collector's Eviction Notice)
|
71
|
+
* `ItemPrice` object (ie: price for Strange Eviction Notice)
|
38
72
|
|
39
73
|
####IGetCurrencies
|
40
74
|
* Get internal currency data for a given game
|
41
75
|
* [official doc](http://backpack.tf/api/currencies)
|
42
76
|
|
43
|
-
API responses from this interface are captured in the `
|
77
|
+
API responses from this interface are captured in the `Currency` class. Similar the `Price` class, it has a set of class methods, and attributes to describe the API response. Unlike, the `Price` class, this one can be instantiated. There are currently 4 currencies available through the API. Each one is an instance of `Currency` and is held in the `@@currencies` hash of the `Currency` class.
|
44
78
|
|
45
|
-
####IGetSpecialItems
|
79
|
+
####IGetSpecialItems
|
46
80
|
* Get internal backpack.tf item placeholders for a given game.
|
47
81
|
* [official doc](http://backpack.tf/api/special)
|
48
82
|
|
49
|
-
|
83
|
+
This is for items that only exist on backpack.tf. They are not real game items, but you will see them returned in a call to `IGetPrices`. The class for this interface is `SpecialItem`.
|
84
|
+
|
85
|
+
####IGetUsers
|
50
86
|
* Get profile info for a list of 64-bit Steam IDs.
|
51
87
|
* Does not require an API key
|
52
88
|
* [official doc](http://backpack.tf/api/users)
|
53
89
|
|
54
|
-
|
90
|
+
Get some basic information for a list of backpack.tf users. It's basically the info that you'd see on their profile page. The response for this interface is captured in the `User` class. You can request several users at once by sending them in an array.
|
91
|
+
|
92
|
+
####IGetUserListings
|
55
93
|
* Get classified listings for a given user
|
56
94
|
* [official doc](http://backpack.tf/api/classifieds)
|
95
|
+
|
96
|
+
Request all classified listings for one user. You must pass in the 64-bit `steamid`. The response is captured in the `UserListing` class.
|
@@ -67,28 +67,28 @@ module BackpackTF
|
|
67
67
|
#context "USING rspec/mock, updating another another class' class variable" do
|
68
68
|
# before :each do
|
69
69
|
# MockResponse = class_double(Response)
|
70
|
-
#
|
70
|
+
# MockCurrency = class_double(Currency)
|
71
71
|
|
72
72
|
# allow(MockResponse).to receive(:responses) {
|
73
|
-
# {
|
73
|
+
# { MockCurrency => fetched_currencies }
|
74
74
|
# }
|
75
|
-
# expect(MockResponse.responses.keys).to eq [
|
75
|
+
# expect(MockResponse.responses.keys).to eq [MockCurrency]
|
76
76
|
|
77
|
-
# allow(
|
78
|
-
# Response.hash_keys_to_sym(MockResponse.responses[
|
77
|
+
# allow(MockCurrency).to receive(:response) {
|
78
|
+
# Response.hash_keys_to_sym(MockResponse.responses[MockCurrency])
|
79
79
|
# }
|
80
|
-
# expect(
|
80
|
+
# expect(MockCurrency.response.keys).to eq [:success, :currencies, :name, :url, :current_time]
|
81
81
|
|
82
|
-
# allow(
|
83
|
-
# #expect(
|
82
|
+
# allow(MockCurrency).to receive(:currencies)
|
83
|
+
# #expect(MockCurrency.response).to be_nil
|
84
84
|
# end
|
85
85
|
|
86
86
|
# it 'the client passes its fetched data to Response.response class method' do
|
87
87
|
# end
|
88
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(
|
90
|
-
#
|
91
|
-
# expect(
|
89
|
+
# MockResponse.responses(MockCurrency => fetched_currencies)
|
90
|
+
# MockCurrency.response
|
91
|
+
# expect(MockCurrency.currencies).not_to be_nil
|
92
92
|
# end
|
93
93
|
#end
|
94
94
|
|
@@ -96,27 +96,27 @@ module BackpackTF
|
|
96
96
|
stub_http_response_with('currencies.json')
|
97
97
|
Response.responses(:reset => :confirm)
|
98
98
|
expect(Response.responses).to be_empty
|
99
|
-
expect(
|
100
|
-
expect(
|
99
|
+
expect(Currency.response).to be_nil
|
100
|
+
expect(Currency.currencies).to be_nil
|
101
101
|
end
|
102
102
|
|
103
103
|
let(:fetched_currencies) {
|
104
104
|
bp.fetch(:currencies, {:compress => 1, :appid => 440})
|
105
105
|
}
|
106
106
|
|
107
|
-
context 'results on the
|
107
|
+
context 'results on the Currency.response method' do
|
108
108
|
it 'returns this Hash object' do
|
109
|
-
bp.update(
|
109
|
+
bp.update(Currency, fetched_currencies)
|
110
110
|
processed_json = Response.hash_keys_to_sym(fetched_currencies)
|
111
|
-
expect(
|
111
|
+
expect(Currency.response).to eq processed_json
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
context 'results on the
|
115
|
+
context 'results on the Currency.currencies method' do
|
116
116
|
it 'returns this Hash object' do
|
117
|
-
bp.update(
|
117
|
+
bp.update(Currency, fetched_currencies)
|
118
118
|
processed_json = Response.hash_keys_to_sym(fetched_currencies['currencies'])
|
119
|
-
expect(
|
119
|
+
expect(Currency.currencies).to eq processed_json
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module BackpackTF
|
4
|
-
describe
|
4
|
+
describe Currency do
|
5
5
|
let(:bp) { Client.new }
|
6
6
|
|
7
7
|
let(:json_obj) {
|
@@ -17,11 +17,11 @@ module BackpackTF
|
|
17
17
|
}
|
18
18
|
|
19
19
|
it 'responds to these methods' do
|
20
|
-
expect(
|
20
|
+
expect(described_class).to respond_to :responses, :response, :currencies, :interface, :hash_keys_to_sym
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'has these default attributes' do
|
24
|
-
expect(
|
24
|
+
expect(described_class.interface).to eq :IGetCurrencies
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '::responses' do
|
@@ -30,23 +30,23 @@ module BackpackTF
|
|
30
30
|
stub_http_response_with('currencies.json')
|
31
31
|
opts = { :app_id => 440, :compress => 1 }
|
32
32
|
fetched_currencies = bp.fetch(:currencies, opts)
|
33
|
-
Response.responses(
|
33
|
+
Response.responses(described_class.to_sym => fetched_currencies)
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'access from Response class' do
|
37
|
-
it '
|
38
|
-
expect(Response.responses[:'BackpackTF::
|
37
|
+
it 'Currency can be accessed by calling the key, Currency' do
|
38
|
+
expect(Response.responses[:'BackpackTF::Currency']).to eq json_obj
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
context 'access from
|
42
|
+
context 'access from Currency class' do
|
43
43
|
it 'can access response information via the class method, ::response' do
|
44
|
-
expect(
|
44
|
+
expect(described_class.response).to eq json_obj
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
it 'is the same as calling
|
49
|
-
expect(Response.responses[:'BackpackTF::
|
48
|
+
it 'is the same as calling Currency.response' do
|
49
|
+
expect(Response.responses[:'BackpackTF::Currency']).to eq Currency.response
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -55,18 +55,18 @@ module BackpackTF
|
|
55
55
|
stub_http_response_with('currencies.json')
|
56
56
|
opts = { :app_id => 440, :compress => 1 }
|
57
57
|
fetched_currencies = bp.fetch(:currencies, opts)
|
58
|
-
Response.responses(':BackpackTF::
|
58
|
+
Response.responses(':BackpackTF::Currency' => fetched_currencies)
|
59
59
|
end
|
60
60
|
it 'the response attribute should have these keys' do
|
61
|
-
expect(
|
61
|
+
expect(described_class.response.keys).to match_array [:success, :current_time, :currencies, :name, :url]
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'the keys of the response attribute should have these values' do
|
65
|
-
expect(
|
66
|
-
expect(
|
67
|
-
expect(
|
68
|
-
expect(
|
69
|
-
expect(
|
65
|
+
expect(described_class.response[:success]).to eq 1
|
66
|
+
expect(described_class.response[:message]).to eq nil
|
67
|
+
expect(described_class.response[:current_time]).to eq 1430784460
|
68
|
+
expect(described_class.response[:name]).to eq 'Team Fortress 2'
|
69
|
+
expect(described_class.response[:url]).to eq 'http://backpack.tf'
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
@@ -79,26 +79,26 @@ module BackpackTF
|
|
79
79
|
stub_http_response_with('currencies.json')
|
80
80
|
opts = { :app_id => 440, :compress => 1 }
|
81
81
|
fetched_currencies = bp.fetch(:currencies, opts)
|
82
|
-
Response.responses(:'BackpackTF::
|
82
|
+
Response.responses(:'BackpackTF::Currency' => fetched_currencies)
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'returns the fixture and sets to @@currencies variable' do
|
86
|
-
expect(
|
86
|
+
expect(described_class.currencies).not_to be_nil
|
87
87
|
end
|
88
88
|
|
89
89
|
it '@@currencies attribute should be a Hash object' do
|
90
|
-
expect(
|
90
|
+
expect(described_class.currencies).to be_instance_of Hash
|
91
91
|
end
|
92
92
|
|
93
93
|
it '@@currencies should have these keys' do
|
94
94
|
expected_keys = [:metal, :keys, :earbuds, :hat]
|
95
|
-
expect(
|
95
|
+
expect(described_class.currencies.keys).to match_array expected_keys
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
describe 'instance of
|
99
|
+
describe 'instance of Currency' do
|
100
100
|
|
101
|
-
let (:metal) {
|
101
|
+
let (:metal) { described_class.new(:metal, Currency.currencies[:metal]) }
|
102
102
|
|
103
103
|
it 'should respond to these methods' do
|
104
104
|
expect(metal).to respond_to(:quality, :priceindex, :single, :plural, :round, :craftable, :tradable, :defindex, :blanket)
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BackpackTF
|
4
|
+
describe Price do
|
5
|
+
|
6
|
+
let(:bp) { Client.new }
|
7
|
+
|
8
|
+
let(:json_obj) {
|
9
|
+
fixture = file_fixture('prices.json')
|
10
|
+
fixture = JSON.parse(fixture)['response']
|
11
|
+
Response.hash_keys_to_sym(fixture)
|
12
|
+
}
|
13
|
+
|
14
|
+
it 'responds to these inherited class methods' do
|
15
|
+
expect(described_class).to respond_to :responses, :to_sym, :interface, :hash_keys_to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has these default attributes' do
|
19
|
+
expect(described_class.interface).to eq :IGetPrices
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'raises an error when trying to instantiate this class' do
|
23
|
+
expect{described_class.new}.to raise_error RuntimeError
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '::responses' do
|
27
|
+
it "Responses class can access Price response by calling Price key" do
|
28
|
+
stub_http_response_with('prices.json')
|
29
|
+
fetched_prices = bp.fetch(:prices)
|
30
|
+
Response.responses(described_class.to_sym => fetched_prices)
|
31
|
+
expect(Response.responses[described_class.to_sym]).to eq json_obj
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '::response' do
|
36
|
+
before :each do
|
37
|
+
stub_http_response_with('prices.json')
|
38
|
+
fetched_prices = bp.fetch(:prices)
|
39
|
+
Response.responses(described_class.to_sym => fetched_prices)
|
40
|
+
end
|
41
|
+
|
42
|
+
after :all do
|
43
|
+
Response.responses(:reset => :confirm)
|
44
|
+
expect(Response.responses).to be_empty
|
45
|
+
expect(described_class.response).to be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'can access response information' do
|
49
|
+
expect(described_class.response).to eq json_obj
|
50
|
+
end
|
51
|
+
it "returns same info as the Response class calling Price key" do
|
52
|
+
expect(described_class.response).to eq Response.responses[described_class.to_sym]
|
53
|
+
end
|
54
|
+
it 'the response attribute should have these keys' do
|
55
|
+
expect(described_class.response.keys).to match_array [:success, :current_time, :raw_usd_value, :usd_currency, :usd_currency_index, :items]
|
56
|
+
end
|
57
|
+
it 'the keys of the response attribute should have these values' do
|
58
|
+
response = described_class.response
|
59
|
+
expect(response[:success]).to eq 1
|
60
|
+
expect(response[:message]).to eq nil
|
61
|
+
expect(response[:current_time]).to eq 1430785805
|
62
|
+
expect(response[:raw_usd_value]).to eq 0.115
|
63
|
+
expect(response[:usd_currency]).to eq 'metal'
|
64
|
+
expect(response[:usd_currency_index]).to eq 5002
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '::generate_items' do
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '::items' do
|
72
|
+
before :each do
|
73
|
+
stub_http_response_with('prices.json')
|
74
|
+
fetched_prices = bp.fetch(:prices)
|
75
|
+
bp.update(described_class, fetched_prices)
|
76
|
+
end
|
77
|
+
|
78
|
+
after :all do
|
79
|
+
Response.responses(:reset => :confirm)
|
80
|
+
expect(Response.responses).to be_empty
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'returns the fixture and sets to @@items variable' do
|
84
|
+
expect(described_class.items).not_to be_nil
|
85
|
+
end
|
86
|
+
|
87
|
+
context '@@items attribute' do
|
88
|
+
it 'should be a Hash object' do
|
89
|
+
expect(described_class.items).to be_instance_of Hash
|
90
|
+
end
|
91
|
+
xit 'should have this many keys' do
|
92
|
+
expect(described_class.items.keys.length).to be 1661
|
93
|
+
end
|
94
|
+
it 'each key should be a String' do
|
95
|
+
expect(described_class.items.keys).to all be_a String
|
96
|
+
end
|
97
|
+
it 'each value should be an Item' do
|
98
|
+
expect(described_class.items.values).to all be_an Item
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'using keys to generate Item objects' do
|
103
|
+
let(:random_key) { described_class.items.keys.sample }
|
104
|
+
let(:item) { described_class.items[random_key] }
|
105
|
+
|
106
|
+
it 'generates an Item object' do
|
107
|
+
expect(item).to be_instance_of Item
|
108
|
+
end
|
109
|
+
it 'the Item object responds to these methods' do
|
110
|
+
expect(item).to respond_to :item_name, :defindex, :prices
|
111
|
+
end
|
112
|
+
it 'uses the key to assign a value to the @item_name property of the Item' do
|
113
|
+
expect(random_key).to eq item.item_name
|
114
|
+
end
|
115
|
+
it 'passes itself to be stored in the @prices attribute of the Item object' do
|
116
|
+
expect(described_class.items[random_key].prices).to eq item.prices
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '::find_item_by_name' do
|
122
|
+
let(:item) { described_class.items['Kritzkrieg'] }
|
123
|
+
|
124
|
+
before :each do
|
125
|
+
stub_http_response_with('prices.json')
|
126
|
+
fetched_prices = bp.fetch(:prices)
|
127
|
+
|
128
|
+
bp.update(described_class, fetched_prices)
|
129
|
+
expect(described_class.items.values).to all be_an Item
|
130
|
+
end
|
131
|
+
|
132
|
+
after :each do
|
133
|
+
Response.responses(:reset => :confirm)
|
134
|
+
expect(Response.responses).to be_empty
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'returns Item object for the item matching the name' do
|
138
|
+
expect(described_class.find_item_by_name('Kritzkrieg')).to eq item
|
139
|
+
end
|
140
|
+
it 'can return picked attributes' do
|
141
|
+
expect(described_class.find_item_by_name('Kritzkrieg', :defindex)).to eq 35
|
142
|
+
end
|
143
|
+
it 'raises a KeyError if you ask for attribute it does not have' do
|
144
|
+
expect{described_class.find_item_by_name('Kritzkrieg', :foo)}.to raise_error KeyError
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '::random_item' do
|
149
|
+
before :each do
|
150
|
+
stub_http_response_with('prices.json')
|
151
|
+
fetched_prices = bp.fetch(:prices)
|
152
|
+
|
153
|
+
bp.update(described_class, fetched_prices)
|
154
|
+
expect(described_class.items.values).to all be_an Item
|
155
|
+
end
|
156
|
+
|
157
|
+
after :each do
|
158
|
+
Response.responses(:reset => :confirm)
|
159
|
+
expect(Response.responses).to be_empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns a name of an Item object' do
|
163
|
+
item = described_class.random_item
|
164
|
+
expect(described_class.items.keys.include? item).to be_truthy
|
165
|
+
end
|
166
|
+
context 'asking for prices property' do
|
167
|
+
let(:item_prices) { described_class.random_item :price }
|
168
|
+
|
169
|
+
it 'returns a Hash object where the keys are Strings' do
|
170
|
+
expect(item_prices.keys).to all be_a String
|
171
|
+
end
|
172
|
+
it 'returns a Hash object where values are ItemPrice objects' do
|
173
|
+
expect(item_prices.values).to all be_an ItemPrice
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '::generate_price_keys' do
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|