Skip to content

Commit

Permalink
More robust specs
Browse files Browse the repository at this point in the history
  • Loading branch information
akdubya committed Feb 25, 2010
1 parent ee5e18f commit 006cf89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
32 changes: 15 additions & 17 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/helpers'

describe "Rack::Thumb Base" do
describe Rack::Thumb do
before do
@app = Rack::File.new(::File.dirname(__FILE__))
end
Expand All @@ -11,8 +11,8 @@
res = request.get("/media/imagick_50x.jpg")
res.should.be.ok
res.content_type.should == "image/jpeg"
res.content_length.should == 6221
res.body.bytesize.should == 6221
info = image_info(res.body)
info[:dimensions].should == [50, 52]
end

it "should render a thumbnail with height only" do
Expand All @@ -21,8 +21,8 @@
res = request.get("/media/imagick_x50.jpg")
res.should.be.ok
res.content_type.should == "image/jpeg"
res.content_length.should == 5912
res.body.bytesize.should == 5912
info = image_info(res.body)
info[:dimensions].should == [48, 50]
end

it "should render a thumbnail with width and height (crop-resize)" do
Expand All @@ -31,8 +31,8 @@
res = request.get("/media/imagick_50x50.jpg")
res.should.be.ok
res.content_type.should == "image/jpeg"
res.content_length.should == 6074
res.body.bytesize.should == 6074
info = image_info(res.body)
info[:dimensions].should == [50, 50]
end

it "should render a thumbnail with width, height and gravity (crop-resize)" do
Expand All @@ -41,8 +41,8 @@
res = request.get("/media/imagick_50x100-sw.jpg")
res.should.be.ok
res.content_type.should == "image/jpeg"
res.content_length.should == 6696
res.body.bytesize.should == 6696
info = image_info(res.body)
info[:dimensions].should == [50, 100]
end

it "should render a thumbnail with a signature" do
Expand All @@ -53,8 +53,8 @@
res = request.get("/media/imagick_50x100-sw-#{sig}.jpg")
res.should.be.ok
res.content_type.should == "image/jpeg"
res.content_length.should == 6696
res.body.bytesize.should == 6696
info = image_info(res.body)
info[:dimensions].should == [50, 100]
end

it "should not render a thumbnail that exceeds the original image's dimensions" do
Expand All @@ -63,10 +63,8 @@
res = request.get("/media/imagick_1000x1000.jpg")
res.should.be.ok
res.content_type.should == "image/jpeg"
# There is a miniscule difference between this and the original
# because this is run through the processor.
res.content_length.should == 97373
res.body.bytesize.should == 97373
info = image_info(res.body)
info[:dimensions].should == [572, 591]
end

it "should work with non-file source bodies" do
Expand All @@ -78,8 +76,8 @@
res = request.get("/media/imagick_50x.jpg")
res.should.be.ok
res.content_type.should == "image/jpeg"
res.content_length.should == 6221
res.body.bytesize.should == 6221
info = image_info(res.body)
info[:dimensions].should == [50, 52]
end

it "should return bad request if the signature is invalid" do
Expand Down
9 changes: 8 additions & 1 deletion spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ class String
def each(*args, &block)
each_line(*args, &block)
end
end
end

def image_info(body)
t = Tempfile.new('foo.jpg').tap {|f| f.binmode; f.write(body); f.close }
Mapel.info(t.path)
end

Bacon.summary_on_exit

0 comments on commit 006cf89

Please sign in to comment.