assembly-image 1.7.7 → 1.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/image_spec.rb CHANGED
@@ -2,274 +2,278 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # rubocop:disable Metrics/BlockLength
6
- describe Assembly::Image do
7
- it 'does not run if no input file is passed in' do
8
- @ai = Assembly::Image.new('')
9
- expect{ @ai.create_jp2 }.to raise_error
10
- end
5
+ RSpec.describe Assembly::Image do
6
+ let(:ai) { described_class.new(input_path) }
7
+ let(:input_path) { TEST_TIF_INPUT_FILE }
11
8
 
12
- it 'indicates the default jp2 filename' do
13
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
14
- expect(@ai.jp2_filename).to eq TEST_TIF_INPUT_FILE.gsub('.tif', '.jp2')
9
+ after do
10
+ # after each test, empty out the input and output test directories
11
+ remove_files(TEST_INPUT_DIR)
12
+ remove_files(TEST_OUTPUT_DIR)
15
13
  end
16
14
 
17
- it 'indicates the default jp2 filename' do
18
- @ai = Assembly::Image.new('/path/to/a/file_with_no_extension')
19
- expect(@ai.jp2_filename).to eq '/path/to/a/file_with_no_extension.jp2'
20
- end
15
+ describe '#jp2_filename' do
16
+ it 'indicates the default jp2 filename' do
17
+ expect(ai.jp2_filename).to eq TEST_TIF_INPUT_FILE.gsub('.tif', '.jp2')
18
+ end
21
19
 
22
- it 'indicates the default DPG jp2 filename' do
23
- @ai = Assembly::Image.new(TEST_DPG_TIF_INPUT_FILE)
24
- expect(@ai.dpg_jp2_filename).to eq TEST_DPG_TIF_INPUT_FILE.gsub('.tif', '.jp2').gsub('_00_', '_05_')
25
- end
20
+ context 'with a file with no extension' do
21
+ let(:input_path) { '/path/to/a/file_with_no_extension' }
26
22
 
27
- it 'indicates the default jp2 filename' do
28
- @ai = Assembly::Image.new('/path/to/a/file_with_no_00_extension')
29
- expect(@ai.dpg_jp2_filename).to eq '/path/to/a/file_with_no_05_extension.jp2'
23
+ it 'indicates the default jp2 filename' do
24
+ expect(ai.jp2_filename).to eq '/path/to/a/file_with_no_extension.jp2'
25
+ end
26
+ end
30
27
  end
31
28
 
32
- # it 'creates the jp2 without a temp file when given an uncompressed RGB tif' do
33
- # generate_test_image(TEST_TIF_INPUT_FILE)
34
- # expect(File).to exist TEST_TIF_INPUT_FILE
35
- # expect(File).to_not exist TEST_JP2_OUTPUT_FILE
36
- # @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
37
- # result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
38
- # # Indicates a temp tiff was not created.
39
- # expect(@ai.tmp_path).to be_nil
40
- # expect(result).to be_a_kind_of Assembly::Image
41
- # expect(result.path).to eq TEST_JP2_OUTPUT_FILE
42
- # expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
43
- # expect(result.exif.colorspace).to eq 'sRGB'
44
- # @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
45
- # expect(@jp2.height).to eq 100
46
- # expect(@jp2.width).to eq 100
47
- # end
48
-
49
- it 'creates the jp2 with a temp file when given an LZW compressed RGB tif' do
50
- generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw')
51
- expect(File).to exist TEST_TIF_INPUT_FILE
52
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
53
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
54
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
55
- # Indicates a temp tiff was not created.
56
- expect(@ai.tmp_path).to_not be_nil
57
- expect(result).to be_a_kind_of Assembly::Image
58
- expect(result.path).to eq TEST_JP2_OUTPUT_FILE
59
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
60
- expect(result.exif.colorspace).to eq 'sRGB'
61
- @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
62
- expect(@jp2.height).to eq 100
63
- expect(@jp2.width).to eq 100
64
- end
29
+ describe '#dpg_jp2_filename' do
30
+ context 'with a dpg tiff file' do
31
+ let(:input_path) { TEST_DPG_TIF_INPUT_FILE }
65
32
 
