diff options
author | Joel Handwell <joelhandwell@gmail.com> | 2015-09-01 17:32:16 -0400 |
---|---|---|
committer | Joel Handwell <joelhandwell@gmail.com> | 2015-09-02 07:55:27 -0400 |
commit | 51e98c798e455c9e758d9ace22d1391b7aad596c (patch) | |
tree | 8dc8d624c6a8e1a5290e56d684d645e659cdf18b | |
parent | 850bded619ac14e62bed15b85cc34d6ef3b99202 (diff) | |
download | chef-51e98c798e455c9e758d9ace22d1391b7aad596c.tar.gz |
Remove Timecop dependency
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | lib/chef/formatters/doc.rb | 2 | ||||
-rw-r--r-- | spec/unit/formatters/doc_spec.rb | 47 |
3 files changed, 20 insertions, 30 deletions
@@ -14,7 +14,6 @@ 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 2b0161667b..70108f547b 100644 --- a/lib/chef/formatters/doc.rb +++ b/lib/chef/formatters/doc.rb @@ -33,7 +33,7 @@ class Chef time = elapsed_time if time < 60 then message = Time.at(time).utc.strftime("%S seconds") - elsif time < 3600 then + elsif time < 3600 then message = Time.at(time).utc.strftime("%M minutes %S seconds") else message = Time.at(time).utc.strftime("%H hours %M minutes %S seconds") diff --git a/spec/unit/formatters/doc_spec.rb b/spec/unit/formatters/doc_spec.rb index 7db5ebc348..7266afc320 100644 --- a/spec/unit/formatters/doc_spec.rb +++ b/spec/unit/formatters/doc_spec.rb @@ -18,22 +18,13 @@ # require 'spec_helper' -require 'timecop' describe Chef::Formatters::Base do let(:out) { StringIO.new } let(:err) { StringIO.new } - after do - Timecop.return - end - - subject(:formatter) { - Timecop.freeze(Time.local(2008, 9, 9, 9, 9, 9)) do - Chef::Formatters::Doc.new(out, err) - end - } + subject(:formatter) { Chef::Formatters::Doc.new(out, err) } it "prints a policyfile's name and revision ID" do minimal_policyfile = { @@ -59,29 +50,29 @@ describe Chef::Formatters::Base do end it "prints only seconds when elapsed time is less than 60 seconds" do - Timecop.freeze(2008, 9, 9, 9, 9, 19) do - 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 + @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 - Timecop.freeze(2008, 9, 9, 9, 19, 19) do - 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 + @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 - Timecop.freeze(2008, 9, 9, 19, 19, 19) do - 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 + @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 |