spec/prawn/svg/elements/base_spec.rb in prawn-svg-0.22.1 vs spec/prawn/svg/elements/base_spec.rb in prawn-svg-0.23.0
- old
+ new
@@ -1,12 +1,12 @@
require 'spec_helper'
describe Prawn::SVG::Elements::Base do
let(:svg) { "<svg></svg>" }
- let(:document) { Prawn::SVG::Document.new(svg, [800, 600], {}) }
+ let(:document) { Prawn::SVG::Document.new(svg, [800, 600], {}, font_registry: Prawn::SVG::FontRegistry.new("Helvetica" => {:normal => nil})) }
let(:parent_calls) { [] }
- let(:element) { Prawn::SVG::Elements::Base.new(document, document.root, parent_calls, {}) }
+ let(:element) { Prawn::SVG::Elements::Base.new(document, document.root, parent_calls, Prawn::SVG::State.new) }
describe "#initialize" do
let(:svg) { '<something id="hello"/>' }
it "adds itself to the elements_by_id hash if an id attribute is supplied" do
@@ -50,11 +50,11 @@
expect(element).to receive(:apply) do
element.send :add_call, "test", "argument"
end
element.process
- expect(element.parent_calls).to eq [["end_path", [], [["test", ["argument"], []]]]]
+ expect(element.parent_calls).to eq [["fill", [], [["test", ["argument"], []]]]]
end
it "quietly absorbs a SkipElementQuietly exception" do
expect(element).to receive(:parse).and_raise(Prawn::SVG::Elements::Base::SkipElementQuietly)
expect(element).to_not receive(:apply)
@@ -77,49 +77,71 @@
subject { element.send :parse_fill_and_stroke_attributes_and_call }
it "doesn't change anything if no fill attribute provided" do
subject
- expect(element.state[:fill]).to be nil
+ expect(element.state.fill).to be true
+
+ element.state.fill = false
+ subject
+ expect(element.state.fill).to be false
end
it "doesn't change anything if 'inherit' fill attribute provided" do
element.attributes['fill'] = 'inherit'
subject
- expect(element.state[:fill]).to be nil
+ expect(element.state.fill).to be true
+
+ element.state.fill = false
+ subject
+ expect(element.state.fill).to be false
end
it "turns off filling if 'none' fill attribute provided" do
element.attributes['fill'] = 'none'
subject
- expect(element.state[:fill]).to be false
+ expect(element.state.fill).to be false
end
it "uses the fill attribute's color" do
expect(element).to receive(:add_call).with('fill_color', 'ff0000')
element.attributes['fill'] = 'red'
subject
- expect(element.state[:fill]).to be true
+ expect(element.state.fill).to be true
end
it "uses black if the fill attribute's color is unparseable" do
expect(element).to receive(:add_call).with('fill_color', '000000')
element.attributes['fill'] = 'blarble'
subject
- expect(element.state[:fill]).to be true
+ expect(element.state.fill).to be true
end
it "uses the color attribute if 'currentColor' fill attribute provided" do
expect(element).to receive(:add_call).with('fill_color', 'ff0000')
element.attributes['fill'] = 'currentColor'
element.attributes['color'] = 'red'
+ element.send :parse_color_attribute
subject
- expect(element.state[:fill]).to be true
+ expect(element.state.fill).to be true
end
+ context "with a color attribute defined on a parent element" do
+ let(:svg) { '<svg style="color: green;"><g style="color: red;"><rect width="10" height="10" style="fill: currentColor;"></rect></g></svg>' }
+ let(:element) { Prawn::SVG::Elements::Root.new(document, document.root, parent_calls) }
+ let(:flattened_calls) { flatten_calls(element.base_calls) }
+
+ it "uses the parent's color element if 'currentColor' fill attribute provided" do
+ element.process
+
+ expect(flattened_calls).to include ['fill_color', ['ff0000']]
+ expect(flattened_calls).not_to include ['fill_color', ['00ff00']]
+ end
+ end
+
it "turns off filling if UnresolvableURLWithNoFallbackError is raised" do
element.attributes['fill'] = 'url()'
subject
- expect(element.state[:fill]).to be false
+ expect(element.state.fill).to be false
end
end
end