Sha256: 88250e9ed05517c4c6357c903d754af4aa1705a93f79569edb1545edba517dfd

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

# TODO fix include specs, probably failing because of some rspec voodoo

describe 'Paint::SHORTCUTS' do
  before do
    Paint::SHORTCUTS[:example] = {
      :white => Paint.color(:black),
      :red => Paint.color(:red, :bright),
      :title => Paint.color(:underline),
    }
  end

  context 'Paint::Example.method_missing' do
    it 'returns a color defined in the SHORTCUTS hash under the :example key' do
      Paint::Example.red == "\e[31m"
    end

    it 'returns a color defined in the SHORTCUTS hash under the :some_module key; method takes string to colorize' do
      Paint::Example.red 'J-_-L' == "\e[31;1mJ-_-L\e[0m"
    end
  end

  context 'include Paint::Example' do
    include Paint::Example
    #red.should == "\e[31;1m"
    #white( 'Ruby' ).should "\e[30m"
  end


  context 'include Paint::Example::String' do
    it 'adds shortcuts methods that colorize self' do
      class MyString < String # could also have used original String
        include Paint::Example::String
      end

      # MyString.new("J-_-L").red.should == "\e[31;1mJ-_-L\e[0m"
    end

    it 'adds shortcuts methods that colorize self (also works for non-String classes by calling to_s)' do
      Paint::SHORTCUTS[:example][:gold] = Paint.color "gold"
      class Integer
        include Paint::Example::String
      end
      #123.red.should == "\e[38;5;226m123\e[0m"
    end
  end

  context 'include Paint::Example::Prefix::ExampleName' do
    it 'sets a single color helper method to avoid cluttering namespaces' do
      class Object
        include Paint::Example::Prefix::ExampleName
      end
      #"Ruby".example_name(:red).should == "\e[31;1mRuby\e[0m"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
paint-0.8.4 spec/paint_shortcuts_spec.rb
paint-0.8.3 spec/paint_shortcuts_spec.rb
paint-0.8.2 spec/paint_shortcuts_spec.rb
paint-0.8.1 spec/paint_shortcuts_spec.rb
paint-0.8.0 spec/paint_shortcuts_spec.rb