Sha256: 665228debaaf46e82eceb46e57b2b09b89af848fc6cabe449400b76ec409fe27

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

describe "Ppl::Format::Custom" do

  describe "::format" do
    it "should accept a symbol and a block" do
      Ppl::Format::Custom::format :N do |h| h[:name] end
    end
  end

  describe "::process" do
    it "should use the block passed to ::format to process the object" do
      expect(Ppl::Format::Custom::process(:N, {:name => "jdoe"})).to eq "jdoe"
    end
  end

  describe "#initialize" do
    it "should accept a format string" do
      expect(Ppl::Format::Custom.new("%N").format).to eq "%N"
    end
  end

  describe "#process" do
    it "should convert the given object into a string based on the format" do
      custom = Ppl::Format::Custom.new("%N %N %N")
      object = { :name => "jdoe" }
      expect(custom.process(object)).to eq "jdoe jdoe jdoe"
    end
    it "should pad with leading spaces if a positive width is given" do
      custom = Ppl::Format::Custom.new("%10N")
      object = { :name => "jdoe" }
      expect(custom.process(object)).to eq "      jdoe"
    end
    it "should pad with trailing spaces if a negative width is given" do
      custom = Ppl::Format::Custom.new("%-10N")
      object = { :name => "jdoe" }
      expect(custom.process(object)).to eq "jdoe      "
    end
  end

  describe "#use_preset" do
    it "should set the format string to the preset with the given name" do
      custom = Ppl::Format::Custom.new
      custom.preset_formats = { "example" => "%N (%N)" }
      custom.use_preset "example"
      expect(custom.process({:name => "a"})).to eq "a (a)"
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ppl-4.0.5 spec/ppl/format/custom_spec.rb
ppl-4.0.3 spec/ppl/format/custom_spec.rb
ppl-4.0.2 spec/ppl/format/custom_spec.rb