Sha256: 8c85be1534bccae96eb6f08c2f0691fffbc46f60ceab45b2e62123d6dfebdfa8

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'test_helper'

module Vedeu

  describe Colour do

    let(:described)  { Colour.new(attributes) }
    let(:attributes) {
      {
        background: '',
        foreground: ''
      }
    }

    describe '#initialize' do
      it { return_type_for(described, Colour) }
      it { assigns(described, '@attributes', attributes) }
    end

    describe '#background' do
      it { return_type_for(described.background, String) }

      it 'returns an escape sequence' do
        Colour.new({
          background: '#000000'
        }).background.must_equal("\e[48;2;0;0;0m")
      end

      it 'returns an empty string when the value is empty' do
        Colour.new.background.must_equal('')
      end
    end

    describe '#foreground' do
      it { return_type_for(described.foreground, String) }

      it 'returns an escape sequence' do
        Colour.new({
          foreground: '#ff0000'
        }).foreground.must_equal("\e[38;2;255;0;0m")
      end

      it 'returns an empty string when the value is empty' do
        Colour.new.foreground.must_equal('')
      end
    end

    describe '#to_s' do
      it { return_type_for(described.to_s, String) }

      it 'returns an escape sequence' do
        Colour.new({
          foreground: '#ff0000',
          background: '#000000'
        }).to_s.must_equal("\e[38;2;255;0;0m\e[48;2;0;0;0m")
      end

      it 'returns an escape sequence when the foreground is missing' do
        Colour.new({
          background: '#000000'
        }).to_s.must_equal("\e[48;2;0;0;0m")
      end

      it 'returns an escape sequence when the background is missing' do
        Colour.new({
          foreground: '#ff0000',
        }).to_s.must_equal("\e[38;2;255;0;0m")
      end

      it 'returns an empty string when both are missing' do
        Colour.new.to_s.must_equal('')
      end
    end

  end # Colour

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.2.12 test/lib/vedeu/colours/colour_test.rb