-
Notifications
You must be signed in to change notification settings - Fork 23
/
image_sorcery_examples_spec.rb
61 lines (49 loc) · 1.61 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
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
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" }
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