|
8 | 8 | let(:username) { 'chrishunt' } |
9 | 9 | let(:http_client) { double('HttpClient', get: response) } |
10 | 10 | let(:response_code) { 200 } |
11 | | - let(:parsed_response) { nil } |
| 11 | + let(:body) { [] } |
12 | 12 | let(:response) { |
13 | | - double('HTTParty::Response', { |
14 | | - code: response_code, |
15 | | - parsed_response: parsed_response |
| 13 | + double('Faraday::Response', { |
| 14 | + status: response_code, |
| 15 | + body: JSON.generate(body) |
16 | 16 | }) |
17 | 17 | } |
18 | 18 |
|
|
55 | 55 | end |
56 | 56 |
|
57 | 57 | context 'when the github user has keys' do |
58 | | - let(:parsed_response) {[ |
| 58 | + let(:body) {[ |
59 | 59 | { 'id' => 123, 'key' => 'abc123' }, |
60 | 60 | { 'id' => 456, 'key' => 'def456' } |
61 | 61 | ]} |
62 | 62 |
|
63 | 63 | it 'returns the keys' do |
64 | | - expected_keys = parsed_response.map do |entry| |
| 64 | + expected_keys = body.map do |entry| |
65 | 65 | Github::Auth::Key.new username, entry.fetch('key') |
66 | 66 | end |
67 | 67 |
|
|
70 | 70 | end |
71 | 71 |
|
72 | 72 | context 'when the github user does not have keys' do |
73 | | - let(:parsed_response) { [] } |
| 73 | + let(:body) { [] } |
74 | 74 |
|
75 | 75 | it 'returns an empty array' do |
76 | 76 | expect(subject.keys).to eq [] |
|
88 | 88 | end |
89 | 89 |
|
90 | 90 | context 'when there is an issue connecting to Github' do |
91 | | - [SocketError, Errno::ECONNREFUSED].each do |exception| |
92 | | - before { http_client.stub(:get).and_raise exception } |
| 91 | + before do |
| 92 | + http_client |
| 93 | + .stub(:get) |
| 94 | + .and_raise Faraday::Error::ConnectionFailed.new('Oops!') |
| 95 | + end |
93 | 96 |
|
94 | | - it 'raises a GithubUnavailableError' do |
95 | | - expect { |
96 | | - subject.keys |
97 | | - }.to raise_error Github::Auth::KeysClient::GithubUnavailableError |
98 | | - end |
| 97 | + it 'raises a GithubUnavailableError' do |
| 98 | + expect { |
| 99 | + subject.keys |
| 100 | + }.to raise_error Github::Auth::KeysClient::GithubUnavailableError |
99 | 101 | end |
100 | 102 | end |
101 | 103 | end |
|
0 commit comments