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 it "should be able to convert to a currency string" do 123423.to_currency.should == "$123,423.00" 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 it "should be able to convert to a currency string" do 123423.5673.to_currency.should == "$123,423.57" 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 describe Array do describe "flat file conversions" do before :all do @array = ["one", "two","three"] end it "can do flat file string conversions with default values" do @array.to_flat_file_row.should == "one,two,three" end it "can do flat file string conversions with options" do @array.to_flat_file_row(:delimeter => '|', :enclosed_by => '"').should == %q{"one"|"two"|"three"} end end end describe String do it "can generate a string of lower case characters of length" do String.random_of_length(4).should match(/[a-z]{4}/) end end