Sha256: 63a7a456880f3a7dd0bc54ecba3b6e7c7e6c2ab8dee985786a3ea183e156eabd

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8

require 'spec_helper'

RSpec.describe Pastel::Color, '.alias_color' do

  subject(:color) { described_class.new(enabled: true) }

  it 'aliases non existent color' do
    expect {
      color.alias_color(:funky, :unknown)
    }.to raise_error(Pastel::InvalidAttributeNameError)
  end

  it 'aliases color with invalid name' do
    expect {
      color.alias_color('some name', :red)
    }.to raise_error(Pastel::InvalidAliasNameError, /Invalid alias name/)
  end

  it 'aliases standard color' do
    expect {
      color.alias_color(:red, :red)
    }.to raise_error(Pastel::InvalidAliasNameError, /alias standard color/)
  end

  it 'aliases color :red to :funky' do
    color.alias_color(:funky, :red)
    expect(color.valid?(:funky)).to eq(true)
    expect(color.code(:funky)).to eq([31])
    expect(color.lookup(:funky)).to eq("\e[31m")
  end

  it "has global aliases" do
    color_foo = described_class.new(enabled: true)
    color_bar = described_class.new(enabled: true)
    color_foo.alias_color(:foo, :red)
    color_bar.alias_color(:bar, :red)
    expect(color_foo.valid?(:foo)).to eq(true)
    expect(color_foo.valid?(:bar)).to eq(true)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pastel-0.5.3 spec/unit/color/alias_color_spec.rb
pastel-0.5.2 spec/unit/color/alias_color_spec.rb
pastel-0.5.1 spec/unit/color/alias_color_spec.rb
pastel-0.5.0 spec/unit/color/alias_color_spec.rb
pastel-0.4.0 spec/unit/color/alias_color_spec.rb
pastel-0.3.0 spec/unit/color/alias_color_spec.rb