2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-09-29 10:26:40 -04:00
|
|
|
describe TimeHelper do
|
2015-08-25 21:42:46 -04:00
|
|
|
describe "#duration_in_words" do
|
|
|
|
it "returns minutes and seconds" do
|
|
|
|
intervals_in_words = {
|
|
|
|
100 => "1 minute 40 seconds",
|
|
|
|
121 => "2 minutes 1 second",
|
|
|
|
3721 => "62 minutes 1 second",
|
|
|
|
0 => "0 seconds"
|
|
|
|
}
|
|
|
|
|
|
|
|
intervals_in_words.each do |interval, expectation|
|
2015-09-15 15:24:57 -04:00
|
|
|
expect(duration_in_words(Time.now + interval, Time.now)).to eq(expectation)
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calculates interval from now if there is no finished_at" do
|
2015-09-15 15:24:57 -04:00
|
|
|
expect(duration_in_words(nil, Time.now - 5)).to eq("5 seconds")
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#time_interval_in_words" do
|
|
|
|
it "returns minutes and seconds" do
|
|
|
|
intervals_in_words = {
|
|
|
|
100 => "1 minute 40 seconds",
|
|
|
|
121 => "2 minutes 1 second",
|
|
|
|
3721 => "62 minutes 1 second",
|
|
|
|
0 => "0 seconds"
|
|
|
|
}
|
|
|
|
|
|
|
|
intervals_in_words.each do |interval, expectation|
|
2015-09-15 15:24:57 -04:00
|
|
|
expect(time_interval_in_words(interval)).to eq(expectation)
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|