Sha256: 86e7cc2d9831f33147761518671b0ad54a5f8166e1df3e688e14724efb27cb5a

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe Chroma do
  describe '.paint' do
    context 'with named color' do
      it 'creates a color' do
        expect(Chroma.paint('red')).to be_a(Chroma::Color)
      end
    end

    context 'with 6 character hexadecimal' do
      it 'creates a color' do
        expect(Chroma.paint('#ff0000')).to be_a(Chroma::Color)
        expect(Chroma.paint('ff0000')).to be_a(Chroma::Color)
      end
    end

    context 'with 3 character hexadecimal' do
      it 'creates a color' do
        expect(Chroma.paint('#f00')).to be_a(Chroma::Color)
        expect(Chroma.paint('f00')).to be_a(Chroma::Color)
      end
    end

    context 'with 8 character hexadecimal' do
      let(:hex) { '#80ff0000' }

      it 'creates a color' do
        expect(Chroma.paint(hex)).to be_a(Chroma::Color)
        expect(Chroma.paint(hex[1..-1])).to be_a(Chroma::Color)
      end

      it 'sets alpha' do
        expect(Chroma.paint(hex).alpha).to be_within(0.1).of(0.5)
      end
    end

    context 'with rgb' do
      it 'creates a color' do
        expect(Chroma.paint('rgb(255, 0, 0)')).to be_a(Chroma::Color)
        expect(Chroma.paint('rgba(255, 0, 0, 0.5)')).to be_a(Chroma::Color)
      end

      it 'sets alpha' do
        expect(Chroma.paint('rgba(255, 0, 0, 0.5)').alpha).to eq(0.5)
      end
    end

    context 'with hsl' do
      it 'creates a color' do
        expect(Chroma.paint('hsl(120, 100%, 50%)')).to be_a(Chroma::Color)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chroma-0.2.0 spec/chroma/paint_spec.rb
chroma-0.1.0 spec/chroma/paint_spec.rb
chroma-0.0.1 spec/chroma/paint_spec.rb
chroma-0.0.1.alpha.3 spec/chroma/paint_spec.rb
chroma-0.0.1.alpha.2 spec/chroma/paint_spec.rb