Sha256: 2be9ac2ae3fc047ca2b62e414cdf09554b748963786b28983be1312b53720948

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8

require 'spec_helper'

RSpec.describe Pastel::Color, '.supports?' do
  it "isn't enabled for non tty terminal" do
    allow($stdout).to receive(:tty?).and_return(false)
    color = described_class.new

    expect(color.enabled?).to eq(false)
    expect(color.decorate("Unicorn", :red)).to eq("Unicorn")
  end

  it "isn't enabled for dumb terminal" do
    allow($stdout).to receive(:tty?).and_return(true)
    allow(ENV).to receive(:[]).with('TERM').and_return('dumb')
    color = described_class.new

    expect(color.enabled?).to eq(false)
  end

  it "is enabled for term with color support" do
    allow($stdout).to receive(:tty?).and_return(true)
    allow(ENV).to receive(:[]).with('TERM').and_return('xterm')
    color = described_class.new

    expect(color.enabled?).to eq(true)
  end

  it "is enabled for color terminal" do
    allow($stdout).to receive(:tty?).and_return(true)
    allow(ENV).to receive(:[]).with('TERM').and_return('unknown')
    allow(ENV).to receive(:[]).with('COLORTERM').and_return(true)
    color = described_class.new

    expect(color.enabled?).to eq(true)
  end

  it "forces to be enabled with supports? check" do
    color = described_class.new(enabled: false)
    allow(color).to receive(:supports?)

    expect(color.enabled?).to eq(false)
    expect(color).to_not have_received(:supports?)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pastel-0.2.1 spec/unit/color/supports_spec.rb
pastel-0.2.0 spec/unit/color/supports_spec.rb