diff options
Diffstat (limited to 'spec/mspec/spec/runner/formatters/html_spec.rb')
-rw-r--r-- | spec/mspec/spec/runner/formatters/html_spec.rb | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/spec/mspec/spec/runner/formatters/html_spec.rb b/spec/mspec/spec/runner/formatters/html_spec.rb index 3783ab6a89..ed973ad93f 100644 --- a/spec/mspec/spec/runner/formatters/html_spec.rb +++ b/spec/mspec/spec/runner/formatters/html_spec.rb @@ -4,22 +4,23 @@ require 'mspec/runner/formatters/html' require 'mspec/runner/mspec' require 'mspec/runner/example' require 'mspec/utils/script' +require 'mspec/helpers' -describe HtmlFormatter do +RSpec.describe HtmlFormatter do before :each do @formatter = HtmlFormatter.new end it "responds to #register by registering itself with MSpec for appropriate actions" do - MSpec.stub(:register) - MSpec.should_receive(:register).with(:start, @formatter) - MSpec.should_receive(:register).with(:enter, @formatter) - MSpec.should_receive(:register).with(:leave, @formatter) + allow(MSpec).to receive(:register) + expect(MSpec).to receive(:register).with(:start, @formatter) + expect(MSpec).to receive(:register).with(:enter, @formatter) + expect(MSpec).to receive(:register).with(:leave, @formatter) @formatter.register end end -describe HtmlFormatter, "#start" do +RSpec.describe HtmlFormatter, "#start" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -32,9 +33,8 @@ describe HtmlFormatter, "#start" do it "prints the HTML head" do @formatter.start ruby_engine = RUBY_ENGINE - ruby_engine.should =~ /^#{ruby_engine}/ - @out.should == -%[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" + expect(ruby_engine).to match(/^#{ruby_engine}/) + expect(@out).to eq(%[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> @@ -55,11 +55,11 @@ ul { </style> </head> <body> -] +]) end end -describe HtmlFormatter, "#enter" do +RSpec.describe HtmlFormatter, "#enter" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -71,11 +71,11 @@ describe HtmlFormatter, "#enter" do it "prints the #describe string" do @formatter.enter "describe" - @out.should == "<div><p>describe</p>\n<ul>\n" + expect(@out).to eq("<div><p>describe</p>\n<ul>\n") end end -describe HtmlFormatter, "#leave" do +RSpec.describe HtmlFormatter, "#leave" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -87,11 +87,11 @@ describe HtmlFormatter, "#leave" do it "prints the closing tags for the #describe string" do @formatter.leave - @out.should == "</ul>\n</div>\n" + expect(@out).to eq("</ul>\n</div>\n") end end -describe HtmlFormatter, "#exception" do +RSpec.describe HtmlFormatter, "#exception" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -108,14 +108,13 @@ describe HtmlFormatter, "#exception" do @formatter.exception exc exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful") @formatter.exception exc - @out.should == -%[<li class="fail">- it (<a href="#details-1">FAILED - 1</a>)</li> + expect(@out).to eq(%[<li class="fail">- it (<a href="#details-1">FAILED - 1</a>)</li> <li class="fail">- it (<a href="#details-2">ERROR - 2</a>)</li> -] +]) end end -describe HtmlFormatter, "#after" do +RSpec.describe HtmlFormatter, "#after" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -129,7 +128,7 @@ describe HtmlFormatter, "#after" do it "prints the #it once when there are no exceptions raised" do @formatter.after @state - @out.should == %[<li class="pass">- it</li>\n] + expect(@out).to eq(%[<li class="pass">- it</li>\n]) end it "does not print any output if an exception is raised" do @@ -137,68 +136,73 @@ describe HtmlFormatter, "#after" do @formatter.exception exc out = @out.dup @formatter.after @state - @out.should == out + expect(@out).to eq(out) end end -describe HtmlFormatter, "#finish" do +RSpec.describe HtmlFormatter, "#finish" do before :each do @tally = double("tally").as_null_object - TallyAction.stub(:new).and_return(@tally) + allow(TallyAction).to receive(:new).and_return(@tally) @timer = double("timer").as_null_object - TimerAction.stub(:new).and_return(@timer) + allow(TimerAction).to receive(:new).and_return(@timer) + + @out = tmp("HtmlFormatter") - $stdout = @out = IOStub.new context = ContextState.new "describe" @state = ExampleState.new(context, "it") - MSpec.stub(:register) - @formatter = HtmlFormatter.new + allow(MSpec).to receive(:register) + @formatter = HtmlFormatter.new(@out) @formatter.register @exception = MSpecExampleError.new("broken") - @exception.stub(:backtrace).and_return(["file.rb:1", "file.rb:2"]) + allow(@exception).to receive(:backtrace).and_return(["file.rb:1", "file.rb:2"]) end after :each do - $stdout = STDOUT + rm_r @out end it "prints a failure message for an exception" do exc = ExceptionState.new @state, nil, @exception @formatter.exception exc @formatter.finish - @out.should include "<p>describe it ERROR</p>" + output = File.read(@out) + expect(output).to include "<p>describe it ERROR</p>" end it "prints a backtrace for an exception" do exc = ExceptionState.new @state, nil, @exception - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.finish - @out.should =~ %r[<pre>.*path/to/some/file.rb:35:in method.*</pre>]m + output = File.read(@out) + expect(output).to match(%r[<pre>.*path/to/some/file.rb:35:in method.*</pre>]m) end it "prints a summary of elapsed time" do - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") @formatter.finish - @out.should include "<p>Finished in 2.0 seconds</p>\n" + output = File.read(@out) + expect(output).to include "<p>Finished in 2.0 seconds</p>\n" end it "prints a tally of counts" do - @tally.should_receive(:format).and_return("1 example, 0 failures") + expect(@tally).to receive(:format).and_return("1 example, 0 failures") @formatter.finish - @out.should include '<p class="pass">1 example, 0 failures</p>' + output = File.read(@out) + expect(output).to include '<p class="pass">1 example, 0 failures</p>' end it "prints errors, backtraces, elapsed time, and tallies" do exc = ExceptionState.new @state, nil, @exception - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") - @tally.should_receive(:format).and_return("1 example, 1 failures") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") + expect(@tally).to receive(:format).and_return("1 example, 1 failures") @formatter.finish - @out.should == -%[<li class=\"fail\">- it (<a href=\"#details-1\">ERROR - 1</a>)</li> + output = File.read(@out) + expect(output).to eq(%[<li class=\"fail\">- it (<a href=\"#details-1\">ERROR - 1</a>)</li> <hr> <ol id="details"> <li id="details-1"><p>describe it ERROR</p> @@ -211,6 +215,6 @@ path/to/some/file.rb:35:in method</pre> <p class="fail">1 example, 1 failures</p> </body> </html> -] +]) end end |