Permalink
Browse files

rspec tests pass with both ruby 1.9 and 1.8

  • Loading branch information...
1 parent cc959c4 commit 830b40d8b227e94c563519980432b3931399ef81 @markus markus committed Jan 20, 2011
Showing with 37 additions and 35 deletions.
  1. +25 −24 spec/im_magick_convert_spec.rb
  2. +12 −11 spec/im_magick_spec.rb
@@ -9,6 +9,7 @@
@fnormal = @fontpath + '/union.ttf'
@fbold = @fontpath + '/unionbd.ttf'
@logo = @input + '/ImageMagick.jpg'
+ FileUtils.mkdir_p(@output)
end
after(:all) do
@@ -17,15 +18,15 @@
it "builds a command from chained method calls" do
cmd = ImMagick::convert.background(:red).fill(:black).font(@fbold).pointsize(40).size('300x').gravity('west').caption(:placeholder)
- base_cmd = %q[-background red -fill black -font ./spec/fonts/unionbd.ttf -pointsize 40 -size 300x -gravity west caption:placeholder]
+ base_cmd = %[-background red -fill black -font #{@fbold} -pointsize 40 -size 300x -gravity west caption:placeholder]
cmd.inspect.should == base_cmd
cmd.run.save(@output + '/chained-base.jpg').should be_a_success
File.exists?(@output + '/chained-base.jpg').should be_true
cmd.bordercolor(:red).border(10)
- expected = %q[-background red -fill black -font ./spec/fonts/unionbd.ttf -pointsize 40 -size 300x -gravity west caption:placeholder -bordercolor red -border 10]
+ expected = %[-background red -fill black -font #{@fbold} -pointsize 40 -size 300x -gravity west caption:placeholder -bordercolor red -border 10]
cmd.inspect.should == expected
cmd.run.save(@output + '/chained-base-border.jpg').should be_a_success
@@ -52,7 +53,7 @@
m -= :flatten
end
- expected = "-size 500x100 xc:none -fill blue -draw 'line 15,0 15,99' -undercolor white \\( -clone 0 \\\n-font ./spec/fonts/unionbd.ttf -fill orange -pointsize 36 -annotate +5+60 foo \\) \\( -clone 0 \\\n-font ./spec/fonts/union.ttf -fill red -pointsize 36 -annotate +5+60 rab \\) -delete 0 -trim +repage +append -transparent blue -trim +repage -background white -flatten"
+ expected = "-size 500x100 xc:none -fill blue -draw 'line 15,0 15,99' -undercolor white \\( -clone 0 \\\n-font #{@fbold} -fill orange -pointsize 36 -annotate +5+60 foo \\) \\( -clone 0 \\\n-font #{@fnormal} -fill red -pointsize 36 -annotate +5+60 rab \\) -delete 0 -trim +repage +append -transparent blue -trim +repage -background white -flatten"
cmd.inspect(:text_a => 'foo', :text_b => 'bar').should == expected
runner = cmd.run(:text_a => 'foo', :text_b => 'rab').save(@output + '/block-with-clone.jpg')
@@ -70,7 +71,7 @@
it "allows introspection of command arguments" do
cmd = ImMagick::convert.size('320x100').xc(:transparent).font(@fnormal).pointsize(72).fill(:red).annotate('+26+70', :placeholder)
- expected = %q[-size 320x100 xc:transparent -font ./spec/fonts/union.ttf -pointsize 72 -fill red -annotate +26+70 'Foo Bar']
+ expected = %[-size 320x100 xc:transparent -font #{@fnormal} -pointsize 72 -fill red -annotate +26+70 'Foo Bar']
cmd.inspect(:placeholder => 'Foo Bar').should == expected
cmd.size?.should == ['320x100']
@@ -87,7 +88,7 @@
it "allows binding to command argument symbols" do
cmd = ImMagick::convert.from(:source).resize('200x').rotate(:rotation)
- expected = './spec/fixtures/ImageMagick.jpg -resize 200x -rotate 90'
+ expected = "#{@logo} -resize 200x -rotate 90"
cmd.inspect(:source => @logo, :rotation => 90).should == expected
cmd.run(:source => @logo, :rotation => 90).save(@output + '/magick-200.jpg').should be_a_success
end
@@ -105,12 +106,12 @@
m.border = 5
end.to("#{@output}/label-%s.png")
- expected = %q[-size 1000x1200 xc:orange -background orange -bordercolor orange -pointsize 30 -gravity north -font ./spec/fonts/union.ttf -fill black -annotate +0+0.0 foo -fill black -annotate +0+36.0 bar -trim +repage -border 5]
+ expected = %[-size 1000x1200 xc:orange -background orange -bordercolor orange -pointsize 30 -gravity north -font #{@fnormal} -fill black -annotate +0+0.0 foo -fill black -annotate +0+36.0 bar -trim +repage -border 5]
cmd.inspect(:text => "foo\nbar", :red => :orange, :white => :black, :pointsize => 30).should == expected # check twice
cmd.inspect(:text => "foo\nbar", :red => :orange, :white => :black, :pointsize => 30).should == expected
runner = cmd.run(:text => "foo\nbar", :red => :orange, :white => :black, :pointsize => 30).save('sample')
- runner.last_command.should == "convert " + expected + " \\\n./spec/output/label-sample.png"
+ runner.last_command.should == "convert " + expected + " \\\n#{@output}/label-sample.png"
runner.output.should be_empty
runner.should be_a_success
File.exists?(@output + '/label-sample.png').should be_true
@@ -125,7 +126,7 @@
m.stroke(:none).push(action)
end
- expected = "-gravity center -size 400x100 xc:white -font ./spec/fonts/unionbd.ttf -pointsize 60 -fill red -stroke black -strokewidth 7 -annotate +0+5 'Hello World' -stroke none -annotate +0+5 'Hello World'"
+ expected = "-gravity center -size 400x100 xc:white -font #{@fbold} -pointsize 60 -fill red -stroke black -strokewidth 7 -annotate +0+5 'Hello World' -stroke none -annotate +0+5 'Hello World'"
cmd.inspect(:text => 'Hello World').should == expected
cmd.run(:text => 'Hello World', :red => :magenta, :white => :orange).save(@output + '/double-outline.gif').should be_a_success
@@ -134,10 +135,10 @@
it "can create instances of itself which can be adapted at runtime" do
cmd = ImMagick::convert.size('320x100').canvas(:black).gravity(:center).font(@fnormal).pointsize(80).fill(:black).stroke(:orange).strokewidth(2)
- base_cmd = %q[-size 320x100 xc:black -gravity center -font ./spec/fonts/union.ttf -pointsize 80 -fill black -stroke orange -strokewidth 2]
+ base_cmd = %[-size 320x100 xc:black -gravity center -font #{@fnormal} -pointsize 80 -fill black -stroke orange -strokewidth 2]
cmd.inspect.should == base_cmd
- expected = %q[-size 320x100 xc:black -gravity center -font ./spec/fonts/union.ttf -pointsize 80 -fill black -stroke orange -strokewidth 2 -annotate +0+0 'foo bar']
+ expected = %[-size 320x100 xc:black -gravity center -font #{@fnormal} -pointsize 80 -fill black -stroke orange -strokewidth 2 -annotate +0+0 'foo bar']
cmd.instance.annotate('+0+0', 'foo bar').inspect.should == expected
cmd.inspect.should == base_cmd
@@ -147,20 +148,20 @@
it "allows you to specify the output destination as a path" do
cmd = ImMagick::convert.from(:source).resize('200x').crop(200, 100).to(@output + '/magick-cropped.jpg')
- expected = './spec/fixtures/ImageMagick.jpg -resize 200x -crop 200x100+0+0'
+ expected = "#{@logo} -resize 200x -crop 200x100+0+0"
cmd.inspect(:source => @logo).should == expected
runner = cmd.run(:source => @logo).save
- runner.last_command.should == "convert " + expected + " \\\n./spec/output/magick-cropped.jpg"
+ runner.last_command.should == "convert " + expected + " \\\n#{@output}/magick-cropped.jpg"
runner.should be_a_success
runner.output.should be_empty
end
it "allows you to specify the output destination as a sprintf pattern" do
cmd = ImMagick::convert.from(:source).resize('100x').quality(80).to("#{@output}/pattern-%02d.jpg")
- expected = './spec/fixtures/ImageMagick.jpg -resize 100x -quality 80'
+ expected = "#{@logo} -resize 100x -quality 80"
cmd.inspect(:source => @logo).should == expected
runner = cmd.run(:source => @logo).save(1)
- runner.last_command.should == "convert " + expected + " \\\n./spec/output/pattern-01.jpg"
+ runner.last_command.should == "convert " + expected + " \\\n#{@output}/pattern-01.jpg"
runner.should be_a_success
runner.output.should be_empty
File.exists?(@output + '/pattern-01.jpg').should be_true
@@ -177,13 +178,13 @@
m.caption = :pipe
end.quality(85).to(@output + '/date-%s.jpg')
- expected = "-background red -fill white -font ./spec/fonts/union.ttf -pointsize 50 -size 500x -gravity center caption:'matches :pipe to :@- to read from pipe' -quality 85"
+ expected = "-background red -fill white -font #{@fnormal} -pointsize 50 -size 500x -gravity center caption:'matches :pipe to :@- to read from pipe' -quality 85"
cmd.inspect(:pipe => 'matches :pipe to :@- to read from pipe').should == expected
- expected = "-background red -fill white -font ./spec/fonts/union.ttf -pointsize 50 -size 500x -gravity center caption:@- -quality 85"
+ expected = "-background red -fill white -font #{@fnormal} -pointsize 50 -size 500x -gravity center caption:@- -quality 85"
runner = cmd.run.pipe('date').save('today')
- runner.last_command.should == "date | convert " + expected + " \\\n./spec/output/date-today.jpg"
+ runner.last_command.should == "date | convert " + expected + " \\\n#{@output}/date-today.jpg"
runner.should be_a_success
runner.output.should be_empty
File.exists?(runner.filename).should be_true
@@ -192,31 +193,31 @@
it "offers resize methods" do
cmd = ImMagick::convert.from(:source).resize_percent(50).to(@output + '/magick-geometry-change-a.jpg')
- cmd.inspect(:source => @logo).should == "./spec/fixtures/ImageMagick.jpg -resize '50%'"
+ cmd.inspect(:source => @logo).should == "#{@logo} -resize '50%'"
cmd.run(:source => @logo).save.should be_a_success
cmd = ImMagick::convert.from(:source).resize.to(@output + '/magick-geometry-change-b.jpg')
- cmd.inspect(:source => @logo, :geometry => '100x100>').should == "./spec/fixtures/ImageMagick.jpg -resize '100x100>'"
+ cmd.inspect(:source => @logo, :geometry => '100x100>').should == "#{@logo} -resize '100x100>'"
cmd.run(:source => @logo, :geometry => '100x100>').save.should be_a_success
cmd = ImMagick::convert.from(:source).resize(:w, :h).to(@output + '/magick-geometry-change-c.jpg')
- cmd.inspect(:source => @logo, :w => 100, :h => 200).should == "./spec/fixtures/ImageMagick.jpg -resize 100x200"
+ cmd.inspect(:source => @logo, :w => 100, :h => 200).should == "#{@logo} -resize 100x200"
cmd.run(:source => @logo, :w => 100, :h => 200).save.should be_a_success
end
it "offers a crop_resized macro" do
crop1 = ImMagick::convert.from(:source).crop_resized(:source).to(@output + '/magick-resize-cropped.jpg')
- expected = "./spec/fixtures/ImageMagick.jpg -resize 100x103 -gravity center -crop 100x50+0+0 +repage"
+ expected = "#{@logo} -resize 100x103 -gravity center -crop 100x50+0+0 +repage"
crop1.inspect(:source => @logo, :width => 100, :height => 50).should == expected
- expected = "./spec/fixtures/ImageMagick.jpg -resize 97x100 -gravity south -crop 50x100+0+0 +repage"
+ expected = "#{@logo} -resize 97x100 -gravity south -crop 50x100+0+0 +repage"
crop1.inspect(:source => @logo, :width => 50, :height => 100, :gravity => :south).should == expected
crop2 = ImMagick::convert.from(:src).crop_resized(:src, :w, :h, :g).rotate(:'90').grayscale.gaussian_blur(:b).to(@output + '/magick-resize-cropped-gs-blur.jpg')
- expected = "./spec/fixtures/ImageMagick.jpg -resize 97x100 -gravity south -crop 50x100+0+0 +repage -rotate 180 -fx intensity -gaussian-blur 3.0x1.0"
+ expected = "#{@logo} -resize 97x100 -gravity south -crop 50x100+0+0 +repage -rotate 180 -fx intensity -gaussian-blur 3.0x1.0"
crop2.inspect(:src => @logo, :w => 50, :h => 100, :g => :south, :'90' => 180, :b => 3).should == expected
runner = crop2.run(:src => @logo, :w => 50, :h => 100, :g => :south, :'90' => 180, :b => 3).save
- runner.last_command.should == "convert " + expected + " \\\n./spec/output/magick-resize-cropped-gs-blur.jpg"
+ runner.last_command.should == "convert " + expected + " \\\n#{@output}/magick-resize-cropped-gs-blur.jpg"
runner.should be_a_success
info = ImMagick::ImageInfo.on(runner.filename)
@@ -9,6 +9,7 @@
@fnormal = @fontpath + '/union.ttf'
@fbold = @fontpath + '/unionbd.ttf'
@logo = @input + '/ImageMagick.jpg'
+ FileUtils.mkdir_p(@output)
end
after(:all) do
@@ -63,13 +64,13 @@ def resize_image(img, size)
m.font(@fnormal).pointsize(20).gravity(:center).caption(:placeholder)
end
- expected = "-background white -fill black -size 200x -font ./spec/fonts/union.ttf -pointsize 20 -gravity center caption:placeholder"
+ expected = "-background white -fill black -size 200x -font #{@fnormal} -pointsize 20 -gravity center caption:placeholder"
img.inspect.should == expected
img[:background] = :pink
img[:placeholder] = 'Hello World'
- expected = "-background pink -fill black -size 200x -font ./spec/fonts/union.ttf -pointsize 20 -gravity center caption:'Hello World'"
+ expected = "-background pink -fill black -size 200x -font #{@fnormal} -pointsize 20 -gravity center caption:'Hello World'"
img.inspect.should == expected
img.save(@output + '/image-with-caption.jpg').should == @output + '/image-with-caption.jpg'
@@ -89,7 +90,7 @@ def resize_image(img, size)
img.exists?.should_not be_true
- expected = "./spec/fixtures/ImageMagick.jpg"
+ expected = "#{@input}/ImageMagick.jpg"
img.inspect.should == expected
img.save(0).should == @output + '/ImageMagick-0.jpg'
@@ -103,7 +104,7 @@ def resize_image(img, size)
cmd << file1 << file2
cmd.append!
end
- expected = "-background transparent -fill black ./spec/output/ImageMagick-1.jpg ./spec/output/ImageMagick-2.jpg +append"
+ expected = "-background transparent -fill black #{file1} #{file2} +append"
img.inspect.should == expected
img.save(@output + '/appended.jpg').should == @output + '/appended.jpg'
end
@@ -116,33 +117,33 @@ def resize_image(img, size)
with_image(@logo) do |img|
resize_image(img, 100)
- img.inspect.should == "./spec/fixtures/ImageMagick.jpg -resize 100x100"
+ img.inspect.should == "#{@logo} -resize 100x100"
end
with_image(@logo) do |img|
resize_image(img, [100, 50])
- img.inspect.should == "./spec/fixtures/ImageMagick.jpg -resize 100x50"
+ img.inspect.should == "#{@logo} -resize 100x50"
end
with_image(@logo) do |img|
resize_image(img, :width => 100, :height => 200)
- img.inspect.should == "./spec/fixtures/ImageMagick.jpg -resize 194x200 -gravity center -crop 100x200+0+0 +repage"
+ img.inspect.should == "#{@logo} -resize 194x200 -gravity center -crop 100x200+0+0 +repage"
end
with_image(@logo) do |img|
resize_image(img, :width => 200, :height => 300, :gravity => :west)
- img.inspect.should == "./spec/fixtures/ImageMagick.jpg -resize 291x300 -gravity west -crop 200x300+0+0 +repage"
+ img.inspect.should == "#{@logo} -resize 291x300 -gravity west -crop 200x300+0+0 +repage"
end
end
it "offers a macro for crop_resized" do
img = ImMagick::Image.file(@logo)
- img.source.should == "./spec/fixtures/ImageMagick.jpg"
+ img.source.should == @logo
img.crop_resized(200, 200, :south)
- img.inspect.should == "./spec/fixtures/ImageMagick.jpg -resize 200x207 -gravity south -crop 200x200+0+0 +repage"
+ img.inspect.should == "#{@logo} -resize 200x207 -gravity south -crop 200x200+0+0 +repage"
img = ImMagick::Image.file(@logo)
img.crop_resized(:w, :h, :g)
- img.inspect(:w => 200, :h => 300, :g => :south).should == "./spec/fixtures/ImageMagick.jpg -resize 291x300 -gravity south -crop 200x300+0+0 +repage"
+ img.inspect(:w => 200, :h => 300, :g => :south).should == "#{@logo} -resize 291x300 -gravity south -crop 200x300+0+0 +repage"
img.save(@output + '/crop-resized-img.jpg', :w => 200, :h => 300, :g => :south).should == @output + '/crop-resized-img.jpg'
end

0 comments on commit 830b40d

Please sign in to comment.