|
10 | 10 | )
|
11 | 11 | end
|
12 | 12 |
|
13 |
| - describe '(integrations tests)', integration: true do |
| 13 | + describe '(integrations tests)', :integration do |
14 | 14 | before(:all) do
|
15 | 15 | WebMock.disable!
|
16 | 16 | end
|
|
73 | 73 | 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=fr'
|
74 | 74 | end
|
75 | 75 |
|
76 |
| - before do |
77 |
| - @stub = stub_request(:post, translate_url).with( |
| 76 | + let!(:stub) do |
| 77 | + stub_request(:post, translate_url).with( |
78 | 78 | body: '[{"Text":"First sentence"},{"Text":"Second sentence"}]'
|
79 | 79 | ).to_return(
|
80 | 80 | body: load_response('translation_1')
|
|
88 | 88 |
|
89 | 89 | it 'calls the service' do
|
90 | 90 | results
|
91 |
| - expect(@stub).to have_been_requested |
| 91 | + expect(stub).to have_been_requested |
92 | 92 | end
|
93 | 93 | end
|
94 | 94 |
|
95 | 95 | context 'with Types::Sentence' do
|
96 | 96 | it 'calls the service' do
|
97 | 97 | results
|
98 |
| - expect(@stub).to have_been_requested |
| 98 | + expect(stub).to have_been_requested |
99 | 99 | end
|
100 | 100 | end
|
101 | 101 |
|
|
110 | 110 | it 'returns the detected language' do
|
111 | 111 | expect(results.map(&:detected_language)).to eq %i[en en]
|
112 | 112 | end
|
| 113 | + |
| 114 | + context 'with a unauthorized request' do |
| 115 | + before do |
| 116 | + stub_request(:post, translate_url).to_return( |
| 117 | + status: 401 |
| 118 | + ) |
| 119 | + end |
| 120 | + |
| 121 | + it 'raises a NetError' do |
| 122 | + expect { results }.to raise_error(TranslatorText::NetError) |
| 123 | + end |
| 124 | + end |
113 | 125 | end
|
114 | 126 |
|
115 | 127 | describe '#detect' do
|
|
128 | 140 | 'https://api.cognitive.microsofttranslator.com/detect?api-version=3.0'
|
129 | 141 | end
|
130 | 142 |
|
131 |
| - before do |
132 |
| - @stub = stub_request(:post, detect_url).with( |
| 143 | + let!(:stub) do |
| 144 | + stub_request(:post, detect_url).with( |
133 | 145 | body: '[{"Text":"First sentence"},{"Text":"Second sentence"}]'
|
134 | 146 | ).to_return(
|
135 | 147 | body: load_response('detection_1')
|
|
143 | 155 |
|
144 | 156 | it 'calls the service' do
|
145 | 157 | results
|
146 |
| - expect(@stub).to have_been_requested |
| 158 | + expect(stub).to have_been_requested |
147 | 159 | end
|
148 | 160 | end
|
149 | 161 |
|
150 | 162 | context 'with Types::Sentence' do
|
151 | 163 | it 'calls the service' do
|
152 | 164 | results
|
153 |
| - expect(@stub).to have_been_requested |
| 165 | + expect(stub).to have_been_requested |
154 | 166 | end
|
155 | 167 | end
|
156 | 168 |
|
|
161 | 173 | it 'returns the detected language' do
|
162 | 174 | expect(results.map(&:language)).to eq %i[en en]
|
163 | 175 | end
|
| 176 | + |
| 177 | + context 'with a unauthorized request' do |
| 178 | + before do |
| 179 | + stub_request(:post, detect_url).to_return( |
| 180 | + status: 401 |
| 181 | + ) |
| 182 | + end |
| 183 | + |
| 184 | + it 'raises a NetError' do |
| 185 | + expect { results }.to raise_error(TranslatorText::NetError) |
| 186 | + end |
| 187 | + end |
164 | 188 | end
|
165 | 189 | end
|
0 commit comments