Sha256: eb0902405c5cdb07e0a065df04f207c2b711e8993b92032919ae2f5eba038c02

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 KB

Contents

require "spec_helper"


describe Shamu::ToBoolExtension do
  before( :each ) do
    Shamu::ToBoolExtension.extend!
  end

  describe Shamu::ToBoolExtension::Strings do
    {
      "1"     => true,
      "0"     => false,
      "true"  => true,
      "false" => false,
      ""      => false,
      "True"  => true,
      "False" => false,
      "T"     => true,
      "F"     => false,
      "Yes"   => true,
      "No"    => false,
      "Y"     => true,
      "N"     => false,
    }.each do |candidate, expected|
      it "converts '#{ candidate }' to #{ expected }" do
        expect( candidate.to_bool ).to eq expected
      end
    end

    it "uses default for no-match" do
      expect( "Random".to_bool( :nope ) ).to eq :nope
    end
  end

  describe Shamu::ToBoolExtension::Integers do
    {
      1    => true,
      0    => false
    }.each do |candidate, expected|
      it "converts '#{ candidate }' to #{ expected }" do
        expect( candidate.to_bool ).to eq expected
      end
    end

    it "uses default for no-match" do
      expect( 100.to_bool( :nope ) ).to eq :nope
    end
  end

  describe Shamu::ToBoolExtension::Boolean do
    {
      true  => true,
      false => false,
    }.each do |candidate, expected|
      it "converts '#{ candidate }' to #{ expected }" do
        expect( candidate.to_bool ).to eq expected
      end
    end
  end

  describe Shamu::ToBoolExtension::Nil do
    it "uses default" do
      expect( nil.to_bool( :whatever ) ).to eq( :whatever )
    end
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.21 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.20 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.19 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.18 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.17 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.15 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.14 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.13 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.11 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.9 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.8 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.7 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.5 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.4 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.3 spec/lib/shamu/to_bool_extension_spec.rb
shamu-0.0.2 spec/lib/shamu/to_bool_extension_spec.rb