2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-09-29 10:26:40 -04:00
|
|
|
describe TimeHelper do
|
2016-07-18 10:44:10 -04:00
|
|
|
describe "#time_interval_in_words" do
|
2015-08-25 21:42:46 -04:00
|
|
|
it "returns minutes and seconds" do
|
|
|
|
intervals_in_words = {
|
2018-07-10 06:49:28 -04:00
|
|
|
60 => "1 minute",
|
|
|
|
100 => "1 minute and 40 seconds",
|
|
|
|
100.32 => "1 minute and 40 seconds",
|
|
|
|
120 => "2 minutes",
|
|
|
|
121 => "2 minutes and 1 second",
|
|
|
|
3721 => "62 minutes and 1 second",
|
2015-08-25 21:42:46 -04:00
|
|
|
0 => "0 seconds"
|
|
|
|
}
|
|
|
|
|
|
|
|
intervals_in_words.each do |interval, expectation|
|
2016-07-18 10:44:10 -04:00
|
|
|
expect(time_interval_in_words(interval)).to eq(expectation)
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-18 10:44:10 -04:00
|
|
|
describe "#duration_in_numbers" do
|
2018-09-27 07:44:03 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2018-10-10 01:27:16 -04:00
|
|
|
where(:duration, :formatted_string) do
|
|
|
|
0 | "00:00"
|
|
|
|
1.second | "00:01"
|
|
|
|
42.seconds | "00:42"
|
|
|
|
2.minutes + 1.second | "02:01"
|
|
|
|
3.hours + 2.minutes + 1.second | "03:02:01"
|
|
|
|
30.hours | "30:00:00"
|
2018-09-27 07:44:03 -04:00
|
|
|
end
|
|
|
|
|
2018-10-10 01:27:16 -04:00
|
|
|
with_them do
|
|
|
|
it { expect(duration_in_numbers(duration)).to eq formatted_string }
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|