|  | 
| 8 | 8 |   let(:file) { 'https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt' } | 
| 9 | 9 |   let(:result) { double } | 
| 10 | 10 | 
 | 
| 11 |  | -  it 'executes task and returns result' do | 
| 12 |  | -    expect(ConvertApi.client).to( | 
| 13 |  | -      receive(:post).with('convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result) | 
| 14 |  | -    ) | 
|  | 11 | +  shared_examples 'successful task' do | 
|  | 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 | +      ) | 
| 15 | 16 | 
 | 
| 16 |  | -    expect(subject).to be_instance_of(ConvertApi::Result) | 
|  | 17 | +      expect(subject).to be_instance_of(ConvertApi::Result) | 
|  | 18 | +    end | 
| 17 | 19 |   end | 
| 18 | 20 | 
 | 
|  | 21 | +  it_behaves_like 'successful task' | 
|  | 22 | + | 
| 19 | 23 |   context 'with converter' do | 
| 20 | 24 |     let(:params) { { File: file, Converter: 'openoffice' } } | 
| 21 | 25 | 
 | 
|  | 
| 53 | 57 | 
 | 
| 54 | 58 |       expect(subject).to be_instance_of(ConvertApi::Result) | 
| 55 | 59 |     end | 
|  | 60 | + | 
|  | 61 | +    it 'executes task and returns result' do | 
|  | 62 | +      expect(ConvertApi.client).to( | 
|  | 63 | +        receive(:post).with('convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result) | 
|  | 64 | +      ) | 
|  | 65 | + | 
|  | 66 | +      expect(subject).to be_instance_of(ConvertApi::Result) | 
|  | 67 | +    end | 
|  | 68 | +  end | 
|  | 69 | + | 
|  | 70 | + | 
|  | 71 | +  describe 'async' do | 
|  | 72 | +    shared_examples 'successful async task' do | 
|  | 73 | +      it 'submits an async task and returns result' do | 
|  | 74 | +        expect(ConvertApi.client).to( | 
|  | 75 | +          receive(:post).with('async/convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result) | 
|  | 76 | +        ) | 
|  | 77 | + | 
|  | 78 | +        expect(subject).to be_instance_of(ConvertApi::AsyncResult) | 
|  | 79 | +      end | 
|  | 80 | +    end | 
|  | 81 | + | 
|  | 82 | +    context 'Async: false' do | 
|  | 83 | +      let(:params) { { Async: false, File: file } } | 
|  | 84 | + | 
|  | 85 | +      it_behaves_like 'successful task' | 
|  | 86 | +    end | 
|  | 87 | + | 
|  | 88 | +    context 'Async: "false"' do | 
|  | 89 | +      let(:params) { { Async: 'false', File: file } } | 
|  | 90 | + | 
|  | 91 | +      it_behaves_like 'successful task' | 
|  | 92 | +    end | 
|  | 93 | + | 
|  | 94 | +    context 'Async: true' do | 
|  | 95 | +      let(:params) { { Async: true, File: file } } | 
|  | 96 | + | 
|  | 97 | +      it_behaves_like 'successful async task' | 
|  | 98 | +    end | 
|  | 99 | + | 
|  | 100 | +    context 'Async: "true"' do | 
|  | 101 | +      let(:params) { { Async: "true", File: file } } | 
|  | 102 | + | 
|  | 103 | +      it_behaves_like 'successful async task' | 
|  | 104 | +    end | 
| 56 | 105 |   end | 
| 57 | 106 | end | 
0 commit comments