Sha256: 01da78ad0f876040ae465b2ab20a8e52a914eddb0345b7ece0ddd6809bdbed79

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

require 'spec_helper'

RSpec.describe TTY::Screen::Color, '.supports?' do
  let(:output) { StringIO.new('', 'w+') }

  subject(:color) { described_class.new(output: output) }

  it "doesn't check color support for non tty terminal" do
    allow(output).to receive(:tty?).and_return(false)

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

  it "fails to load curses for color support" do
    allow(color).to receive(:require).with('curses').
      and_raise(LoadError)

    expect(color.from_curses).to eq(false)
  end

  it "loads curses for color support" do
    allow(color).to receive(:require).with('curses').and_return(true)
    curses = double(:curses)
    allow(curses).to receive(:init_screen)
    allow(curses).to receive(:has_colors?).and_return(true)
    allow(curses).to receive(:close_screen)

    expect(color.from_curses(curses)).to eql(true)
    expect(curses).to have_received(:has_colors?)
  end

  it "fails to find color for dumb terminal" do
    allow(ENV).to receive(:[]).with('TERM').and_return('dumb')

    expect(color.from_term).to eq(false)
  end

  it "inspects term variable for color capabilities" do
    allow(ENV).to receive(:[]).with('TERM').and_return('xterm')

    expect(color.from_term).to eq(true)
  end

  it "inspects color terminal variable for support" do
    allow(ENV).to receive(:include?).with('COLORTERM').and_return(true)

    expect(color.from_env).to eq(true)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tty-screen-0.4.2 spec/unit/color_spec.rb
tty-screen-0.4.1 spec/unit/color_spec.rb
tty-screen-0.4.0 spec/unit/color_spec.rb