Sha256: 88b53e29ec48404e1c55a0f4d78cabdec074832a8d77fddca4675540dad258f3

Contents?: true

Size: 1.01 KB

Versions: 26

Compression:

Stored size: 1.01 KB

Contents

require 'simple_spec_helper'

describe Lolita::Support::Formatter do
  let(:klass){Lolita::Support::Formatter}

  context "create new" do

    it "should accept value as format" do
      formatter=klass.new("%Y-%m")
      formatter.format.should == "%Y-%m"
    end

    it "should accept block" do
      formatter=klass.new do |value|
        value**2
      end
      formatter.block.should_not be_nil
    end
  end

  context "calling formatter" do
    it "should call block" do
      formatter=klass.new do |value|
        value.to_i+1
      end
      formatter.with(2).should == 3
    end

    it "should try to call #format method on given value" do
      formatter = klass.new("M")
      object = double
      object.stub(:format).and_return(1)
      object.stub(:respond_to?).with(:format).and_return(true)
      formatter.with(object).should == 1
    end

    it "should convert received value to string and call #unpack" do
      formatter=klass.new("%.3f")
      formatter.with(44.88).should == "44.880"
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
lolita-4.0.11 spec/support/formatter_spec.rb
lolita-4.2.0 spec/support/formatter_spec.rb
lolita-4.0.10 spec/support/formatter_spec.rb
lolita-4.0.9 spec/support/formatter_spec.rb
lolita-4.0.8 spec/support/formatter_spec.rb
lolita-4.0.7 spec/support/formatter_spec.rb
lolita-4.0.6 spec/support/formatter_spec.rb
lolita-4.0.5 spec/support/formatter_spec.rb
lolita-4.0.4 spec/support/formatter_spec.rb
lolita-4.0.3 spec/support/formatter_spec.rb
lolita-4.0.2 spec/support/formatter_spec.rb
lolita-4.0.1 spec/support/formatter_spec.rb
lolita-4.0.0 spec/support/formatter_spec.rb
lolita-3.4.3 spec/support/formatter_spec.rb
lolita-3.4.2 spec/support/formatter_spec.rb
lolita-3.4.1 spec/support/formatter_spec.rb
lolita-3.4.0 spec/support/formatter_spec.rb
lolita-3.3.9 spec/support/formatter_spec.rb
lolita-3.3.8 spec/support/formatter_spec.rb
lolita-3.3.7 spec/support/formatter_spec.rb