Sha256: 1c0bab94c2102600bf23d7e4a005723fdf569b2e8e6c827812fdcacfd58c6346

Contents?: true

Size: 1.78 KB

Versions: 14

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

module Roadie
  describe StyleProperty do
    it "is initialized with a property, value, if it is marked as important, and the specificity" do
      StyleProperty.new('color', 'green', true, 45).tap do |declaration|
        expect(declaration.property).to eq('color')
        expect(declaration.value).to eq('green')
        expect(declaration).to be_important
        expect(declaration.specificity).to eq(45)
      end
    end

    describe "string representation" do
      it "is the property and the value joined with a colon" do
        expect(StyleProperty.new('color', 'green', false, 1).to_s).to eq('color:green')
        expect(StyleProperty.new('font-size', '1.1em', false, 1).to_s).to eq('font-size:1.1em')
      end

      it "contains the !important flag when set" do
        expect(StyleProperty.new('color', 'green', true, 1).to_s).to eq('color:green !important')
      end
    end

    describe "comparing" do
      def declaration(specificity, important = false)
        StyleProperty.new('color', 'green', important, specificity)
      end

      it "compares on specificity" do
        expect(declaration(5)).to eq(declaration(5))
        expect(declaration(4)).to be < declaration(5)
        expect(declaration(6)).to be > declaration(5)
      end

      context "with an important declaration" do
        it "is less than the important declaration regardless of the specificity" do
          expect(declaration(99, false)).to be < declaration(1, true)
        end

        it "compares like normal when both declarations are important" do
          expect(declaration(5, true)).to eq(declaration(5, true))
          expect(declaration(4, true)).to be < declaration(5, true)
          expect(declaration(6, true)).to be > declaration(5, true)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
roadie-3.5.1 spec/lib/roadie/style_property_spec.rb
roadie-3.5.0 spec/lib/roadie/style_property_spec.rb
roadie-3.4.0 spec/lib/roadie/style_property_spec.rb
roadie-3.3.0 spec/lib/roadie/style_property_spec.rb
roadie-3.2.2 spec/lib/roadie/style_property_spec.rb
roadie-3.2.1 spec/lib/roadie/style_property_spec.rb
roadie-3.2.0 spec/lib/roadie/style_property_spec.rb
roadie-3.1.1 spec/lib/roadie/style_property_spec.rb
roadie-3.1.0 spec/lib/roadie/style_property_spec.rb
roadie-3.1.0.rc1 spec/lib/roadie/style_property_spec.rb
roadie-3.0.5 spec/lib/roadie/style_property_spec.rb
roadie-3.0.4 spec/lib/roadie/style_property_spec.rb
roadie-3.0.3 spec/lib/roadie/style_property_spec.rb
roadie-3.0.2 spec/lib/roadie/style_property_spec.rb