66
- it 'creates the jp2 with a temp file when given an uncompressed compressed RGB tif with more than 4GB of image data' do
67
- skip 'This test will create a 4GB test image and a 4GB temporary image, so skipping by default.'
68
- generate_test_image(TEST_TIF_INPUT_FILE, compress: 'none', width: '37838', height: '37838')
69
- expect(File).to exist TEST_TIF_INPUT_FILE
70
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
71
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
72
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
73
- expect(@ai.tmp_path).to_not be_nil
74
- expect(result).to be_a_kind_of Assembly::Image
75
- expect(result.path).to eq TEST_JP2_OUTPUT_FILE
76
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
77
- expect(result.exif.colorspace).to eq 'sRGB'
78
- @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
79
- expect(@jp2.height).to eq 37_838
80
- expect(@jp2.width).to eq 37_838
81
- end
33
+ it 'indicates the default DPG jp2 filename' do
34
+ expect(ai.dpg_jp2_filename).to eq TEST_DPG_TIF_INPUT_FILE.gsub('.tif', '.jp2').gsub('_00_', '_05_')
35
+ end
36
+ end
82
37
 
83
- it 'creates the jp2 with a temp file when given an LZW compressed RGB tif with more than 4GB of image data' do
84
- skip 'This test will create a 4GB temporary image, so skipping by default.'
85
- generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw', width: '37838', height: '37838')
86
- expect(File).to exist TEST_TIF_INPUT_FILE
87
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
88
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
89
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
90
- expect(@ai.tmp_path).to_not be_nil
91
- expect(result).to be_a_kind_of Assembly::Image
92
- expect(result.path).to eq TEST_JP2_OUTPUT_FILE
93
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
94
- expect(result.exif.colorspace).to eq 'sRGB'
95
- @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
96
- expect(@jp2.height).to eq 37_838
97
- expect(@jp2.width).to eq 37_838
98
- end
38
+ context 'with a file with no extension' do
39
+ let(:input_path) { '/path/to/a/file_with_no_00_extension' }
99
40
 
100
- it 'creates grayscale jp2 when given a bitonal tif' do
101
- # Need to force group4 compression to get ImageMagick to create bitonal tiff
102
- generate_test_image(TEST_TIF_INPUT_FILE, image_type: 'Bilevel', compress: 'group4')
103
- expect(File).to exist TEST_TIF_INPUT_FILE
104
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
105
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
106
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
107
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
108
- expect(result.exif.colorspace).to eq 'Grayscale'
41
+ it 'indicates the default jp2 filename' do
42
+ expect(ai.dpg_jp2_filename).to eq '/path/to/a/file_with_no_05_extension.jp2'
43
+ end
44
+ end
109
45
  end
110
46
 
111
- it 'creates color jp2 when given a color tif but bitonal image data (1 channels and 1 bits per pixel)' do
112
- generate_test_image(TEST_TIF_INPUT_FILE, color: 'Bilevel', image_type: 'TrueColor', profile: '')
113
- expect(File).to exist TEST_TIF_INPUT_FILE
114
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
115
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
116
- expect(@ai).to_not have_color_profile
117
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
118
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
119
- expect(result.exif.colorspace).to eq 'sRGB'
120
- end
47
+ describe '#create_jp2' do
48
+ context 'when input path is blank' do
49
+ let(:input_path) { '' }
121
50
 
122
- it 'creates grayscale jp2 when given a graycale tif but with bitonal image data (1 channel and 1 bits per pixel)' do
123
- generate_test_image(TEST_TIF_INPUT_FILE, color: 'Bilevel', image_type: 'Grayscale', profile: '')
124
- expect(File).to exist TEST_TIF_INPUT_FILE
125
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
126
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
127
- # Indicates a temp tiff was not created.
128
- expect(@ai.tmp_path).to be_nil
129
- expect(@ai).to_not have_color_profile
130
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
131
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
132
- expect(result.exif.colorspace).to eq 'Grayscale'
133
- end
51
+ it 'does not run if no input file is passed in' do
52
+ expect { ai.create_jp2 }.to raise_error
53
+ end
54
+ end
134
55
 
