|
2 | 2 |
|
3 | 3 | RSpec.describe Fax do |
4 | 4 | let(:test_file) { File.open test_file_path } |
5 | | - let(:test_file_path) { File.expand_path(File.join('..', '..', 'support', 'files', 'test.pdf'), __FILE__) } |
6 | | - let(:test_recipient_number) { ENV.fetch('TEST_RECIPIENT_NUMBER', '+15558675309') } |
| 5 | + let(:test_file_path) { File.join File.expand_path('..', __dir__), 'support', 'files', 'test.pdf' } |
| 6 | + let(:test_recipient_number) { TEST_NUMBER } |
7 | 7 |
|
8 | | - describe 'creating a fax' do |
| 8 | + describe 'creating a fax', vcr: 'fax/create' do |
9 | 9 | let(:action) { Fax.create params } |
10 | 10 | let(:params) { {to: test_recipient_number, file: test_file} } |
11 | 11 |
|
12 | | - around(:each) do |example| |
13 | | - VCR.use_cassette('resources/fax/create') do |
14 | | - example.run |
15 | | - end |
16 | | - end |
17 | | - |
18 | 12 | it 'makes the request to Phaxio' do |
19 | 13 | expect_api_request :post, 'faxes', to: test_recipient_number, file: test_file |
20 | 14 | action |
|
27 | 21 | end |
28 | 22 | end |
29 | 23 |
|
30 | | - describe 'retrieving a fax' do |
| 24 | + describe 'retrieving a fax', vcr: 'fax/get' do |
31 | 25 | let(:action) { Fax.get fax_id, params } |
32 | | - let!(:fax_id) { |
33 | | - VCR.use_cassette('resources/fax/create_for_get') do |
34 | | - Phaxio::Fax.create(to: test_recipient_number, file: test_file).id |
35 | | - end |
36 | | - } |
| 26 | + let(:fax_id) { Fax.create(to: test_recipient_number, file: test_file).id } |
37 | 27 | let(:params) { {} } |
38 | 28 |
|
39 | | - around(:each) do |example| |
40 | | - VCR.use_cassette('resources/fax/get') do |
41 | | - example.run |
42 | | - end |
43 | | - end |
44 | | - |
45 | 29 | it 'makes the request to Phaxio' do |
46 | 30 | expect_api_request :get, "faxes/#{fax_id}", params |
47 | 31 | action |
|
54 | 38 | end |
55 | 39 | end |
56 | 40 |
|
57 | | - describe 'cancelling a fax' do |
| 41 | + describe 'cancelling a fax', vcr: 'fax/cancel' do |
58 | 42 | let(:action) { Fax.cancel fax_id, params } |
| 43 | + let(:fax_id) { Fax.create(to: test_recipient_number, file: test_file).id } |
59 | 44 | let(:params) { {} } |
60 | | - let!(:fax_id) { |
61 | | - VCR.use_cassette('resources/fax/create_for_cancel') do |
62 | | - Phaxio::Fax.create(to: test_recipient_number, file: test_file).id |
63 | | - end |
64 | | - } |
65 | | - |
66 | | - around(:each) do |example| |
67 | | - VCR.use_cassette('resources/fax/cancel') do |
68 | | - example.run |
69 | | - end |
70 | | - end |
71 | 45 |
|
72 | 46 | it 'makes the request to Phaxio' do |
73 | 47 | expect_api_request :post, "faxes/#{fax_id}/cancel", params |
|
81 | 55 | end |
82 | 56 | end |
83 | 57 |
|
84 | | - describe 'listing faxes' do |
| 58 | + describe 'listing faxes', vcr: 'fax/list' do |
85 | 59 | let(:action) { Fax.list params } |
86 | 60 | let(:params) { {created_before: time} } |
87 | 61 | let(:time) { Time.new 2017, 10, 28, 0, 17, 0, 0 } |
88 | 62 |
|
89 | | - around do |example| |
90 | | - VCR.use_cassette('resources/fax/list') do |
91 | | - example.run |
92 | | - end |
93 | | - end |
94 | | - |
95 | 63 | it 'sends the request to phaxio' do |
96 | 64 | expect_api_request :get, 'faxes', params |
97 | 65 | action |
|
103 | 71 | end |
104 | 72 | end |
105 | 73 |
|
106 | | - describe 'resending a fax' do |
| 74 | + describe 'resending a fax', vcr: 'fax/resend' do |
107 | 75 | let(:action) { Fax.resend fax_id, params } |
108 | | - let!(:fax_id) { |
109 | | - VCR.use_cassette('resources/fax/create_for_resend') do |
110 | | - Phaxio::Fax.create(to: test_recipient_number, file: test_file).id |
111 | | - end |
| 76 | + let(:fax_id) { |
| 77 | + fax_id = Fax.create(to: test_recipient_number, file: test_file).id |
| 78 | + sleep 30 if VCR.current_cassette.recording? |
| 79 | + fax_id |
112 | 80 | } |
113 | 81 | let(:params) { {} } |
114 | 82 |
|
115 | | - around do |example| |
116 | | - VCR.use_cassette('resources/fax/resend') do |
117 | | - example.run |
118 | | - end |
119 | | - end |
120 | | - |
121 | 83 | it 'makes the request to Phaxio' do |
122 | 84 | expect_api_request :post, "faxes/#{fax_id}/resend", params |
123 | 85 | action |
|
130 | 92 | end |
131 | 93 | end |
132 | 94 |
|
133 | | - describe 'deleting a fax' do |
| 95 | + describe 'deleting a fax', vcr: 'fax/delete' do |
134 | 96 | let(:action) { Fax.delete fax_id, params } |
135 | | - let!(:fax_id) { |
136 | | - VCR.use_cassette('resources/fax/create_for_delete') do |
137 | | - Phaxio::Fax.create(to: test_recipient_number, file: test_file).id |
138 | | - end |
| 97 | + let(:fax_id) { |
| 98 | + fax_id = Fax.create(to: test_recipient_number, file: test_file).id |
| 99 | + sleep 30 if VCR.current_cassette.recording? |
| 100 | + fax_id |
139 | 101 | } |
140 | 102 | let(:params) { {} } |
141 | 103 |
|
142 | | - around do |example| |
143 | | - VCR.use_cassette('resources/fax/delete') do |
144 | | - example.run |
145 | | - end |
146 | | - end |
147 | | - |
148 | 104 | it 'makes the request to Phaxio' do |
149 | 105 | expect_api_request :delete, "faxes/#{fax_id}", params |
150 | 106 | action |
|
156 | 112 | end |
157 | 113 | end |
158 | 114 |
|
159 | | - describe 'deleting a fax file' do |
| 115 | + describe 'deleting a fax file', vcr: 'fax/delete_file' do |
160 | 116 | let(:action) { Fax.delete_file fax_id, params } |
161 | | - let!(:fax_id) { |
162 | | - VCR.use_cassette('resources/fax/create_for_delete_file') do |
163 | | - Phaxio::Fax.create(to: test_recipient_number, file: test_file).id |
164 | | - end |
| 117 | + let(:fax_id) { |
| 118 | + fax_id = Fax.create(to: test_recipient_number, file: test_file).id |
| 119 | + sleep 30 if VCR.current_cassette.recording? |
| 120 | + fax_id |
165 | 121 | } |
166 | 122 | let(:params) { {} } |
167 | 123 |
|
168 | | - around do |example| |
169 | | - VCR.use_cassette('resources/fax/delete_file') do |
170 | | - example.run |
171 | | - end |
172 | | - end |
173 | | - |
174 | 124 | it 'makes the request to Phaxio' do |
175 | 125 | expect_api_request :delete, "faxes/#{fax_id}/file", params |
176 | 126 | action |
|
182 | 132 | end |
183 | 133 | end |
184 | 134 |
|
185 | | - describe 'downloading a fax file' do |
| 135 | + describe 'downloading a fax file', vcr: 'fax/file' do |
186 | 136 | let(:action) { Fax.file fax_id, params } |
187 | | - let!(:fax_id) { |
188 | | - VCR.use_cassette('resources/fax/create_for_download_file') do |
189 | | - Phaxio::Fax.create(to: test_recipient_number, file: test_file).id |
190 | | - end |
| 137 | + let(:fax_id) { |
| 138 | + fax_id = Fax.create(to: test_recipient_number, file: test_file).id |
| 139 | + sleep 30 if VCR.current_cassette.recording? |
| 140 | + fax_id |
191 | 141 | } |
192 | 142 | let(:params) { {} } |
193 | 143 |
|
194 | | - around do |example| |
195 | | - VCR.use_cassette('resources/fax/file') do |
196 | | - example.run |
197 | | - end |
198 | | - end |
199 | | - |
200 | 144 | it 'makes the request to phaxio' do |
201 | 145 | expect_api_request :get, "faxes/#{fax_id}/file", params |
202 | 146 | action |
|
208 | 152 | end |
209 | 153 | end |
210 | 154 |
|
211 | | - describe 'receiving a test fax' do |
| 155 | + describe 'receiving a test fax', vcr: 'fax/test_receive' do |
212 | 156 | let(:action) { Fax.test_receive params } |
213 | 157 | let(:params) { {file: test_file} } |
214 | 158 |
|
215 | | - around do |example| |
216 | | - VCR.use_cassette('resources/fax/test_receive') do |
217 | | - example.run |
218 | | - end |
219 | | - end |
220 | | - |
221 | 159 | it 'makes the request to Phaxio' do |
222 | 160 | expect_api_request :post, 'faxes', {file: test_file, direction: 'received'} |
223 | 161 | action |
|
229 | 167 | end |
230 | 168 | end |
231 | 169 |
|
232 | | - describe Fax::Reference do |
233 | | - let!(:fax_id) { |
234 | | - VCR.use_cassette('resources/fax/create_for_reference') do |
235 | | - Phaxio::Fax.create(to: test_recipient_number, file: test_file).id |
236 | | - end |
237 | | - } |
| 170 | + describe Fax::Reference, vcr: 'fax/reference' do |
| 171 | + let(:fax_id) { Fax.create(to: test_recipient_number, file: test_file).id } |
238 | 172 |
|
239 | 173 | it 'gets the full fax' do |
240 | | - VCR.use_cassette('resources/fax/reference') do |
241 | | - reference = Fax::Reference.new fax_id |
242 | | - result = reference.get |
243 | | - expect(result).to be_a(Fax) |
244 | | - expect(result.id).to eq(fax_id) |
245 | | - end |
| 174 | + reference = Fax::Reference.new fax_id |
| 175 | + result = reference.get |
| 176 | + expect(result).to be_a(Fax) |
| 177 | + expect(result.id).to eq(fax_id) |
246 | 178 | end |
247 | 179 | end |
248 | 180 | end |
0 commit comments