summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Handwell <joelhandwell@gmail.com>2015-08-25 18:08:16 -0400
committerJoel Handwell <joelhandwell@gmail.com>2015-09-02 07:55:21 -0400
commitf2de463a69508cb91e952f3034f7e951c9ab1af7 (patch)
tree4e617d0e950b26b4f5651ce4ae742c9286e1b1bd
parenta4ca79d7a3a6e0a992c9710cbf6c7445534cad44 (diff)
downloadchef-f2de463a69508cb91e952f3034f7e951c9ab1af7.tar.gz
Add unit tests for elapsed_time
-rw-r--r--Gemfile1
-rw-r--r--lib/chef/formatters/doc.rb2
-rw-r--r--spec/unit/formatters/doc_spec.rb35
3 files changed, 37 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index af0bef493c..0f547c1645 100644
--- a/Gemfile
+++ b/Gemfile
@@ -14,6 +14,7 @@ group(:development, :test) do
gem "simplecov"
gem 'rack', "~> 1.5.1"
gem 'cheffish', "~> 1.3"
+ gem 'timecop'
gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(aix|cygwin)/)
end
diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb
index deeb5d3e96..93039d6171 100644
--- a/lib/chef/formatters/doc.rb
+++ b/lib/chef/formatters/doc.rb
@@ -32,7 +32,7 @@ class Chef
elsif time < 3600 then
message = Time.at(time).utc.strftime("%M minutes %S seconds")
else
- message = Time.at(time).utc.strftime("%H hour %M minutes %S seconds")
+ message = Time.at(time).utc.strftime("%H hours %M minutes %S seconds")
end
message
end
diff --git a/spec/unit/formatters/doc_spec.rb b/spec/unit/formatters/doc_spec.rb
index eb98f5abd3..f208508aba 100644
--- a/spec/unit/formatters/doc_spec.rb
+++ b/spec/unit/formatters/doc_spec.rb
@@ -18,12 +18,21 @@
#
require 'spec_helper'
+require 'timecop'
describe Chef::Formatters::Base do
let(:out) { StringIO.new }
let(:err) { StringIO.new }
+ before do
+ Timecop.freeze(Time.local(2008, 9, 9, 9, 9, 9))
+ end
+
+ after do
+ Timecop.return
+ end
+
subject(:formatter) { Chef::Formatters::Doc.new(out, err) }
it "prints a policyfile's name and revision ID" do
@@ -49,4 +58,30 @@ describe Chef::Formatters::Base do
expect(out.string).to include("- apache2 (1.2.3")
end
+ it "prints only seconds when elapsed time is less than 60 seconds" do
+ f = Chef::Formatters::Doc.new(out, err)
+ Timecop.freeze(2008, 9, 9, 9, 9, 19) do
+ f.run_completed(nil)
+ expect(f.elapsed_time).to include("10 seconds")
+ expect(f.elapsed_time).not_to include("minutes")
+ expect(f.elapsed_time).not_to include("hours")
+ end
+ end
+
+ it "prints minutes and seconds when elapsed time is more than 60 seconds" do
+ f = Chef::Formatters::Doc.new(out, err)
+ Timecop.freeze(2008, 9, 9, 9, 19, 19) do
+ f.run_completed(nil)
+ expect(f.elapsed_time).to include("10 minutes 10 seconds")
+ expect(f.elapsed_time).not_to include("hours")
+ end
+ end
+
+ it "prints hours, minutes and seconds when elapsed time is more than 3600 seconds" do
+ f = Chef::Formatters::Doc.new(out, err)
+ Timecop.freeze(2008, 9, 9, 19, 19, 19) do
+ f.run_completed(nil)
+ expect(f.elapsed_time).to include("10 hours 10 minutes 10 seconds")
+ end
+ end
end