135
- it 'creates color jp2 when given a color tif but with greyscale image data (1 channel and 8 bits per pixel)' do
136
- generate_test_image(TEST_TIF_INPUT_FILE, color: 'Grayscale', image_type: 'TrueColor', profile: '')
137
- expect(File).to exist TEST_TIF_INPUT_FILE
138
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
139
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
140
- # Indicates a temp tiff was not created.
141
- expect(@ai.tmp_path).to be_nil
142
- expect(@ai).to_not have_color_profile
143
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
144
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
145
- expect(result.exif.colorspace).to eq 'sRGB'
146
- end
56
+ context 'when given an uncompressed compressed RGB tif with more than 4GB of image data', skip: 'This test will create a 4GB test image and a 4GB temporary image, so skipping by default.' do
57
+ before do
58
+ generate_test_image(TEST_TIF_INPUT_FILE, compress: 'none', width: '37838', height: '37838')
59
+ end
147
60
 
148
- it 'creates a jp2 when the source image has no profile' do
149
- generate_test_image(TEST_TIF_INPUT_FILE, profile: '') # generate a test input with no profile
150
- expect(File).to exist TEST_TIF_INPUT_FILE
151
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
152
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
153
- # Indicates a temp tiff was not created.
154
- expect(@ai.tmp_path).to be_nil
155
- expect(@ai).to_not have_color_profile
156
- expect(@ai).to be_a_valid_image
157
- expect(@ai).to be_jp2able
158
- @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
159
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
160
- end
61
+ it 'creates the jp2 with a temp file' do
62
+ expect(File).to exist TEST_TIF_INPUT_FILE
63
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
64
+ result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
65
+ expect(ai.tmp_path).not_to be_nil
66
+ expect(result).to be_a_kind_of described_class
67
+ expect(result.path).to eq TEST_JP2_OUTPUT_FILE
68
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
69
+ expect(result.exif.colorspace).to eq 'sRGB'
70
+ jp2 = described_class.new(TEST_JP2_OUTPUT_FILE)
71
+ expect(jp2.height).to eq 37_838
72
+ expect(jp2.width).to eq 37_838
73
+ end
74
+ end
161
75
 
162
- it "does not run if the output file exists and you don't allow overwriting" do
163
- generate_test_image(TEST_TIF_INPUT_FILE)
164
- generate_test_image(TEST_JP2_OUTPUT_FILE)
165
- expect(File).to exist TEST_TIF_INPUT_FILE
166
- expect(File).to exist TEST_JP2_OUTPUT_FILE
167
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
168
- expect{ @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE) }.to raise_error(SecurityError)
169
- end
76
+ context 'when given an LZW compressed RGB tif with more than 4GB of image data', skip: 'This test will create a 4GB temporary image, so skipping by default.' do
77
+ before do
78
+ generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw', width: '37838', height: '37838')
79
+ end
170
80
 
171
- it 'gets the correct image height and width' do
172
- generate_test_image(TEST_TIF_INPUT_FILE)
173
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
174
- expect(@ai.height).to eq 100
175
- expect(@ai.width).to eq 100
176
- end
81
+ it 'creates the jp2 with a temp file' do
82
+ expect(File).to exist TEST_TIF_INPUT_FILE
83
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
84
+ result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
85
+ expect(ai.tmp_path).not_to be_nil
86
+ expect(result).to be_a_kind_of described_class
87
+ expect(result.path).to eq TEST_JP2_OUTPUT_FILE
88
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
89
+ expect(result.exif.colorspace).to eq 'sRGB'
90
+ jp2 = described_class.new(TEST_JP2_OUTPUT_FILE)
91
+ expect(jp2.height).to eq 37_838
92
+ expect(jp2.width).to eq 37_838
93
+ end
94
+ end
177
95
 
