spec/prawn/svg/elements/base_spec.rb in prawn-svg-0.27.1 vs spec/prawn/svg/elements/base_spec.rb in prawn-svg-0.28.0
- old
+ new
@@ -42,10 +42,40 @@
]]
]
end
end
+ describe "fills and strokes" do
+ before { element.process }
+ subject { element.base_calls.last }
+
+ context "with neither fill nor stroke" do
+ let(:svg) { '<rect style="fill: none;"></rect>' }
+ it { is_expected.to eq ['end_path', [], []] }
+ end
+
+ context "with a fill only" do
+ let(:svg) { '<rect style="fill: black;"></rect>' }
+ it { is_expected.to eq ['fill', [], []] }
+ end
+
+ context "with a stroke only" do
+ let(:svg) { '<rect style="fill: none; stroke: black;"></rect>' }
+ it { is_expected.to eq ['stroke', [], []] }
+ end
+
+ context "with fill and stroke" do
+ let(:svg) { '<rect style="fill: black; stroke: black;"></rect>' }
+ it { is_expected.to eq ['fill_and_stroke', [], []] }
+ end
+
+ context "with fill with evenodd fill rule" do
+ let(:svg) { '<rect style="fill: black; fill-rule: evenodd;"></rect>' }
+ it { is_expected.to eq ['fill', [{fill_rule: :even_odd}], []] }
+ end
+ end
+
it "appends calls to the parent element" do
expect(element).to receive(:apply) do
element.send :add_call, "test", "argument"
end
@@ -127,8 +157,34 @@
it "computes to 'none' if UnresolvableURLWithNoFallbackError is raised" do
expect(element).to_not receive(:add_call)
element.properties.fill = 'url()'
subject
expect(element.computed_properties.fill).to eq 'none'
+ end
+ end
+
+ describe "stylesheets" do
+ let(:svg) { <<-SVG }
+ <svg>
+ <style>
+ .special rect { fill: green; }
+ rect { fill: red; }
+ </style>
+ <rect width="100" height="100"></rect>
+ <g class="special">
+ <rect width="100" height="100"></rect>
+ <rect width="100" height="100" style="fill: yellow;"></rect>
+ </g>
+ </svg>
+ SVG
+
+ it "applies stylesheet styling but style attributes take precedence" do
+ document = Prawn::SVG::Document.new(svg, [100, 100], {})
+ calls = []
+ element = Prawn::SVG::Elements::Root.new(document, document.root, calls)
+ element.process
+
+ fill_colors = calls.select { |cmd, _, _| cmd == 'fill_color' }.map { |_, args, _| args.first }
+ expect(fill_colors).to eq ['000000', 'ff0000', '008000', 'ffff00']
end
end
end