Sha256: 0fc86aa76051a69424488b010586c81a647e8fff1ba2d2962c516bcbba1653a1

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

describe Hash do
  it "limit_to_keys should limit keys in hash" do
    h = {:bro1=>'me',:bro2=>'rob',:bro3=>'eric'}
    h.limit_to_keys([:bro1,:bro2]).should == {:bro1=>'me',:bro2=>'rob'}
    h.should == {:bro1=>'me',:bro2=>'rob',:bro3=>'eric'}
  end

  it "limit_to_keys! should destructively limit keys in hash" do
    h = {:bro1=>'me',:bro2=>'rob',:bro3=>'eric'}
    h.limit_to_keys!([:bro1,:bro2]).should == {:bro1=>'me',:bro2=>'rob'}
    h.should == {:bro1=>'me',:bro2=>'rob'}
  end

  it "soft deletes" do
    h = {:dan=>1,:eric=>2}
    h.soft_delete(:dan).should == {:eric=>2}
  end

  it "merge_add_values should add values with same key" do
    h = {:e=>[1],:f=>3}
    h2 = {:e=>[2],:f=>22}
    h.merge_add_values(h2).should == {:e=>[1,2],:f=>25}
  end
end

describe Integer do
  it "should return the number divided by 100 as a float" do
    i = 1000043
    i.as_cost.should == 10000.43
  end

  it "should return the number in hundredths" do
    i = 10343
    i.in_hundredths.should == 172.38
  end
end

describe Float do
  it "should return the number divided by 100" do
    i = 1000043.0
    i.as_cost.should == 10000.430
  end

  it "should return the number in hundredths" do
    i = 10343.56
    i.in_hundredths.should == 172.39
  end
end

describe Range do
  it "method split_by_step creates ranges out of original range by step" do
    range = 0..30
    range.split_by_step(10).should == [0..10,11..21,22..30]
    range = 1..101
    range.split_by_step(25).should == [1..26,27..52,53..78,79..101]
    range = 0..20
    range.split_by_step(20).should == [0..20]
    range = 1..2
    range.split_by_step(3).should == [1..2]
    range = 1..1
    range.split_by_step(10).should == [1..1]
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fossil-0.5.40 spec/core_extensions_spec.rb
fossil-0.5.39 spec/core_extensions_spec.rb
fossil-0.5.38 spec/core_extensions_spec.rb
fossil-0.5.37 spec/core_extensions_spec.rb
fossil-0.5.36 spec/core_extensions_spec.rb
fossil-0.5.35 spec/core_extensions_spec.rb
fossil-0.5.34 spec/core_extensions_spec.rb
fossil-0.5.33 spec/core_extensions_spec.rb