178
- it 'does not run if the input file is a jp2' do
179
- generate_test_image(TEST_TIF_INPUT_FILE, profile: '') # generate a test input with no profile
180
- expect(File).to exist TEST_TIF_INPUT_FILE
181
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
182
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
183
- # Indicates a temp tiff was not created.
184
- expect(@ai.tmp_path).to be_nil
185
- expect(@ai).to_not have_color_profile
186
- expect(@ai).to be_a_valid_image
187
- expect(@ai).to be_jp2able
188
- @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
189
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
190
- @ai = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
191
- expect(@ai).to be_valid_image
192
- expect(@ai).to_not be_jp2able
193
- expect { @ai.create_jp2 }.to raise_error
194
- end
96
+ context 'when given a bitonal tif' do
97
+ before do
98
+ # Need to force group4 compression to get ImageMagick to create bitonal tiff
99
+ generate_test_image(TEST_TIF_INPUT_FILE, image_type: 'Bilevel', compress: 'group4')
100
+ end
195
101
 
196
- it 'runs if you specify a bogus output profile, because this is not currently an option' do
197
- generate_test_image(TEST_TIF_INPUT_FILE)
198
- expect(File).to exist TEST_TIF_INPUT_FILE
199
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
200
- result = @ai.create_jp2(output_profile: 'bogusness')
201
- expect(result).to be_a_kind_of Assembly::Image
202
- expect(result.path).to eq TEST_JP2_INPUT_FILE
203
- expect(TEST_JP2_INPUT_FILE).to be_a_jp2
204
- expect(result.exif.colorspace).to eq 'sRGB'
205
- end
102
+ it 'creates grayscale jp2' do
103
+ expect(File).to exist TEST_TIF_INPUT_FILE
104
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
105
+ result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
106
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
107
+ expect(result.exif.colorspace).to eq 'Grayscale'
108
+ end
109
+ end
206
110
 
207
- it 'creates jp2 when given a JPEG' do
208
- generate_test_image(TEST_JPEG_INPUT_FILE)
209
- expect(File).to exist TEST_JPEG_INPUT_FILE
210
- expect(File).to_not exist TEST_JP2_OUTPUT_FILE
211
- @ai = Assembly::Image.new(TEST_JPEG_INPUT_FILE)
212
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
213
- # Indicates a temp tiff was created.
214
- expect(@ai.tmp_path).not_to be_nil
215
- expect(File).not_to exist @ai.tmp_path
216
- expect(result).to be_a_kind_of Assembly::Image
217
- expect(result.path).to eq TEST_JP2_OUTPUT_FILE
218
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
219
- end
111
+ context 'when given a color tif but bitonal image data (1 channels and 1 bits per pixel)' do
112
+ before do
113
+ generate_test_image(TEST_TIF_INPUT_FILE, color: 'Bilevel', image_type: 'TrueColor', profile: '')
114
+ end
220
115
 
221
- it 'does not run if you specify a bogus tmp folder' do
222
- generate_test_image(TEST_JPEG_INPUT_FILE)
223
- bogus_folder = '/crapsticks'
224
- expect(File).to exist TEST_JPEG_INPUT_FILE
225
- expect(File).to_not exist bogus_folder
226
- @ai = Assembly::Image.new(TEST_JPEG_INPUT_FILE)
227
- expect { @ai.create_jp2(tmp_folder: bogus_folder) }.to raise_error
228
- end
116
+ it 'creates color jp2' do
117
+ expect(File).to exist TEST_TIF_INPUT_FILE
118
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
119
+ expect(ai).not_to have_color_profile
120
+ result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
121
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
122
+ expect(result.exif.colorspace).to eq 'sRGB'
123
+ end
124
+ end
229
125
 
