mini_magick 4.0.0 → 4.0.1

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.

Potentially problematic release.


This version of mini_magick might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65e1d54473e9a429c269d44123e8a6977bf489fe
4
- data.tar.gz: 7b2b4762e6ee9d6d47ade148b65df993c3b9e08e
3
+ metadata.gz: 7813127461ce5e5ca5f48e6a502672535afd76d4
4
+ data.tar.gz: e82edbba8bb1af4fc07103cbaea62430f03fbb3f
5
5
  SHA512:
6
- metadata.gz: 4852bcf9522da52f7603a2ef96635312b91fef2e72dbcaa77dbec94dddd8e949e4c34d3e6ccc3da8588e42efe6c43b01cace0166d840f40c478966252f0390d0
7
- data.tar.gz: 77bd9eac7c1a015ad7e6cc6de77657a210fc6b7bbb907928aafb08a0bb0b0c237e85a2ca4cd7ecd75cdfda7b55732352ebda096f46adb699ea62b52695385feb
6
+ metadata.gz: 0fee195089d16cd7e8f3ac7b034c1569a7f353116966000698f18153f7c0fa5a4b71b2620375b460d02497521c5d275f68072e8b4960bfc87f9df64c0d2b2014
7
+ data.tar.gz: da4fbde0cffd34084dd50340d4c8e8e51f5b26773b77370f856cc7aeb814e78ca605c053a055b54437bb9127e9c1fc0f631fd0eba581ca8e0b41d0b24217b5a5
@@ -121,7 +121,11 @@ module MiniMagick
121
121
  #
122
122
  def self.attribute(name, key = name.to_s)
123
123
  define_method(name) do |*args|
124
- @info[key, *args]
124
+ if args.any? && MiniMagick::Tool::Mogrify.instance_methods.include?(name)
125
+ mogrify { |b| b.send(name, *args) }
126
+ else
127
+ @info[key, *args]
128
+ end
125
129
  end
126
130
  end
127
131
 
@@ -9,7 +9,7 @@ module MiniMagick
9
9
  module VERSION
10
10
  MAJOR = 4
11
11
  MINOR = 0
12
- TINY = 0
12
+ TINY = 1
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-11-14 00:00:00.000000000 Z
15
+ date: 2014-11-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -76,19 +76,6 @@ files:
76
76
  - lib/mini_magick/tool/stream.rb
77
77
  - lib/mini_magick/utilities.rb
78
78
  - lib/mini_magick/version.rb
79
- - spec/fixtures/animation.gif
80
- - spec/fixtures/default.jpg
81
- - spec/fixtures/exif.jpg
82
- - spec/fixtures/image.psd
83
- - spec/fixtures/not_an_image.rb
84
- - spec/lib/mini_magick/configuration_spec.rb
85
- - spec/lib/mini_magick/image_spec.rb
86
- - spec/lib/mini_magick/shell_spec.rb
87
- - spec/lib/mini_magick/tool_spec.rb
88
- - spec/lib/mini_magick/utilities_spec.rb
89
- - spec/lib/mini_magick_spec.rb
90
- - spec/spec_helper.rb
91
- - spec/support/helpers.rb
92
79
  homepage: https://github.com/minimagick/minimagick
93
80
  licenses:
94
81
  - MIT
@@ -114,17 +101,4 @@ rubygems_version: 2.2.2
114
101
  signing_key:
115
102
  specification_version: 4
