Sha256: 9a3a7a73681646c2f12e086dbb38bb605026bfe3906822f56dd43cca6dcff0b2

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'
require 'rspec/core/formatters/console_codes'

RSpec.describe "RSpec::Core::Formatters::ConsoleCodes" do
  let(:console_codes) { RSpec::Core::Formatters::ConsoleCodes }

  describe "#console_code_for(code_or_symbol)" do
    context "when given a VT100 integer code" do
      it "returns the code" do
         expect(console_codes.console_code_for(32)).to eq 32
      end
    end

    context "when given a symbolic name" do
      it "returns the code" do
         expect(console_codes.console_code_for(:green)).to eq 32
      end
    end

    context "when given a nonexistant code" do
      it "returns the code for white" do
         expect(console_codes.console_code_for(:octarine)).to eq 37
      end
    end
  end

  describe "#wrap" do
    before do
      allow(RSpec.configuration).to receive(:color_enabled?) { true }
    end

    context "when given a VT100 integer code" do
      it "formats the text with it" do
         expect(console_codes.wrap('abc', 32)).to eq "\e[32mabc\e[0m"
      end
    end

    context "when given a symbolic color name" do
      it "translates it to the correct integer code and formats the text with it" do
         expect(console_codes.wrap('abc', :green)).to eq "\e[32mabc\e[0m"
      end
    end

    context "when given :bold" do
      it "formats the text as bold" do
         expect(console_codes.wrap('abc', :bold)).to eq "\e[1mabc\e[0m"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-core-2.99.2 spec/rspec/core/formatters/console_codes_spec.rb
rspec-core-2.99.1 spec/rspec/core/formatters/console_codes_spec.rb
rspec-core-2.99.0 spec/rspec/core/formatters/console_codes_spec.rb
rspec-core-2.99.0.rc1 spec/rspec/core/formatters/console_codes_spec.rb