230
- it 'creates a jp2 and preserve the temporary file if specified' do
231
- generate_test_image(TEST_JPEG_INPUT_FILE)
232
- expect(File).to exist TEST_JPEG_INPUT_FILE
233
- @ai = Assembly::Image.new(TEST_JPEG_INPUT_FILE)
234
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE, preserve_tmp_source: true)
235
- # Indicates a temp tiff was created.
236
- expect(@ai.tmp_path).not_to be_nil
237
- expect(File).to exist @ai.tmp_path
238
- expect(result).to be_a_kind_of Assembly::Image
239
- expect(result.path).to eq TEST_JP2_OUTPUT_FILE
240
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
241
- expect(File.exist?(@ai.tmp_path)).to be true
242
- end
126
+ context 'when given a graycale tif but with bitonal image data (1 channel and 1 bits per pixel)' do
127
+ before do
128
+ generate_test_image(TEST_TIF_INPUT_FILE, color: 'Bilevel', image_type: 'Grayscale', profile: '')
129
+ end
243
130
 
244
- it 'creates a jp2 of the same filename and in the same location as the input if no output file is specified, and should cleanup tmp file' do
245
- generate_test_image(TEST_TIF_INPUT_FILE)
246
- expect(File).to exist TEST_TIF_INPUT_FILE
247
- expect(File.exist?(TEST_JP2_INPUT_FILE)).to be false
248
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
249
- result = @ai.create_jp2
250
- expect(result).to be_a_kind_of Assembly::Image
251
- expect(result.path).to eq TEST_JP2_INPUT_FILE
252
- expect(TEST_JP2_INPUT_FILE).to be_a_jp2
253
- expect(result.exif.colorspace).to eq 'sRGB'
254
- end
131
+ it 'creates grayscale jp2' do
132
+ expect(File).to exist TEST_TIF_INPUT_FILE
133
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
134
+ expect(ai).not_to have_color_profile
135
+ result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
136
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
137
+ expect(result.exif.colorspace).to eq 'Grayscale'
138
+ end
139
+ end
255
140
 
256
- it 'recreates jp2 if the output file exists and if you allow overwriting' do
257
- generate_test_image(TEST_TIF_INPUT_FILE)
258
- generate_test_image(TEST_JP2_OUTPUT_FILE)
259
- expect(File).to exist TEST_TIF_INPUT_FILE
260
- expect(File).to exist TEST_JP2_OUTPUT_FILE
261
- @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
262
- result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE, overwrite: true)
263
- expect(result).to be_a_kind_of Assembly::Image
264
- expect(result.path).to eq TEST_JP2_OUTPUT_FILE
265
- expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
266
- expect(result.exif.colorspace).to eq 'sRGB'
267
- end
141
+ context 'when given a color tif but with greyscale image data (1 channel and 8 bits per pixel)' do
142
+ before do
143
+ generate_test_image(TEST_TIF_INPUT_FILE, color: 'Grayscale', image_type: 'TrueColor', profile: '')
144
+ end
268
145
 
