Sha256: 23842d6832e70e8b955e270077edabca6965875287c12e3911ddeacd51923f0f

Contents?: true

Size: 1.42 KB

Versions: 16

Compression:

Stored size: 1.42 KB

Contents

require 'inline_svg'
require 'inline_svg/transform_pipeline'

describe InlineSvg::TransformPipeline::Transformations::Transformation do
  context "#with_svg" do
    it "returns a Nokogiri::XML::Document representing the parsed document fragment" do
      document = Nokogiri::XML::Document.parse("<svg>Some document</svg>")

      transformation = InlineSvg::TransformPipeline::Transformations::Transformation.new(:irrelevant)
      expect(transformation.with_svg(document).to_html).to eq(
        "<svg>Some document</svg>\n"
      )
    end

    it "yields to the block when the document contains an SVG element" do
      document = Nokogiri::XML::Document.parse("<svg>Some document</svg>")
      svg = document.at_css("svg")

      transformation = InlineSvg::TransformPipeline::Transformations::Transformation.new(:irrelevant)

      returned_document = nil
      expect do |b|
        returned_document = transformation.with_svg(document, &b)
      end.to yield_control

      expect(returned_document.to_s).to match(/<svg>Some document<\/svg>/)
    end

    it "does not yield if the document does not contain an SVG element at the root" do
      document = Nokogiri::XML::Document.parse("<foo>bar</foo><svg>Some document</svg>")

      transformation = InlineSvg::TransformPipeline::Transformations::Transformation.new(:irrelevant)

      expect do |b|
        transformation.with_svg(document, &b)
      end.not_to yield_control
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
inline_svg-1.10.0 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.9.0 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.8.0 spec/transformation_pipeline/transformations/transformation_spec.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/inline_svg-1.7.2/spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.7.2 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.7.1 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.7.0 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.6.0 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.5.2 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.5.1 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.5.0 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.4.0 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.3.1 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.3.0 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.2.3 spec/transformation_pipeline/transformations/transformation_spec.rb
inline_svg-1.2.2 spec/transformation_pipeline/transformations/transformation_spec.rb