Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. describe DurationHelper, "#format_duration" do
  2. it "returns the correct string for many different durations" do
  3. helper.format_duration(212751).should == "2 days 11 hrs 5 mins 51 secs"
  4. helper.format_duration(79805).should == "22 hrs 10 mins 5 secs"
  5. helper.format_duration(2730).should == "45 mins 30 secs"
  6. helper.format_duration(142800).should == "1 day 15 hrs 40 mins"
  7. helper.format_duration(352800).should == "4 days 2 hrs"
  8. helper.format_duration(345600).should == "4 days"
  9. helper.format_duration(32).should == "32 secs"
  10. helper.format_duration(32.9).should == "32 secs"
  11. helper.format_duration(0).should == "0 seconds"
  12. helper.format_duration(0.5).should == "0 seconds"
  13. end
  14.  
  15. it "excludes least-significant units using the :parts_to_show option"do
  16. helper.format_duration(212751, :parts_to_show => 1).should == "2 days"
  17. helper.format_duration(212751, :parts_to_show => 2).should == "2 days 11 hrs"
  18. helper.format_duration(212751, :parts_to_show => 3).should == "2 days 11 hrs 5 mins"
  19. helper.format_duration(212751, :parts_to_show => 0).should == ""
  20. end
  21.  
  22. it "counts a zero component that's not shown in :parts_to_show" do
  23. # By using :parts_to_show => 3, that means we want days, hours, and minutes;
  24. # but if hours turns out to be zero, then we'll actually just show 2 parts.
  25. helper.format_duration(1.day + 1.minute + 1.second, :parts_to_show => 3).should == "1 day 1 min"
  26. end
  27.  
  28. it "uses short duration words with :word_style => :short" do
  29. helper.format_duration(2730, :word_style => :short).should == "45 mins 30 secs"
  30. end
  31.  
  32. it "uses long duration words with :word_style => :long" do
  33. helper.format_duration(2730, :word_style => :long).should == "45 minutes 30 seconds"
  34. end
  35.  
  36. it "uses a float for a least-significant part in days or hours with :specific_end => true" do
  37. helper.format_duration(352800, :specific_end => true).should == "4 days 2 hrs"
  38. helper.format_duration(352800, :parts_to_show => 1, :specific_end => true).should == "4.1 days"
  39. helper.format_duration(352835, :parts_to_show => 2, :specific_end => true).should == "4 days 2 hrs"
  40. helper.format_duration(79805, :parts_to_show => 1, :specific_end => true).should == "22.2 hrs"
  41. helper.format_duration(79805, :parts_to_show => 2, :specific_end => true).should == "22 hrs 10 mins"
  42. helper.format_duration(79805, :parts_to_show => 3, :specific_end => true).should == "22 hrs 10 mins 5 secs"
  43. helper.format_duration(79200, :parts_to_show => 1, :specific_end => true).should == "22 hrs"
  44. end
  45. end
Add Comment
Please, Sign In to add comment