Sha256: 852150e06dd5e2f70c189dbfc33a35775267f4ebb64e01dc38e9bd631c227839

Contents?: true

Size: 1.36 KB

Versions: 11

Compression:

Stored size: 1.36 KB

Contents

require 'rib/test'
require 'rib/more/color'

describe Rib::Color do
  behaves_like :rib

  should 'give correct color' do
    @color = Class.new do
      include Rib::Color
      def colors
        @colors ||= Rib::Shell.new.before_loop.config[:color]
      end
    end.new

    @color.send(:format_color,
      [{0 => :a}, 'b', [nil, {false => Object}], {true => Exception.new}]).
        should.eq \
          "\e[34m[\e[0m\e[34m{\e[0m\e[31m0\e[0m\e[34m=>\e[0m\e[36m:a\e[0m\e" \
          "[34m}\e[0m\e[34m, \e[0m\e[32m\"b\"\e[0m\e[34m, \e[0m\e[34m[\e[0m" \
          "\e[35mnil\e[0m\e[34m, \e[0m\e[34m{\e[0m\e[35mfalse\e[0m\e[34m=>"  \
          "\e[0m\e[33mObject\e[0m\e[34m}\e[0m\e[34m]\e[0m\e[34m, \e[0m\e[34m"\
          "{\e[0m\e[35mtrue\e[0m\e[34m=>\e[0m\e[35m#<Exception: Exception>"  \
          "\e[0m\e[34m}\e[0m\e[34m]\e[0m"
  end

  # regression test
  should "colorize errors with `/' inside" do
    i = if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
          1
        else
          0
        end

    begin
      line = __LINE__; 1/0
    rescue ZeroDivisionError => e
      msg = "test/more/#{Rib::Color.yellow{'test_color.rb'}}:" \
            "#{Rib::Color.red{line}}:in #{Rib::Color.green}"
      Rib::Color.colorize_backtrace(e.backtrace)[i].should =~ \
        Regexp.new(
          "#{Regexp.escape(msg)}`.+'#{Regexp.escape(Rib::Color.reset)}")
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rib-1.1.5 test/more/test_color.rb
rib-1.1.4 test/more/test_color.rb
rib-1.1.3 test/more/test_color.rb
rib-1.1.2 test/more/test_color.rb
rib-1.1.1 test/more/test_color.rb
rib-1.1.0 test/more/test_color.rb
rib-1.0.5 test/more/test_color.rb
rib-1.0.4 test/more/test_color.rb
rib-1.0.3 test/more/test_color.rb
rib-1.0.2 test/more/test_color.rb
rib-1.0.1 test/more/test_color.rb