|
2 | 2 |
|
3 | 3 | describe IEX::Resources::Quote do
|
4 | 4 | include_context 'client'
|
5 |
| - context 'known symbol', vcr: { cassette_name: 'quote/msft' } do |
6 |
| - subject do |
7 |
| - client.quote('MSFT') |
8 |
| - end |
9 |
| - it 'retrieves a quote' do |
10 |
| - expect(subject.symbol).to eq 'MSFT' |
11 |
| - expect(subject.company_name).to eq 'Microsoft Corp.' |
12 |
| - expect(subject.market_cap).to eq 915_754_985_600 |
13 |
| - end |
14 |
| - it 'coerces numbers' do |
15 |
| - expect(subject.latest_price).to eq 119.36 |
16 |
| - expect(subject.change).to eq(-0.61) |
17 |
| - expect(subject.week_52_high).to eq 120.82 |
18 |
| - expect(subject.week_52_low).to eq 87.73 |
19 |
| - expect(subject.change_percent).to eq(-0.00508) |
20 |
| - expect(subject.change_percent_s).to eq '-0.51%' |
21 |
| - expect(subject.extended_change_percent).to eq(-0.00008) |
22 |
| - expect(subject.extended_change_percent_s).to eq '-0.01%' |
| 5 | + |
| 6 | + describe '#quote' do |
| 7 | + context 'known symbol', vcr: { cassette_name: 'quote/msft' } do |
| 8 | + subject do |
| 9 | + client.quote('MSFT') |
| 10 | + end |
| 11 | + it 'retrieves a quote' do |
| 12 | + expect(subject.symbol).to eq 'MSFT' |
| 13 | + expect(subject.company_name).to eq 'Microsoft Corp.' |
| 14 | + expect(subject.market_cap).to eq 915_754_985_600 |
| 15 | + end |
| 16 | + it 'coerces numbers' do |
| 17 | + expect(subject.latest_price).to eq 119.36 |
| 18 | + expect(subject.change).to eq(-0.61) |
| 19 | + expect(subject.week_52_high).to eq 120.82 |
| 20 | + expect(subject.week_52_low).to eq 87.73 |
| 21 | + expect(subject.change_percent).to eq(-0.00508) |
| 22 | + expect(subject.change_percent_s).to eq '-0.51%' |
| 23 | + expect(subject.extended_change_percent).to eq(-0.00008) |
| 24 | + expect(subject.extended_change_percent_s).to eq '-0.01%' |
| 25 | + end |
| 26 | + it 'coerces times' do |
| 27 | + expect(subject.latest_update).to eq 1_554_408_000_193 |
| 28 | + expect(subject.latest_update_t).to eq Time.at(1_554_408_000) |
| 29 | + expect(subject.iex_last_updated).to eq 1_554_407_999_529 |
| 30 | + expect(subject.iex_last_updated_t).to eq Time.at(1_554_407_999) |
| 31 | + end |
23 | 32 | end
|
24 |
| - it 'coerces times' do |
25 |
| - expect(subject.latest_update).to eq 1_554_408_000_193 |
26 |
| - expect(subject.latest_update_t).to eq Time.at(1_554_408_000) |
27 |
| - expect(subject.iex_last_updated).to eq 1_554_407_999_529 |
28 |
| - expect(subject.iex_last_updated_t).to eq Time.at(1_554_407_999) |
| 33 | + |
| 34 | + context 'invalid symbol', vcr: { cassette_name: 'quote/invalid' } do |
| 35 | + subject do |
| 36 | + client.quote('INVALID') |
| 37 | + end |
| 38 | + it 'fails with SymbolNotFoundError' do |
| 39 | + expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found' |
| 40 | + end |
29 | 41 | end
|
30 | 42 | end
|
31 | 43 |
|
32 |
| - context 'invalid symbol', vcr: { cassette_name: 'quote/invalid' } do |
| 44 | + describe '#stream_quote' do |
33 | 45 | subject do
|
34 |
| - client.quote('INVALID') |
| 46 | + quotes = [] |
| 47 | + client.stream_quote('SPY', interval: '5Second') do |quote| |
| 48 | + quotes << quote |
| 49 | + end |
| 50 | + |
| 51 | + quotes.first |
35 | 52 | end
|
36 |
| - it 'fails with SymbolNotFoundError' do |
37 |
| - expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found' |
| 53 | + |
| 54 | + it 'retrieves a quote', vcr: { cassette_name: 'stream_quote/spy' } do |
| 55 | + expect(subject.symbol).to eq('SPY') |
| 56 | + expect(subject.close).to eq(433.63) |
38 | 57 | end
|
39 | 58 | end
|
40 | 59 | end
|
0 commit comments