269
- after(:each) do
270
- # after each test, empty out the input and output test directories
271
- remove_files(TEST_INPUT_DIR)
272
- remove_files(TEST_OUTPUT_DIR)
146
+ it 'creates color jp2' do
147
+ expect(File).to exist TEST_TIF_INPUT_FILE
148
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
149
+ expect(ai).not_to have_color_profile
150
+ result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
151
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
152
+ expect(result.exif.colorspace).to eq 'sRGB'
153
+ end
154
+ end
155
+
156
+ context 'when the source image has no profile' do
157
+ before do
158
+ generate_test_image(TEST_TIF_INPUT_FILE, profile: '') # generate a test input with no profile
159
+ end
160
+
161
+ it 'creates a jp2' do
162
+ expect(File).to exist TEST_TIF_INPUT_FILE
163
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
164
+ expect(ai).not_to have_color_profile
165
+ expect(ai).to be_a_valid_image
166
+ expect(ai).to be_jp2able
167
+ ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
168
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
169
+ end
170
+ end
171
+
172
+ context "when the output file exists and you don't allow overwriting" do
173
+ before do
174
+ generate_test_image(TEST_TIF_INPUT_FILE)
175
+ generate_test_image(TEST_JP2_OUTPUT_FILE)
176
+ end
177
+
178
+ it 'does not run' do
179
+ expect(File).to exist TEST_TIF_INPUT_FILE
180
+ expect(File).to exist TEST_JP2_OUTPUT_FILE
181
+ expect { ai.create_jp2(output: TEST_JP2_OUTPUT_FILE) }.to raise_error(SecurityError)
182
+ end
183
+ end
184
+
185
+ context 'when given a test tiff' do
186
+ before do
187
+ generate_test_image(TEST_TIF_INPUT_FILE)
188
+ end
189
+
190
+ it 'gets the correct image height and width' do
191
+ expect(ai.height).to eq 100
192
+ expect(ai.width).to eq 100
193
+ end
194
+ end
195
+
196
+ context 'when the input file is a jp2' do
197
+ before do
198
+ generate_test_image(TEST_TIF_INPUT_FILE, profile: '') # generate a test input with no profile
199
+ end
200
+
201
+ it 'does not run' do
202
+ expect(File).to exist TEST_TIF_INPUT_FILE
203
+ expect(File).not_to exist TEST_JP2_OUTPUT_FILE
204
+ expect(ai).not_to have_color_profile
205
+ expect(ai).to be_a_valid_image
206
+ expect(ai).to be_jp2able
207
+ ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
208
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
209
+ jp2_file = described_class.new(TEST_JP2_OUTPUT_FILE)
210
+ expect(jp2_file).to be_valid_image
211
+ expect(jp2_file).not_to be_jp2able
212
+ expect { jp2_file.create_jp2 }.to raise_error
213
+ end
214
+ end
215
+
216
+ context 'when you specify a bogus output profile' do
217
+ before do
218
+ generate_test_image(TEST_TIF_INPUT_FILE)
219
+ end
220
+
221
+ it 'runs, because this is not currently an option' do
222
+ expect(File).to exist TEST_TIF_INPUT_FILE
223
+ result = ai.create_jp2(output_profile: 'bogusness')
224
+ expect(result).to be_a_kind_of described_class
225
+ expect(result.path).to eq TEST_JP2_INPUT_FILE
226
+ expect(TEST_JP2_INPUT_FILE).to be_a_jp2
227
+ expect(result.exif.colorspace).to eq 'sRGB'
228
+ end
229
+ end
230
+
231
+ context 'when an invalid tmp folder' do
232
+ before do
233
+ generate_test_image(TEST_JPEG_INPUT_FILE)
234
+ end
235
+
236
+ let(:input_path) { TEST_JPEG_INPUT_FILE }
237
+
238
+ it 'does not run' do
239
+ bogus_folder = '/crapsticks'
240
+ expect(File).to exist TEST_JPEG_INPUT_FILE
241
+ expect(File).not_to exist bogus_folder
242
+ expect { ai.create_jp2(tmp_folder: bogus_folder) }.to raise_error
243
+ end
244
+ end
245
+
246
+ context 'when no output file is specified' do
247
+ before do
248
+ generate_test_image(TEST_TIF_INPUT_FILE)
249
+ end
250
+
251
+ it 'creates a jp2 of the same filename and in the same location as the input and cleans up the tmp file' do
252
+ expect(File).to exist TEST_TIF_INPUT_FILE
253
+ expect(File.exist?(TEST_JP2_INPUT_FILE)).to be false
254
+ result = ai.create_jp2
255
+ expect(result).to be_a_kind_of described_class
256
+ expect(result.path).to eq TEST_JP2_INPUT_FILE
257
+ expect(TEST_JP2_INPUT_FILE).to be_a_jp2
258
+ expect(result.exif.colorspace).to eq 'sRGB'
259
+ end
260
+ end
261
+
262
+ context 'when the output file exists and you allow overwriting' do
263
+ before do
264
+ generate_test_image(TEST_TIF_INPUT_FILE)
265
+ generate_test_image(TEST_JP2_OUTPUT_FILE)
266
+ end
267
+
268
+ it 'recreates jp2' do
269
+ expect(File).to exist TEST_TIF_INPUT_FILE
270
+ expect(File).to exist TEST_JP2_OUTPUT_FILE
271
+ result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE, overwrite: true)
272
+ expect(result).to be_a_kind_of described_class
273
+ expect(result.path).to eq TEST_JP2_OUTPUT_FILE
274
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
275
+ expect(result.exif.colorspace).to eq 'sRGB'
276
+ end
277
+ end
273
278
  end
