spec/image_spec.rb in psd-1.5.0 vs spec/image_spec.rb in psd-2.0.0
- old
+ new
@@ -1,9 +1,9 @@
require 'spec_helper'
describe 'Image Exporting' do
- let(:psd) { PSD.new('spec/files/pixel.psd') }
+ let!(:psd) { PSD.new('spec/files/pixel.psd') }
describe "the full preview image" do
it "should successfully parse the image data" do
psd.parse!
expect(psd).to be_parsed
@@ -31,55 +31,56 @@
).to eq([0, 100, 200, 255])
end
end
end
- describe "layer images" do
- it "should successfully parse the image data" do
- psd.options[:parse_layer_images] = true
+ describe "Renderer" do
+ before(:each) do
psd.parse!
+ end
- image = psd.tree.children.first.image
- expect(image.width).to eq(1)
- expect(image.height).to eq(1)
+ it "should be available via any tree node" do
+ [psd.tree, psd.tree.children.first].each do |node|
+ expect(node).to respond_to(:renderer)
+ expect(node).to respond_to(:to_png)
+ expect(node).to respond_to(:save_as_png)
+ end
+ end
- expect(image.pixel_data).to eq([ChunkyPNG::Color.rgba(0, 100, 200, 255)])
+ it "returns a Renderer object" do
+ [psd.tree, psd.tree.children.first].each do |node|
+ expect(node.renderer).to be_an_instance_of(PSD::Renderer)
+ end
end
- describe "as PNG" do
- it "should produce a valid PNG object" do
- psd.options[:parse_layer_images] = true
- psd.parse!
+ it "produces a correct PNG" do
+ expect(psd.tree.to_png).to be_an_instance_of(ChunkyPNG::Canvas)
+ expect(psd.tree.to_png.pixels).to eq([ChunkyPNG::Color.rgba(0, 100, 200, 255)])
+ expect(psd.tree.to_png[0, 0]).to eq(ChunkyPNG::Color.rgba(0, 100, 200, 255))
+ end
- png = psd.tree.children.first.image.to_png
- expect(png).to be_an_instance_of(ChunkyPNG::Canvas)
- expect(png.width).to eq(1)
- expect(png.height).to eq(1)
- expect(
- ChunkyPNG::Color.to_truecolor_alpha_bytes(png[0,0])
- ).to eq([0, 100, 200, 255])
+ describe "Canvas" do
+ before do
+ @node = psd.tree.children.first
+ @canvas = PSD::Renderer::Canvas.new(@node)
end
- it "memorizes the png instance" do
- psd.options[:parse_layer_images] = true
- psd.parse!
+ it 'is initialized properly' do
+ expect(@canvas.node).to be @node
+ expect(@canvas.width).to eq @node.width
+ expect(@canvas.height).to eq @node.height
- node = psd.tree.children.first
- png = node.image.to_png
+ expect(@canvas.opacity).to eq @node.opacity
+ expect(@canvas.fill_opacity).to eq @node.fill_opacity
- expect(png).to be_an_instance_of(ChunkyPNG::Canvas)
- expect(node.image.to_png.__id__).to eq(png.__id__)
+ expect(@canvas.canvas).to be_an_instance_of(ChunkyPNG::Canvas)
+ expect(@canvas.instance_variable_get(:@pixel_data)).to be_nil
+ expect(@canvas.canvas.pixels.length).to be 1
end
- it "memorizes the png_with_mask instance" do
- psd = PSD.new('spec/files/path.psd', parse_layer_images: true)
- psd.parse!
-
- node = psd.tree.children.first
- png = node.image.to_png_with_mask
-
- expect(png).to be_an_instance_of(ChunkyPNG::Canvas)
- expect(node.image.to_png_with_mask.__id__).to eq(png.__id__)
+ it 'delegates array methods to internal canvas' do
+ expect(@canvas[0, 0]).to eq ChunkyPNG::Color.rgba(0, 100, 200, 255)
+ expect(@canvas).to respond_to(:[]=)
end
end
end
end