/
image_sorcery_examples_spec.rb
97 lines (75 loc) · 2.91 KB
/
image_sorcery_examples_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'fileutils'
require 'image_sorcery'
shared_examples_for Sorcery do |new_instance_method|
subject(:image) do
FileUtils.copy "./spec/fixtures/dog.jpeg", "./spec/fixtures/dog-2.jpeg"
Sorcery.send(new_instance_method, "./spec/fixtures/dog-2.jpeg") # Who doesn't love dogs?
end
describe "getting the dimensions of an image" do
it "returns a hash of dimensions" do
image.dimensions.should == {:x => 160, :y => 120}
end
end
describe "manipulating an image" do
it "resizes an image" do
original_dimensions = image.dimensions
image.manipulate!(:resize => "50%")
image.dimensions.map {|k,v| v.to_i}.should == original_dimensions.map {|k,v| v.to_i/2}
end
it "exposes width and height as integers" do
image.width.should == 160
image.height.should == 120
end
its(:filename_changed?) { should be_false }
its(:file) { should eq "./spec/fixtures/dog-2.jpeg" }
describe "change of format" do
before :each do
image.manipulate!(:format => "png")
end
describe "with image" do
it "should delete original file" do
File.exists?("./spec/fixtures/dog-2.jpeg").should be_false
end
it "should create file with new extension" do
File.exists?("./spec/fixtures/dog-2.png").should be_true
end
its(:identify) { should include "PNG 160x120" }
its(:filename_changed?) { should be_true }
its(:file) { should eq "./spec/fixtures/dog-2.png" }
end
describe "with multi page pdf" do
subject :image do
FileUtils.copy "./spec/fixtures/pdf-sample.pdf", "./spec/fixtures/pdf-sample-2.pdf"
Sorcery.send(new_instance_method, "./spec/fixtures/pdf-sample-2.pdf")
end
it "should delete original file" do
File.exists?("./spec/fixtures/pdf-sample-2.pdf").should be_false
end
it "should create file with new extension" do
case new_instance_method
when "new"
File.exists?("./spec/fixtures/pdf-sample-2-0.png").should be_true
File.exists?("./spec/fixtures/pdf-sample-2-1.png").should be_true
when "gm"
File.exists?("./spec/fixtures/pdf-sample-2.png").should be_true
end
end
its(:identify) { should include "PNG 595x842" }
its(:filename_changed?) { should be_true }
its(:file) { should eq "./spec/fixtures/pdf-sample-2.png" } if new_instance_method == "gm"
its(:file) { should eq "./spec/fixtures/pdf-sample-2-*.png" } if new_instance_method == "new"
end
end
end
describe "converting an image" do
it "writes the new image out to a file" do
image.convert("new_image.png")
File.exists?("new_image.png").should be_true
end
end
describe "identifying an image" do
it "returns a list of layers" do
image.identify.should include "JPEG 160x120"
end
end
end