116
103
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
117
- test_files:
118
- - spec/fixtures/animation.gif
119
- - spec/fixtures/default.jpg
120
- - spec/fixtures/exif.jpg
121
- - spec/fixtures/image.psd
122
- - spec/fixtures/not_an_image.rb
123
- - spec/lib/mini_magick/configuration_spec.rb
124
- - spec/lib/mini_magick/image_spec.rb
125
- - spec/lib/mini_magick/shell_spec.rb
126
- - spec/lib/mini_magick/tool_spec.rb
127
- - spec/lib/mini_magick/utilities_spec.rb
128
- - spec/lib/mini_magick_spec.rb
129
- - spec/spec_helper.rb
130
- - spec/support/helpers.rb
104
+ test_files: []
Binary file
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
1
- expect(__FILE__).not_to be_an_image
@@ -1,66 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe MiniMagick::Configuration do
4
- subject { Object.new.extend(MiniMagick::Configuration) }
5
-
6
- describe "#configure" do
7
- it "yields self" do
8
- expect { |b| subject.configure(&b) }
9
- .to yield_with_args(subject)
10
- end
11
- end
12
-
13
- describe "#cli" do
14
- it "can be assigned" do
15
- subject.cli = :imagemagick
16
- expect(subject.cli).to eq :imagemagick
17
- end
18
-
19
- it "returns :imagemagick if #processor is mogrify" do
20
- allow(subject).to receive(:processor).and_return("mogrify")
21
- expect(subject.cli).to eq :imagemagick
22
- end
23
-
24
- it "returns :graphicsmagick if #processor is gm" do
25
- allow(subject).to receive(:processor).and_return("gm")
26
- expect(subject.cli).to eq :graphicsmagick
27
- end
28
-
29
- it "returns nil of #processor is nil" do
30
- allow(subject).to receive(:processor).and_return(nil)
31
- expect(subject.cli).to eq nil
32
- end
33
- end
34
-
35
- describe "#cli=" do
36
- it "raises an error when set to an invalid value" do
37
- expect { subject.cli = :grapicsmagick }
38
- .to raise_error(ArgumentError)
39
- end
40
- end
41
-
42
- describe "#processor" do
43
- it "assigns :mogrify by default" do
44
- expect(subject.processor).to eq "mogrify"
45
- end
46
-
47
- it "assigns :gm if ImageMagick is not available" do
48
- allow(MiniMagick::Utilities).to receive(:which).with("mogrify").and_return(nil)
49
- allow(MiniMagick::Utilities).to receive(:which).with("gm").and_return(true)
50
- expect(subject.processor).to eq "gm"
51
- end
52
-
53
- it "returns nil if neither ImageMagick nor GraphicsMagick are available" do
54
- allow(MiniMagick::Utilities).to receive(:which).with("mogrify").and_return(nil)
55
- allow(MiniMagick::Utilities).to receive(:which).with("gm").and_return(nil)
56
- expect(subject.processor).to eq nil
57
- end
58
- end
59
-
60
- describe "#processor=" do
61
- it "raises an error when set to an invalid value" do
62
- expect { subject.processor = "mogrfy" }
63
- .to raise_error(ArgumentError)
64
- end
65
- end
66
- end
@@ -1,460 +0,0 @@
1
- require "spec_helper"
2
- require "pathname"
3
- require "tempfile"
4
- require "fileutils"
5
- require "stringio"
6
-
7
- ["ImageMagick", "GraphicsMagick"].each do |cli|
8
- RSpec.context "With #{cli}", cli: cli.downcase.to_sym do
9
- describe MiniMagick::Image do
10
- subject { described_class.open(image_path) }
11
-
12
- describe ".read" do
13
- it "reads image from String" do
14
- string = File.binread(image_path)
15
- image = described_class.read(string)
16
- expect(image).to be_valid
17
- end
18
-
19
- it "reads image from StringIO" do
20
- stringio = StringIO.new(File.binread(image_path))
21
- image = described_class.read(stringio)
22
- expect(image).to be_valid
23
- end
24
-
25
- it "reads image from tempfile" do
26
- tempfile = Tempfile.open('magick')
27
- FileUtils.cp image_path, tempfile.path
28
- image = described_class.read(tempfile)
29
- expect(image).to be_valid
30
- end
31
- end
32
-
33
- describe ".import_pixels" do
34
- let(:dimensions) { [325, 200] }
35
- let(:depth) { 16 } # 16 bits (2 bytes) per pixel
36
- let(:map) { 'gray' }
37
- let(:pixels) { Array.new(dimensions.inject(:*)) { |i| i } }
38
- let(:blob) { pixels.pack('S*') } # unsigned short, native byte order
39
-
40
- it "can import pixels with default format" do
41
- image = described_class.import_pixels(blob, *dimensions, depth, map)
42
-
43
- expect(image).to be_valid
44
- expect(image.type).to eq 'PNG'
45
- expect(image.dimensions).to eq dimensions
46
- end
47
-
48
- it "can import pixels with custom format" do
49
- image = described_class.import_pixels(blob, *dimensions, depth, map, 'jpeg')
50
-
51
- expect(image).to be_valid
52
- expect(image.type).to eq 'JPEG'
53
- expect(image.dimensions).to eq dimensions
54
- end
55
- end
56
-
57
- describe ".open" do
58
- it "makes a copy of the image" do
59
- image = described_class.open(image_path)
60
- expect(image.path).not_to eq image_path
61
- expect(image).to be_valid
62
- end
63
-
64
- it "accepts a Pathname" do
65
- image = described_class.open(Pathname(image_path))
66
- expect(image).to be_valid
67
- end
68
-
69
- it "loads a remote image" do
70
- begin
71
- image = described_class.open(image_url)
72
- expect(image).to be_valid
73
- rescue SocketError
74
- end
75
- end
76
-
77
- it "validates the image" do
78
- expect { described_class.open(image_path(:not)) }
79
- .to raise_error(MiniMagick::Invalid)
80
- end
81
- end
82
-
83
- describe ".create" do
84
- def create(path = image_path)
85
- described_class.create do |f|
86
- f.write(File.binread(path))
87
- end
88
- end
89
-
90
- it "creates an image" do
91
- image = create
92
- expect(File.exists?(image.path)).to eq true
93
- end
94
-
95
- it "validates the image if validation is set" do
96
- allow(MiniMagick).to receive(:validate_on_create).and_return(true)
97
- expect { create(image_path(:not)) }
98
- .to raise_error(MiniMagick::Invalid)
99
- end
100
-
101
- it "doesn't validate image if validation is disabled" do
102
- allow(MiniMagick).to receive(:validate_on_create).and_return(false)
103
- expect { create(image_path(:not)) }
104
- .not_to raise_error
105
- end
106
- end
107
-
108
- describe "#initialize" do
109
- it "initializes a new image" do
110
- image = described_class.new(image_path)
111
- expect(image).to be_valid
112
- end
113
-
114
- it "accepts a block which it passes on to #combine_options" do
115
- image = described_class.new(subject.path) do |b|
116
- b.resize "100x100!"
117
- end
118
- expect(image.dimensions).to eq [100, 100]
119
- end
120
- end
121
-
122
- describe "equivalence" do
123
- subject(:image) { described_class.new(image_path) }
124
- let(:same_image) { described_class.new(image_path) }
125
- let(:other_image) { described_class.new(image_path(:exif)) }
126
-
127
- it "is #== and #eql? to itself" do
128
- expect(image).to eq(image)
129
- expect(image).to eql(image)
130
- end
131
-
132
- it "is #== and #eql? to an instance of the same image" do
133
- expect(image).to eq(same_image)
134
- expect(image).to eql(same_image)
135
- end
136
-
137
- it "is not #== nor #eql? to an instance of a different image" do
138
- expect(image).not_to eq(other_image)
139
- expect(image).not_to eql(other_image)
140
- end
141
-
142
- it "generates the same hash code for an instance of the same image" do
143
- expect(image.hash).to eq(same_image.hash)
144
- end
145
-
146
- it "generates different same hash codes for a different image" do
147
- expect(image.hash).not_to eq(other_image.hash)
148
- end
149
- end
150
-
151
- describe "#format" do
152
- subject { described_class.open(image_path(:jpg)) }
153
-
154
- it "changes the format of the photo" do
155
- expect { subject.format("png") }
156
- .to change { subject.type }
157
- end
158
-
159
- it "reformats an image with a given extension" do
160
- expect { subject.format('png') }
161
- .to change { File.extname(subject.path) }.to ".png"
162
- end
163
-
164
- it "creates the file with new extension" do
165
- subject.format('png')
166
- expect(File.exist?(subject.path)).to eq true
167
- end
168
-
169
- it "accepts a block of additional commands" do
170
- expect {
171
- subject.format("png") do |b|
172
- b.resize("100x100!")
173
- end
174
- }.to change { subject.dimensions }.to [100, 100]
175
- end
176
-
177
- it "works without an extension" do
178
- subject = described_class.open(image_path(:without_extension))
179
- expect { subject.format("png") }
180
- .to change { File.extname(subject.path) }.from("").to(".png")
181
- end
182
-
183
- it "deletes the previous tempfile" do
184
- old_path = subject.path.dup
185
- subject.format('png')
186
- expect(File.exist?(old_path)).to eq false
187
- end
188
-
189
- it "doesn't delete itself when formatted to the same format" do
190
- subject.format(subject.type.downcase)
191
- expect(File.exists?(subject.path)).to eq true
192
- end
193
-
194
- it "reformats multi-image formats to multiple images" do
195
- subject = described_class.open(image_path(:animation))
196
- subject.format('jpg', nil)
197
- expect(Dir[subject.path.sub('.', '*.')]).not_to be_empty
198
- end
199
-
200
- it "reformats multi-image formats to a single image" do
201
- subject = described_class.open(image_path(:animation))
202
- subject.format('jpg')
203
- expect(subject).to be_valid
204
- end
205
-
206
- it "returns self" do
207
- expect(subject.format('png')).to eq subject
208
- end
209
- end
210
-
211
- describe "#write" do
212
- it "writes the image" do
213
- output_path = random_path("test output")
214
- subject.write(output_path)
215
- expect(described_class.new(output_path)).to be_valid
216
- end
217
-
218
- it "writes an image with stream" do
219
- output_stream = StringIO.new
220
- subject.write(output_stream)
221
- expect(described_class.read(output_stream.string)).to be_valid
222
- end
223
-
224
- it "writes layers" do
225
- output_path = random_path(["", ".#{subject.type.downcase}"])
226
- subject = described_class.new(image_path(:gif))
227
- subject.frames.first.write(output_path)
228
- expect(described_class.new(output_path)).to be_valid
229
- end
230
-
231
- it "accepts a Pathname" do
232
- output_path = Pathname(random_path)
233
- subject.write(output_path)
234
- expect(described_class.new(output_path.to_s)).to be_valid
235
- end
236
- end
237
-
238
- describe "#valid?" do
239
- it "returns true when image is valid" do
240
- image = described_class.new(image_path)
241
- expect(image).to be_valid
242
- end
243
-
244
- it "returns false when image is not valid" do
245
- image = described_class.new(image_path(:not))
246
- expect(image).not_to be_valid
247
- end
248
- end
249
-
250
- describe "#[]" do
251
- it "inspects image meta info" do
252
- expect(subject[:width]).to be_a(Fixnum)
253
- expect(subject[:height]).to be_a(Fixnum)
254
- expect(subject[:dimensions]).to all(be_a(Fixnum))
255
- expect(subject[:colorspace]).to be_a(String)
256
- expect(subject[:format]).to match(/[A-Z]/)
257
- expect(subject[:signature]).to match(/[[:alnum:]]{64}/)
258
- end
259
-
260
- it "supports string keys" do
261
- expect(subject["width"]).to be_a(Fixnum)
262
- expect(subject["height"]).to be_a(Fixnum)
263
- expect(subject["dimensions"]).to all(be_a(Fixnum))
264
- expect(subject["colorspace"]).to be_a(String)
265
- expect(subject["format"]).to match(/[A-Z]/)
266
- expect(subject['signature']).to match(/[[:alnum:]]{64}/)
267
- end
268
-
269
- it "reads exif" do
270
- subject = described_class.new(image_path(:exif))
271
- gps_latitude = subject.exif["GPSLatitude"].split(/\s*,\s*/)
272
- gps_longitude = subject.exif["GPSLongitude"].split(/\s*,\s*/)
273
-
274
- expect(subject["EXIF:ColorSpace"]).to eq "1"
275
- expect(gps_latitude.size).to eq 3
276
- expect(gps_longitude.size).to eq 3
277
- end
278
-
279
- it "passes unknown values directly to -format" do
280
- expect(subject["%w %h"].split.map(&:to_i)).to eq [subject[:width], subject[:height]]
281
- end
282
- end
283
-
284
- it "has attributes" do
285
- expect(subject.type).to match(/^[A-Z]+$/)
286
- expect(subject.mime_type).to match(/^image\/[a-z]+$/)
287
- expect(subject.width).to be_a(Fixnum).and be_nonzero
288
- expect(subject.height).to be_a(Fixnum).and be_nonzero
289
- expect(subject.dimensions).to all(be_a(Fixnum))
290
- expect(subject.size).to be_a(Fixnum).and be_nonzero
291
- expect(subject.colorspace).to be_a(String)
292
- expect(subject.resolution).to all(be_a(Fixnum))
293
- expect(subject.signature).to match(/[[:alnum:]]{64}/)
294
- end
295
-
296
- describe "#exif" do
297
- subject { described_class.new(image_path(:exif)) }
298
-
299
- it "returns a hash of EXIF data" do
300
- expect(subject.exif["DateTimeOriginal"]).to be_a(String)
301
- end
302
-
303
- it "decodes the ExifVersion" do
304
- expect(subject.exif["ExifVersion"]).to eq("0221")
305
- end
306
- end
307
-
308
- describe "#resolution" do
309
- it "accepts units", skip_cli: :graphicsmagick do
310
- expect(subject.resolution("PixelsPerCentimeter"))
311
- .not_to eq subject.resolution("PixelsPerInch")
312
- end
313
- end
314
-
315
- describe "#mime_type" do
316
- it "returns the correct mime type" do
317
- jpg = described_class.new(image_path(:jpg))
318
- expect(jpg.mime_type).to eq 'image/jpeg'
319
- end
320
- end
321
-
322
- describe "#layers" do
323
- it "returns a list of images" do
324
- expect(subject.layers).to all(be_a(MiniMagick::Image))
325
- expect(subject.layers.first).to be_valid
326
- end
327
-
328
- it "returns multiple images for GIFs, PDFs and PSDs" do
329
- gif = described_class.new(image_path(:gif))
330
- psd = described_class.new(image_path(:psd))
331
-
332
- expect(gif.frames.count).to be > 1
333
- expect(psd.layers.count).to be > 1 unless MiniMagick.graphicsmagick?
334
- end
335
-
336
- it "returns one image for other formats" do
337
- jpg = described_class.new(image_path(:jpg))
338
-
339
- expect(jpg.layers.count).to eq 1
340
- end
341
- end
342
-
343
- describe "missing methods" do
344
- context "for a known method" do
345
- it "is executed by #method_missing" do
346
- expect { subject.resize '20x30!' }
347
- .to change { subject.dimensions }.to [20, 30]
348
- end
349
-
350
- it "returns self" do
351
- expect(subject.resize('20x30!')).to eq subject
352
- end
353
-
354
- it "can be responed to" do
355
- expect(subject.respond_to?(:resize)).to eq true
356
- end
357
- end
358
-
359
- context "for an unknown method" do
360
- it "fails with a NoMethodError" do
361
- expect { subject.foo }
362
- .to raise_error(NoMethodError, /MiniMagick::Image/)
363
- end
364
-
365
- it "cannot be responded to" do
366
- expect(subject.respond_to?(:foo)).to eq false
367
- end
368
- end
369
- end
370
-
371
- describe "#combine_options" do
372
- it "chains multiple options and executes them in one command" do
373
- expect {
374
- subject.combine_options { |c| c.resize '20x30!' }
375
- }.to change { subject.dimensions }.to [20, 30]
376
- end
377
-
378
- it "doesn't allow calling of #format" do
379
- expect { subject.combine_options { |c| c.format("png") } }
380
- .to raise_error(NoMethodError)
381
- end
382
-
383
- it "returns self" do
384
- expect(subject.combine_options {}).to eq subject
385
- end
386
- end
387
-
388
- describe "#composite" do
389
- let(:other_image) { described_class.open(image_path) }
390
- let(:mask) { described_class.open(image_path) }
391
-
392
- it "creates a composite of two images" do
393
- image = subject.composite(other_image)
394
- expect(image).to be_valid
395
- end
396
-
397
- it "creates a composite of two images with mask" do
398
- image = subject.composite(other_image, 'jpg', mask)
399
- expect(image).to be_valid
400
- end
401
-
402
- it "yields an optional block" do
403
- expect { |b| subject.composite(other_image, &b) }
404
- .to yield_with_args(an_instance_of(MiniMagick::Tool::Composite))
405
- end
406
-
407
- it "makes the composited image with the provided extension" do
408
- result = subject.composite(other_image, 'png')
409
- expect(result.path).to end_with ".png"
410
-
411
- result = subject.composite(other_image)
412
- expect(result.path).to end_with ".jpg"
413
- end
414
- end
415
-
416
- describe "#collapse!" do
417
- subject { described_class.open(image_path(:animation)) }
418
-
419
- it "collapses the image to one frame" do
420
- subject.collapse!
421
- expect(subject.identify.lines.count).to eq 1
422
- end
423
-
424
- it "keeps the extension" do
425
- expect { subject.collapse! }
426
- .not_to change { subject.type }
427
- end
428
-
429
- it "clears the info" do
430
- expect { subject.collapse! }
431
- .to change { subject.size }
432
- end
433
-
434
- it "returns self" do
435
- expect(subject.collapse!).to eq subject
436
- end
437
- end
438
-
439
- describe "#identify" do
440
- it "returns the output of identify" do
441
- expect(subject.identify).to match(subject.type)
442
- end
443
-
444
- it "yields an optional block" do
445
- output = subject.identify do |b|
446
- b.verbose
447
- end
448
- expect(output).to match("Format:")
449
- end
450
- end
451
-
452
- describe "#run_command" do
453
- it "runs the given command" do
454
- output = subject.run_command("identify", "-format", "%w", subject.path)
455
- expect(output).to eq subject.width.to_s
456
- end
457
- end
458
- end
459
- end
460
- end
@@ -1,66 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe MiniMagick::Shell do
4
- subject { described_class.new }
5
-
6
- describe "#run" do
7
- it "calls #execute with the command" do
8
- expect(subject).to receive(:execute).and_call_original
9
- subject.run(%W[identify #{image_path}])
10
- end
11
-
12
- it "returns stdout" do
13
- allow(subject).to receive(:execute).and_return(["stdout", "stderr", 0])
14
- output = subject.run(%W[foo])
15
- expect(output).to eq "stdout"
16
- end
17
-
18
- it "uses stderr for error messages" do
19
- allow(subject).to receive(:execute).and_return(["", "stderr", 1])
20
- expect { subject.run(%W[foo]) }
21
- .to raise_error(MiniMagick::Error, /`foo`.*stderr/m)
22
- end
23
-
24
- it "raises an error when executable wasn't found" do
25
- allow(subject).to receive(:execute).and_return(["", "not found", 127])
26
- expect { subject.run(%W[foo]) }
27
- .to raise_error(MiniMagick::Error, /not found/)
28
- end
29
-
30
- it "raises errors only in whiny mode" do
31
- subject = described_class.new(false)
32
- allow(subject).to receive(:execute).and_return(["stdout", "", 127])
33
- expect(subject.run(%W[foo])).to eq "stdout"
34
- end
35
-
36
- it "prints to stderr output to $stderr in non-whiny mode" do
37
- subject = described_class.new(false)
38
- allow(subject).to receive(:execute).and_return(["", "stderr", 1])
39
- expect { subject.run(%W[foo]) }.to output("stderr").to_stderr
40
- end
41
- end
42
-
43
- describe "#execute" do
44
- it "executes the command in the shell" do
45
- stdout, * = subject.execute(%W[identify #{image_path(:gif)}])
46
- expect(stdout).to match("GIF")
47
- end
48
-
49
- it "logs the command and execution time in debug mode" do
50
- allow(MiniMagick).to receive(:debug).and_return(true)
51
- expect { subject.execute(%W[identify #{image_path(:gif)}]) }.
52
- to output(/\[\d+.\d+s\] identify #{image_path(:gif)}/).to_stdout
53
- end
54
-
55
- it "returns an appropriate response when command wasn't found" do
56
- stdout, stderr, code = subject.execute(%W[unexisting command])
57
- expect(code).to eq 127
58
- expect(stderr).to match(/not found/)
59
- end
60
-
61
- it "doesn't break on spaces" do
62
- stdout, * = subject.execute(["identify", "-format", "%w %h", image_path])
63
- expect(stdout).to match(/\d+ \d+/)
64
- end
65
- end
66
- end
@@ -1,107 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe MiniMagick::Tool do
4
- subject { MiniMagick::Tool::Identify.new }
5
-
6
- describe "#call" do
7
- it "calls the shell to run the command" do
8
- subject << image_path(:gif)
9
- output = subject.call
10
- expect(output).to match("GIF")
11
- end
12
-
13
- it "strips the output" do
14
- subject << image_path
15
- output = subject.call
16
- expect(output).not_to end_with("\n")
17
- end
18
- end
19
-
20
- describe ".new" do
21
- it "accepts a block, and immediately executes the command" do
22
- output = described_class.new("identify") do |builder|
23
- builder << image_path(:gif)
24
- end
25
- expect(output).to match("GIF")
26
- end
27
- end
28
-
29
- describe "#command" do
30
- it "includes the executable and the arguments" do
31
- allow(subject).to receive(:args).and_return(%W[-list Command])
32
- expect(subject.command).to include(*%W[identify -list Command])
33
- end
34
- end
35
-
36
- describe "#executable" do
37
- it "prepends 'gm' to the command list when using GraphicsMagick" do
38
- allow(MiniMagick).to receive(:cli).and_return(:graphicsmagick)
39
- expect(subject.executable).to eq %W[gm identify]
40
- end
41
-
42
- it "respects #cli_path" do
43
- allow(MiniMagick).to receive(:cli).and_return(:imagemagick)
44
- allow(MiniMagick).to receive(:cli_path).and_return("path/to/cli")
45
- expect(subject.executable).to eq %W[path/to/cli/identify]
46
- end
47
- end
48
-
49
- describe "#<<" do
50
- it "adds argument to the args list" do
51
- subject << "foo" << "bar" << 123
52
- expect(subject.args).to eq %W[foo bar 123]
53
- end
54
- end
55
-
56
- describe "#merge!" do
57
- it "adds arguments to the args list" do
58
- subject << "pre-existing"
59
- subject.merge! ["foo", 123]
60
- expect(subject.args).to eq %W[pre-existing foo 123]
61
- end
62
- end
63
-
64
- describe "#+" do
65
- it "switches the last option to + form" do
66
- subject.help
67
- subject.help.+
68
- subject.debug.+ "foo"
69
- subject.debug.+ 8, "bar"
70
- expect(subject.args).to eq %W[-help +help +debug foo +debug 8 bar]
71
- end
72
- end
73
-
74
- ["ImageMagick", "GraphicsMagick"].each do |cli|
75
- context "with #{cli}", cli: cli.downcase.to_sym do
76
- it "adds dynamically generated operator methods" do
77
- subject.help.depth(8)
78
- expect(subject.args).to eq %W[-help -depth 8]
79
- end
80
-
81
- it "doesn't just delegate to #method_missing" do
82
- expect(subject.class.instance_methods).to include(:help)
83
- end
84
-
85
- it "adds dynamically generated creation operator methods" do
86
- subject.radial_gradient.canvas "khaki"
87
- expect(subject.args).to eq %W[radial-gradient: canvas:khaki]
88
- end
89
- end
90
- end
91
-
92
- it "resets the dynamically generated operator methods on CLI change" do
93
- MiniMagick.cli = :imagemagick
94
- expect(subject).to respond_to(:quiet)
95
-
96
- MiniMagick.cli = :graphicsmagick
97
- expect(subject).not_to respond_to(:quiet)
98
- expect(subject).to respond_to(:ping)
99
- end
100
-
101
- it "doesn't raise errors when false is passed to the constructor" do
102
- subject.help
103
- subject.call(false)
104
-
105
- MiniMagick::Tool::Identify.new(false, &:help)
106
- end
107
- end
@@ -1,17 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe MiniMagick::Utilities do
4
- describe ".which" do
5
- it "identifies when mogrify exists" do
6
- expect(MiniMagick::Utilities.which('mogrify')).not_to be_nil
7
- end
8
-
9
- it "identifies when gm exists" do
10
- expect(MiniMagick::Utilities.which('gm')).not_to be_nil
11
- end
12
-
13
- it "returns nil on nonexistent executables" do
14
- expect(MiniMagick::Utilities.which('yogrify')).to be_nil
15
- end
16
- end
17
- end
@@ -1,39 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe MiniMagick do
4
- describe ".imagemagick?" do
5
- it "returns true if CLI is minimagick" do
6
- allow(described_class).to receive(:cli).and_return(:imagemagick)
7
- expect(described_class.imagemagick?).to eq true
8
- end
9
-
10
- it "returns false if CLI isn't minimagick" do
11
- allow(described_class).to receive(:cli).and_return(:graphicsmagick)
12
- expect(described_class.imagemagick?).to eq false
13
- end
14
- end
15
-
16
- describe ".graphicsmagick?" do
17
- it "returns true if CLI is graphicsmagick" do
18
- allow(described_class).to receive(:cli).and_return(:graphicsmagick)
19
- expect(described_class.graphicsmagick?).to eq true
20
- end
21
-
22
- it "returns false if CLI isn't graphicsmagick" do
23
- allow(described_class).to receive(:cli).and_return(:imagemagick)
24
- expect(described_class.graphicsmagick?).to eq false
25
- end
26
- end
27
-
28
- describe ".cli_version" do
29
- it "returns ImageMagick's version" do
30
- allow(described_class).to receive(:cli).and_return(:imagemagick)
31
- expect(described_class.cli_version).to match(/^\d+\.\d+\.\d+-\d+$/)
32
- end
33
-
34
- it "returns GraphicsMagick's version" do
35
- allow(described_class).to receive(:cli).and_return(:graphicsmagick)
36
- expect(described_class.cli_version).to match(/^\d+\.\d+\.\d+$/)
37
- end
38
- end
39
- end
data/spec/spec_helper.rb DELETED
@@ -1,21 +0,0 @@
1
- require "bundler/setup"
2
- require "mini_magick"
3
- require "pry"
4
-
5
- require_relative "support/helpers"
6
-
7
- RSpec.configure do |config|
8
- config.disable_monkey_patching!
9
- config.formatter = "documentation"
10
- config.color = true
11
- config.fail_fast = true unless ENV["CI"]
12
-
13
- [:imagemagick, :graphicsmagick].each do |cli|
14
- config.around(cli: cli) do |example|
15
- MiniMagick.with_cli(cli) { example.run }
16
- end
17
- config.around(skip_cli: cli) do |example|
18
- example.run unless example.metadata[:cli] == cli
19
- end
20
- end
21
- end
@@ -1,37 +0,0 @@
1
- require "tempfile"
2
-
3
- module Helpers
4
- def image_path(type = :default)
5
- if type != :without_extension
6
- File.join("spec/fixtures",
7
- case type
8
- when :default, :jpg then "default.jpg"
9
- when :animation, :gif then "animation.gif"
10
- when :pdf then "document.pdf"
11
- when :psd then "image.psd"
12
- when :exif then "exif.jpg"
13
- when :not then "not_an_image.rb"
14
- else
15
- fail "image #{type.inspect} doesn't exist"
16
- end
17
- )
18
- else
19
- path = random_path
20
- FileUtils.cp image_path, path
21
- path
22
- end
23
- end
24
-
25
- def image_url
26
- "https://avatars2.githubusercontent.com/u/795488?v=2&s=40"
27
- end
28
-
29
- def random_path(basename = "")
30
- @tempfile = Tempfile.open(basename)
31
- @tempfile.path
32
- end
33
- end
34
-
35
- RSpec.configure do |config|
36
- config.include Helpers
37
- end