summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-09-02 13:46:53 +0100
committerThom May <thom@may.lt>2015-09-02 13:46:53 +0100
commitc89c0a4e91d9c80c3d48f40e559ee30aa6051843 (patch)
treeac868385fd147b31256fccc999e2705f17eeff52 /spec
parent1c9eaf7491565742ea3fdbb560278ff606f6f901 (diff)
parent51e98c798e455c9e758d9ace22d1391b7aad596c (diff)
downloadchef-c89c0a4e91d9c80c3d48f40e559ee30aa6051843.tar.gz
Merge pull request #3821 from joelhandwell/elapsed_time
Human friendly elapsed time in log
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/formatters/doc_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/unit/formatters/doc_spec.rb b/spec/unit/formatters/doc_spec.rb
index eb98f5abd3..7266afc320 100644
--- a/spec/unit/formatters/doc_spec.rb
+++ b/spec/unit/formatters/doc_spec.rb
@@ -49,4 +49,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
+ @now = Time.now
+ allow(Time).to receive(:now).and_return(@now, @now + 10.0)
+ formatter.run_completed(nil)
+ expect(formatter.elapsed_time).to eql(10.0)
+ expect(formatter.pretty_elapsed_time).to include("10 seconds")
+ expect(formatter.pretty_elapsed_time).not_to include("minutes")
+ expect(formatter.pretty_elapsed_time).not_to include("hours")
+ end
+
+ it "prints minutes and seconds when elapsed time is more than 60 seconds" do
+ @now = Time.now
+ allow(Time).to receive(:now).and_return(@now, @now + 610.0)
+ formatter.run_completed(nil)
+ expect(formatter.elapsed_time).to eql(610.0)
+ expect(formatter.pretty_elapsed_time).to include("10 minutes 10 seconds")
+ expect(formatter.pretty_elapsed_time).not_to include("hours")
+ end
+
+ it "prints hours, minutes and seconds when elapsed time is more than 3600 seconds" do
+ @now = Time.now
+ allow(Time).to receive(:now).and_return(@now, @now + 36610.0)
+ formatter.run_completed(nil)
+ expect(formatter.elapsed_time).to eql(36610.0)
+ expect(formatter.pretty_elapsed_time).to include("10 hours 10 minutes 10 seconds")
+ end
end