|
9 | 9 |
|
10 | 10 | let(:result) { double } |
11 | 11 |
|
12 | | - it 'executes task and returns result' do |
13 | | - expect(ConvertApi.client).to( |
14 | | - receive(:post).with('convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result) |
15 | | - ) |
| 12 | + shared_examples 'successful task' do |
| 13 | + it 'executes task and returns result' do |
| 14 | + expect(ConvertApi.client).to( |
| 15 | + receive(:post).with('convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result) |
| 16 | + ) |
16 | 17 |
|
17 | | - expect(subject).to be_instance_of(ConvertApi::Result) |
| 18 | + expect(subject).to be_instance_of(ConvertApi::Result) |
| 19 | + end |
18 | 20 | end |
19 | 21 |
|
| 22 | + it_behaves_like 'successful task' |
| 23 | + |
20 | 24 | describe 'async' do |
21 | | - let(:params) { { Async: true, File: 'https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt' } } |
| 25 | + shared_examples 'successful async task' do |
| 26 | + it 'submits an async task and returns result' do |
| 27 | + expect(ConvertApi.client).to( |
| 28 | + receive(:post).with('async/convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result) |
| 29 | + ) |
22 | 30 |
|
23 | | - it 'submits an async task and returns result' do |
24 | | - expect(ConvertApi.client).to( |
25 | | - receive(:post).with('async/convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result) |
26 | | - ) |
| 31 | + expect(subject).to be_instance_of(ConvertApi::AsyncResult) |
| 32 | + end |
| 33 | + end |
27 | 34 |
|
28 | | - expect(subject).to be_instance_of(ConvertApi::Result) |
| 35 | + context 'Async: false' do |
| 36 | + let(:params) { { Async: false, File: 'https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt' } } |
| 37 | + |
| 38 | + it_behaves_like 'successful task' |
| 39 | + end |
| 40 | + |
| 41 | + context 'Async: "false"' do |
| 42 | + let(:params) { { Async: 'false', File: 'https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt' } } |
| 43 | + |
| 44 | + it_behaves_like 'successful task' |
| 45 | + end |
| 46 | + |
| 47 | + context 'Async: true' do |
| 48 | + let(:params) { { Async: true, File: 'https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt' } } |
| 49 | + |
| 50 | + it_behaves_like 'successful async task' |
| 51 | + end |
| 52 | + |
| 53 | + context 'Async: "true"' do |
| 54 | + let(:params) { { Async: "true", File: 'https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt' } } |
| 55 | + |
| 56 | + it_behaves_like 'successful async task' |
29 | 57 | end |
30 | 58 | end |
31 | 59 | end |
|
0 commit comments