2015-09-25 12:07:36 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
describe TimeHelper do
|
2016-08-24 12:49:21 +05:30
|
|
|
describe "#time_interval_in_words" do
|
2015-09-25 12:07:36 +05:30
|
|
|
it "returns minutes and seconds" do
|
|
|
|
intervals_in_words = {
|
|
|
|
100 => "1 minute 40 seconds",
|
2016-08-24 12:49:21 +05:30
|
|
|
100.32 => "1 minute 40 seconds",
|
2015-09-25 12:07:36 +05:30
|
|
|
121 => "2 minutes 1 second",
|
|
|
|
3721 => "62 minutes 1 second",
|
|
|
|
0 => "0 seconds"
|
|
|
|
}
|
|
|
|
|
|
|
|
intervals_in_words.each do |interval, expectation|
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(time_interval_in_words(interval)).to eq(expectation)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe "#duration_in_numbers" do
|
2015-09-25 12:07:36 +05:30
|
|
|
it "returns minutes and seconds" do
|
2016-08-24 12:49:21 +05:30
|
|
|
duration_in_numbers = {
|
|
|
|
[100, 0] => "01:40",
|
|
|
|
[121, 0] => "02:01",
|
|
|
|
[3721, 0] => "01:02:01",
|
|
|
|
[0, 0] => "00:00",
|
|
|
|
[nil, Time.now.to_i - 42] => "00:42"
|
2015-09-25 12:07:36 +05:30
|
|
|
}
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
duration_in_numbers.each do |interval, expectation|
|
|
|
|
expect(duration_in_numbers(*interval)).to eq(expectation)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|