Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe DurationHelper, "#format_duration" do
- it "returns the correct string for many different durations" do
- helper.format_duration(212751).should == "2 days 11 hrs 5 mins 51 secs"
- helper.format_duration(79805).should == "22 hrs 10 mins 5 secs"
- helper.format_duration(2730).should == "45 mins 30 secs"
- helper.format_duration(142800).should == "1 day 15 hrs 40 mins"
- helper.format_duration(352800).should == "4 days 2 hrs"
- helper.format_duration(345600).should == "4 days"
- helper.format_duration(32).should == "32 secs"
- helper.format_duration(32.9).should == "32 secs"
- helper.format_duration(0).should == "0 seconds"
- helper.format_duration(0.5).should == "0 seconds"
- end
- it "excludes least-significant units using the :parts_to_show option"do
- helper.format_duration(212751, :parts_to_show => 1).should == "2 days"
- helper.format_duration(212751, :parts_to_show => 2).should == "2 days 11 hrs"
- helper.format_duration(212751, :parts_to_show => 3).should == "2 days 11 hrs 5 mins"
- helper.format_duration(212751, :parts_to_show => 0).should == ""
- end
- it "counts a zero component that's not shown in :parts_to_show" do
- # By using :parts_to_show => 3, that means we want days, hours, and minutes;
- # but if hours turns out to be zero, then we'll actually just show 2 parts.
- helper.format_duration(1.day + 1.minute + 1.second, :parts_to_show => 3).should == "1 day 1 min"
- end
- it "uses short duration words with :word_style => :short" do
- helper.format_duration(2730, :word_style => :short).should == "45 mins 30 secs"
- end
- it "uses long duration words with :word_style => :long" do
- helper.format_duration(2730, :word_style => :long).should == "45 minutes 30 seconds"
- end
- it "uses a float for a least-significant part in days or hours with :specific_end => true" do
- helper.format_duration(352800, :specific_end => true).should == "4 days 2 hrs"
- helper.format_duration(352800, :parts_to_show => 1, :specific_end => true).should == "4.1 days"
- helper.format_duration(352835, :parts_to_show => 2, :specific_end => true).should == "4 days 2 hrs"
- helper.format_duration(79805, :parts_to_show => 1, :specific_end => true).should == "22.2 hrs"
- helper.format_duration(79805, :parts_to_show => 2, :specific_end => true).should == "22 hrs 10 mins"
- helper.format_duration(79805, :parts_to_show => 3, :specific_end => true).should == "22 hrs 10 mins 5 secs"
- helper.format_duration(79200, :parts_to_show => 1, :specific_end => true).should == "22 hrs"
- end
- end
Add Comment
Please, Sign In to add comment