Sha256: b61d0a39fa1d2c0396bdf9af791b24028a00e23aae488e1836efeba0f51405ce

Contents?: true

Size: 1.64 KB

Versions: 17

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

include TablePrint

describe TablePrint::TimeFormatter do
  describe "#format" do
    it "only operates on Time objects" do
      f = TablePrint::TimeFormatter.new
      f.format(12).should == 12
    end

    it "uses the config'd time_format" do
      f = TablePrint::TimeFormatter.new
      time = Time.local(2012, 01, 11, 1, 23, 45)
      f.format(time).should == "2012-01-11 01:23:45" # default time format is set in config.rb
    end

    it "overrides the config'd time format with one it was passed" do
      f = TablePrint::TimeFormatter.new("%Y")
      time = Time.local(2012, 01, 11, 1, 23, 45)
      f.format(time).should == "2012" # default time format is set in config.rb
    end
  end
end

describe TablePrint::NoNewlineFormatter do
  before(:each) do
    @f = TablePrint::NoNewlineFormatter.new
  end

  describe "#format" do
    it "replaces carriage returns with spaces" do
      @f.format("foo\r\nbar").should == "foo bar"
    end

    it "replaces newlines with spaces" do
      @f.format("foo\nbar").should == "foo bar"
    end
  end
end

describe TablePrint::FixedWidthFormatter do
  before(:each) do
    @f = TablePrint::FixedWidthFormatter.new(10)
  end

  describe "#format" do
    it "pads a short field to the specified width" do
      @f.format("asdf").should == "asdf      "
    end

    it "truncates long fields with periods" do
      @f.format("1234567890123456").should == "1234567..."
    end

    it "uses an empty string in place of nils" do
      @f.format(nil).should == "          "
    end

    it "turns objects into strings before trying to format them" do
      @f.format(123).should == "123       "
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
table_print-1.5.7 spec/formatter_spec.rb
table_print-1.5.6 spec/formatter_spec.rb
table_print-1.5.5 spec/formatter_spec.rb
table_print-1.5.4 spec/formatter_spec.rb
table_print-1.5.3 spec/formatter_spec.rb
table_print-1.5.2 spec/formatter_spec.rb
table_print-1.5.1 spec/formatter_spec.rb
table_print-1.5.0 spec/formatter_spec.rb
table_print-1.4.1 spec/formatter_spec.rb
table_print-1.4.0 spec/formatter_spec.rb
table_print-1.3.3 spec/formatter_spec.rb
table_print-1.3.2 spec/formatter_spec.rb
table_print-1.3.1 spec/formatter_spec.rb
table_print-1.3.0 spec/formatter_spec.rb
table_print-1.2.0 spec/formatter_spec.rb
table_print-1.1.5 spec/formatter_spec.rb
table_print-1.1.4 spec/formatter_spec.rb