summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Handwell <joelhandwell@gmail.com>2015-08-25 19:05:04 -0400
committerJoel Handwell <joelhandwell@gmail.com>2015-09-02 07:55:23 -0400
commit5f6589f3c05c965d3c555613bf21c635978a36be (patch)
tree941ea63042e4c4145c8d33a0731aef20f6d174dc
parentf2de463a69508cb91e952f3034f7e951c9ab1af7 (diff)
downloadchef-5f6589f3c05c965d3c555613bf21c635978a36be.tar.gz
Refactor to reduce duplicated instancialization
-rw-r--r--spec/unit/formatters/doc_spec.rb31
1 files changed, 14 insertions, 17 deletions
diff --git a/spec/unit/formatters/doc_spec.rb b/spec/unit/formatters/doc_spec.rb
index f208508aba..15af595020 100644
--- a/spec/unit/formatters/doc_spec.rb
+++ b/spec/unit/formatters/doc_spec.rb
@@ -25,15 +25,15 @@ 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) }
+ subject(:formatter) {
+ Timecop.freeze(Time.local(2008, 9, 9, 9, 9, 9)) do
+ Chef::Formatters::Doc.new(out, err)
+ end
+ }
it "prints a policyfile's name and revision ID" do
minimal_policyfile = {
@@ -59,29 +59,26 @@ describe Chef::Formatters::Base do
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")
+ formatter.run_completed(nil)
+ expect(formatter.elapsed_time).to include("10 seconds")
+ expect(formatter.elapsed_time).not_to include("minutes")
+ expect(formatter.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")
+ formatter.run_completed(nil)
+ expect(formatter.elapsed_time).to include("10 minutes 10 seconds")
+ expect(formatter.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")
+ formatter.run_completed(nil)
+ expect(formatter.elapsed_time).to include("10 hours 10 minutes 10 seconds")
end
end
end