diff options
author | Joel Handwell <joelhandwell@gmail.com> | 2015-08-25 18:08:16 -0400 |
---|---|---|
committer | Joel Handwell <joelhandwell@gmail.com> | 2015-09-02 07:55:21 -0400 |
commit | f2de463a69508cb91e952f3034f7e951c9ab1af7 (patch) | |
tree | 4e617d0e950b26b4f5651ce4ae742c9286e1b1bd | |
parent | a4ca79d7a3a6e0a992c9710cbf6c7445534cad44 (diff) | |
download | chef-f2de463a69508cb91e952f3034f7e951c9ab1af7.tar.gz |
Add unit tests for elapsed_time
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | lib/chef/formatters/doc.rb | 2 | ||||
-rw-r--r-- | spec/unit/formatters/doc_spec.rb | 35 |
3 files changed, 37 insertions, 1 deletions
@@ -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 |