Sha256: 49cda04d49f578d17fb1fed0eb4f3dbb5655aa50cf8f97fd1c550a1f5111410b

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

# coding: utf-8

require 'spec_helper'

RSpec.describe Pastel, '.detach' do

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

  it "creates detached instance" do
    error = pastel.red.bold.detach
    expect(error).to be_a(Pastel::Detached)
  end

  it "ensures instance is immutable" do
    error = pastel.red.detach
    expect(error.frozen?).to be(true)
  end

  it "detaches colors combination" do
    error = pastel.red.bold.detach
    expect(error.call('unicorn')).to eq("\e[31;1municorn\e[0m")
    expect(error.call('error')).to eq("\e[31;1merror\e[0m")
  end

  it "allows array like access" do
    error = pastel.red.bold.detach
    expect(error['unicorn']).to eq("\e[31;1municorn\e[0m")
  end

  it "allows alternative call invocation" do
    error = pastel.red.bold.detach
    expect(error.('unicorn')).to eq("\e[31;1municorn\e[0m")
  end

  it "calls detached colors with no arguments" do
    warning = pastel.yellow.detach
    expect(warning.call('')).to eq('')
  end

  it "inspects detached colors" do
    warning = pastel.yellow.bold.detach
    expect(warning.inspect).to eq('#<Pastel::Detached styles=[:yellow, :bold]>')
  end

  it "accepts multiple strings" do
    error = pastel.red.bold.detach
    expect(error.call('Unicorns', ' run ', 'wild')).
      to eq("\e[31;1mUnicorns run wild\e[0m")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pastel-0.5.3 spec/unit/detach_spec.rb
pastel-0.5.2 spec/unit/detach_spec.rb
pastel-0.5.1 spec/unit/detach_spec.rb