274
279
  end
275
- # rubocop:enable Metrics/BlockLength
data/spec/images_spec.rb CHANGED
@@ -2,48 +2,46 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # rubocop:disable Metrics/BlockLength
6
- describe Assembly::Images do
7
- it 'should not run if no input folder is passed in' do
8
- expect{ Assembly::Images.batch_generate_jp2('') }.to raise_error
5
+ RSpec.describe Assembly::Images do
6
+ after do
7
+ # after each test, empty out the input and output test directories
8
+ remove_files(TEST_INPUT_DIR)
9
+ remove_files(TEST_OUTPUT_DIR)
10
+ end
11
+
12
+ it 'does not run if no input folder is passed in' do
13
+ expect{ described_class.batch_generate_jp2('') }.to raise_error
9
14
  end
10
15
 
11
- it 'should not run if a non-existent input folder is passed in' do
12
- expect{ Assembly::Images.batch_generate_jp2('/junk/path') }.to raise_error
16
+ it 'does not run if a non-existent input folder is passed in' do
17
+ expect{ described_class.batch_generate_jp2('/junk/path') }.to raise_error
13
18
  end
14
19
 
15
- it 'should run and batch produe jp2s from input tiffs' do
20
+ it 'runs and batch produces jp2s from input tiffs' do
16
21
  ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
17
- Assembly::Images.batch_generate_jp2(TEST_INPUT_DIR, output: TEST_OUTPUT_DIR)
22
+ described_class.batch_generate_jp2(TEST_INPUT_DIR, output: TEST_OUTPUT_DIR)
18
23
  expect(File.directory?(TEST_OUTPUT_DIR)).to be true
19
24
  ['test1', 'test2', 'test3'].each { |image| expect(File.join(TEST_OUTPUT_DIR, "#{image}.jp2")).to be_a_jp2 }
20
25
  end
21
26
 
22
- it 'should run and batch add color profile descriptions input tiffs with no color profile descriptions' do
27
+ it 'runs and batch add color profile descriptions input tiffs with no color profile descriptions' do
23
28
  ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif"), profile: '') }
24
- ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to be nil }
25
- Assembly::Images.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998')
29
+ ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to be_nil }
30
+ described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998')
26
31
  ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'Adobe RGB (1998)' }
27
32
  end
28
33
 
29
- it 'should run and batch add color profile descriptions input tiffs, forcing over existing color profile descriptions' do
34
+ it 'runs and batch add color profile descriptions input tiffs, forcing over existing color profile descriptions' do
30
35
  ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
31
36
  ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'sRGB IEC61966-2.1' }
32
- Assembly::Images.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998', force: true) # force overwrite
37
+ described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998', force: true) # force overwrite
33
38
  ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'Adobe RGB (1998)' }
34
39
  end
35
40
 
36
- it 'should run and batch add color profile descriptions input tiffs, not overwriting existing color profile descriptions' do
41
+ it 'runs and batch add color profile descriptions input tiffs, not overwriting existing color profile descriptions' do
37
42
  ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
38
43
  ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'sRGB IEC61966-2.1' }
39
- Assembly::Images.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998') # do not force overwrite
44
+ described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998') # do not force overwrite
40
45
  ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'sRGB IEC61966-2.1' }
41
46
  end
42
-
43
- after(:each) do
44
- # after each test, empty out the input and output test directories
45
- remove_files(TEST_INPUT_DIR)
46
- remove_files(TEST_OUTPUT_DIR)
47
- end
48
47
  end
49
- # rubocop:enable Metrics/BlockLength