Sha256: de734f7c253ff0c0d8d77a7b8fb9bda5568aa491e1ac247a78d72e1b3ba69a9e

Contents?: true

Size: 1.73 KB

Versions: 7

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Roadie
  describe Stylesheet do
    it "is initialized with a name and CSS" do
      stylesheet = Stylesheet.new("foo.css", "body { color: green; }")
      expect(stylesheet.name).to eq("foo.css")
    end

    it "has a list of blocks" do
      stylesheet = Stylesheet.new("foo.css", <<-CSS)
        body { color: green !important; font-size: 200%; }
        a, i { color: red; }
      CSS
      expect(stylesheet).to have(3).blocks
      expect(stylesheet.blocks.map(&:to_s)).to eq([
        "body{color:green !important;font-size:200%}",
        "a{color:red}",
        "i{color:red}"
      ])
    end

    it "has a string representation of the contents" do
      stylesheet = Stylesheet.new("example.css", "body { color: green;}a{ color: red; font-size: small }")
      expect(stylesheet.to_s).to eq("body{color:green}\na{color:red;font-size:small}")
    end

    it "understands data URIs" do
      # http://css-tricks.com/data-uris/
      stylesheet = Stylesheet.new("foo.css", <<-CSS)
      h1 {
        background-image: url(data:image/gif;base64,R0lGODl)
      }
      CSS

      expect(stylesheet).to have(1).blocks
      expect(stylesheet.blocks.map(&:to_s)).to eq([
        "h1{background-image:url(data:image/gif;base64,R0lGODl)}"
      ])
    end

    it "does not mutate the input CSS" do
      input = "/* comment */ body { color: green; }"
      input_copy = input.dup
      expect {
        Stylesheet.new("name", input)
      }.to_not change { input }.from(input_copy)
    end

    it "strips UTF-8 Byte Order Mark" do
      input = "\xEF\xBB\xBFbody { color: green; }"
      stylesheet = Stylesheet.new("bom.css", input)
      expect(stylesheet.to_s).to eq "body{color:green}"
    end
  end
end

Version data entries

7 entries across 6 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/roadie-5.2.1/spec/lib/roadie/stylesheet_spec.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/roadie-5.2.1/spec/lib/roadie/stylesheet_spec.rb
roadie-5.2.1 spec/lib/roadie/stylesheet_spec.rb
roadie-5.2.0 spec/lib/roadie/stylesheet_spec.rb
roadie-5.1.0 spec/lib/roadie/stylesheet_spec.rb
roadie-5.0.1 spec/lib/roadie/stylesheet_spec.rb
roadie-5.0.0 spec/lib/roadie/stylesheet_spec.rb