summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/runner/formatters
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/spec/runner/formatters')
-rw-r--r--spec/mspec/spec/runner/formatters/describe_spec.rb24
-rw-r--r--spec/mspec/spec/runner/formatters/dotted_spec.rb119
-rw-r--r--spec/mspec/spec/runner/formatters/file_spec.rb34
-rw-r--r--spec/mspec/spec/runner/formatters/html_spec.rb88
-rw-r--r--spec/mspec/spec/runner/formatters/junit_spec.rb100
-rw-r--r--spec/mspec/spec/runner/formatters/method_spec.rb69
-rw-r--r--spec/mspec/spec/runner/formatters/multi_spec.rb20
-rw-r--r--spec/mspec/spec/runner/formatters/specdoc_spec.rb30
-rw-r--r--spec/mspec/spec/runner/formatters/spinner_spec.rb32
-rw-r--r--spec/mspec/spec/runner/formatters/summary_spec.rb4
-rw-r--r--spec/mspec/spec/runner/formatters/unit_spec.rb33
-rw-r--r--spec/mspec/spec/runner/formatters/yaml_spec.rb79
12 files changed, 326 insertions, 306 deletions
diff --git a/spec/mspec/spec/runner/formatters/describe_spec.rb b/spec/mspec/spec/runner/formatters/describe_spec.rb
index 415ced71fb..55f497aca6 100644
--- a/spec/mspec/spec/runner/formatters/describe_spec.rb
+++ b/spec/mspec/spec/runner/formatters/describe_spec.rb
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/describe'
require 'mspec/runner/example'
-describe DescribeFormatter, "#finish" do
+RSpec.describe DescribeFormatter, "#finish" do
before :each do
- MSpec.stub(:register)
- MSpec.stub(:unregister)
+ allow(MSpec).to receive(:register)
+ allow(MSpec).to receive(:unregister)
@timer = double("timer").as_null_object
- TimerAction.stub(:new).and_return(@timer)
- @timer.stub(:format).and_return("Finished in 2.0 seconds")
+ allow(TimerAction).to receive(:new).and_return(@timer)
+ allow(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
$stdout = @out = IOStub.new
context = ContextState.new "Class#method"
@@ -32,36 +32,36 @@ describe DescribeFormatter, "#finish" do
it "prints a summary of elapsed time" do
@formatter.finish
- @out.should =~ /^Finished in 2.0 seconds$/
+ expect(@out).to match(/^Finished in 2.0 seconds$/)
end
it "prints a tally of counts" do
@formatter.finish
- @out.should =~ /^1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged$/
+ expect(@out).to match(/^1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged$/)
end
it "does not print exceptions" do
@formatter.finish
- @out.should == %[
+ expect(@out).to eq(%[
Finished in 2.0 seconds
1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged
-]
+])
end
it "prints a summary of failures and errors for each describe block" do
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
- 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 == %[
+ expect(@out).to eq(%[
Class#method 0 failures, 1 error
Finished in 2.0 seconds
1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged
-]
+])
end
end
diff --git a/spec/mspec/spec/runner/formatters/dotted_spec.rb b/spec/mspec/spec/runner/formatters/dotted_spec.rb
index 5af2ff55f8..336b1227ed 100644
--- a/spec/mspec/spec/runner/formatters/dotted_spec.rb
+++ b/spec/mspec/spec/runner/formatters/dotted_spec.rb
@@ -4,7 +4,7 @@ require 'mspec/runner/mspec'
require 'mspec/runner/example'
require 'mspec/utils/script'
-describe DottedFormatter, "#initialize" do
+RSpec.describe DottedFormatter, "#initialize" do
it "permits zero arguments" do
DottedFormatter.new
end
@@ -14,33 +14,33 @@ describe DottedFormatter, "#initialize" do
end
end
-describe DottedFormatter, "#register" do
+RSpec.describe DottedFormatter, "#register" do
before :each do
@formatter = DottedFormatter.new
- MSpec.stub(:register)
+ allow(MSpec).to receive(:register)
end
it "registers self with MSpec for appropriate actions" do
- MSpec.should_receive(:register).with(:exception, @formatter)
- MSpec.should_receive(:register).with(:before, @formatter)
- MSpec.should_receive(:register).with(:after, @formatter)
- MSpec.should_receive(:register).with(:finish, @formatter)
+ expect(MSpec).to receive(:register).with(:exception, @formatter)
+ expect(MSpec).to receive(:register).with(:before, @formatter)
+ expect(MSpec).to receive(:register).with(:after, @formatter)
+ expect(MSpec).to receive(:register).with(:finish, @formatter)
@formatter.register
end
it "creates TimerAction and TallyAction" do
timer = double("timer")
tally = double("tally")
- timer.should_receive(:register)
- tally.should_receive(:register)
- tally.should_receive(:counter)
- TimerAction.should_receive(:new).and_return(timer)
- TallyAction.should_receive(:new).and_return(tally)
+ expect(timer).to receive(:register)
+ expect(tally).to receive(:register)
+ expect(tally).to receive(:counter)
+ expect(TimerAction).to receive(:new).and_return(timer)
+ expect(TallyAction).to receive(:new).and_return(tally)
@formatter.register
end
end
-describe DottedFormatter, "#print" do
+RSpec.describe DottedFormatter, "#print" do
before :each do
$stdout = IOStub.new
end
@@ -52,25 +52,25 @@ describe DottedFormatter, "#print" do
it "writes to $stdout by default" do
formatter = DottedFormatter.new
formatter.print "begonias"
- $stdout.should == "begonias"
+ expect($stdout).to eq("begonias")
end
it "writes to the file specified when the formatter was created" do
out = IOStub.new
- File.should_receive(:open).with("some/file", "w").and_return(out)
+ expect(File).to receive(:open).with("some/file", "w").and_return(out)
formatter = DottedFormatter.new "some/file"
formatter.print "begonias"
- out.should == "begonias"
+ expect(out).to eq("begonias")
end
it "flushes the IO output" do
- $stdout.should_receive(:flush)
+ expect($stdout).to receive(:flush)
formatter = DottedFormatter.new
formatter.print "begonias"
end
end
-describe DottedFormatter, "#exception" do
+RSpec.describe DottedFormatter, "#exception" do
before :each do
@formatter = DottedFormatter.new
@failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed")
@@ -79,27 +79,27 @@ describe DottedFormatter, "#exception" do
it "sets the #failure? flag" do
@formatter.exception @failure
- @formatter.failure?.should be_true
+ expect(@formatter.failure?).to be_truthy
@formatter.exception @error
- @formatter.failure?.should be_false
+ expect(@formatter.failure?).to be_falsey
end
it "sets the #exception? flag" do
@formatter.exception @error
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
@formatter.exception @failure
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
end
it "adds the exception to the list of exceptions" do
- @formatter.exceptions.should == []
+ expect(@formatter.exceptions).to eq([])
@formatter.exception @error
@formatter.exception @failure
- @formatter.exceptions.should == [@error, @failure]
+ expect(@formatter.exceptions).to eq([@error, @failure])
end
end
-describe DottedFormatter, "#exception?" do
+RSpec.describe DottedFormatter, "#exception?" do
before :each do
@formatter = DottedFormatter.new
@failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed")
@@ -107,29 +107,29 @@ describe DottedFormatter, "#exception?" do
end
it "returns false if there have been no exceptions" do
- @formatter.exception?.should be_false
+ expect(@formatter.exception?).to be_falsey
end
it "returns true if any exceptions are errors" do
@formatter.exception @failure
@formatter.exception @error
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
end
it "returns true if all exceptions are failures" do
@formatter.exception @failure
@formatter.exception @failure
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
end
it "returns true if all exceptions are errors" do
@formatter.exception @error
@formatter.exception @error
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
end
end
-describe DottedFormatter, "#failure?" do
+RSpec.describe DottedFormatter, "#failure?" do
before :each do
@formatter = DottedFormatter.new
@failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed")
@@ -137,23 +137,23 @@ describe DottedFormatter, "#failure?" do
end
it "returns false if there have been no exceptions" do
- @formatter.failure?.should be_false
+ expect(@formatter.failure?).to be_falsey
end
it "returns false if any exceptions are errors" do
@formatter.exception @failure
@formatter.exception @error
- @formatter.failure?.should be_false
+ expect(@formatter.failure?).to be_falsey
end
it "returns true if all exceptions are failures" do
@formatter.exception @failure
@formatter.exception @failure
- @formatter.failure?.should be_true
+ expect(@formatter.failure?).to be_truthy
end
end
-describe DottedFormatter, "#before" do
+RSpec.describe DottedFormatter, "#before" do
before :each do
@state = ExampleState.new ContextState.new("describe"), "it"
@formatter = DottedFormatter.new
@@ -161,19 +161,19 @@ describe DottedFormatter, "#before" do
end
it "resets the #failure? flag to false" do
- @formatter.failure?.should be_true
+ expect(@formatter.failure?).to be_truthy
@formatter.before @state
- @formatter.failure?.should be_false
+ expect(@formatter.failure?).to be_falsey
end
it "resets the #exception? flag to false" do
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
@formatter.before @state
- @formatter.exception?.should be_false
+ expect(@formatter.exception?).to be_falsey
end
end
-describe DottedFormatter, "#after" do
+RSpec.describe DottedFormatter, "#after" do
before :each do
$stdout = @out = IOStub.new
@formatter = DottedFormatter.new
@@ -186,21 +186,21 @@ describe DottedFormatter, "#after" do
it "prints a '.' if there was no exception raised" do
@formatter.after(@state)
- @out.should == "."
+ expect(@out).to eq(".")
end
it "prints an 'F' if there was an expectation failure" do
exc = SpecExpectationNotMetError.new "failed"
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.after(@state)
- @out.should == "F"
+ expect(@out).to eq("F")
end
it "prints an 'E' if there was an exception other than expectation failure" do
exc = MSpecExampleError.new("boom!")
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.after(@state)
- @out.should == "E"
+ expect(@out).to eq("E")
end
it "prints an 'E' if there are mixed exceptions and exepctation failures" do
@@ -209,21 +209,21 @@ describe DottedFormatter, "#after" do
exc = MSpecExampleError.new("boom!")
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.after(@state)
- @out.should == "E"
+ expect(@out).to eq("E")
end
end
-describe DottedFormatter, "#finish" do
+RSpec.describe DottedFormatter, "#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)
$stdout = @out = IOStub.new
context = ContextState.new "Class#method"
@state = ExampleState.new(context, "runs")
- MSpec.stub(:register)
+ allow(MSpec).to receive(:register)
@formatter = DottedFormatter.new
@formatter.register
end
@@ -237,40 +237,39 @@ describe DottedFormatter, "#finish" do
@formatter.exception exc
@formatter.after @state
@formatter.finish
- @out.should =~ /^1\)\nClass#method runs ERROR$/
+ expect(@out).to match(/^1\)\nClass#method runs ERROR$/)
end
it "prints a backtrace for an exception" do
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
- 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.after @state
@formatter.finish
- @out.should =~ %r[path/to/some/file.rb:35:in method$]
+ expect(@out).to match(%r[path/to/some/file.rb:35:in method$])
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 =~ /^Finished in 2.0 seconds$/
+ expect(@out).to match(/^Finished in 2.0 seconds$/)
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 =~ /^1 example, 0 failures$/
+ expect(@out).to match(/^1 example, 0 failures$/)
end
it "prints errors, backtraces, elapsed time, and tallies" do
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
- 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 failure")
+ expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
+ expect(@tally).to receive(:format).and_return("1 example, 1 failure")
@formatter.after @state
@formatter.finish
- @out.should ==
-%[E
+ expect(@out).to eq(%[E
1)
Class#method runs ERROR
@@ -280,6 +279,6 @@ path/to/some/file.rb:35:in method
Finished in 2.0 seconds
1 example, 1 failure
-]
+])
end
end
diff --git a/spec/mspec/spec/runner/formatters/file_spec.rb b/spec/mspec/spec/runner/formatters/file_spec.rb
index 946683ad58..ae11d60845 100644
--- a/spec/mspec/spec/runner/formatters/file_spec.rb
+++ b/spec/mspec/spec/runner/formatters/file_spec.rb
@@ -3,27 +3,27 @@ require 'mspec/runner/formatters/file'
require 'mspec/runner/mspec'
require 'mspec/runner/example'
-describe FileFormatter, "#register" do
+RSpec.describe FileFormatter, "#register" do
before :each do
@formatter = FileFormatter.new
- MSpec.stub(:register)
- MSpec.stub(:unregister)
+ allow(MSpec).to receive(:register)
+ allow(MSpec).to receive(:unregister)
end
it "registers self with MSpec for :load, :unload actions" do
- MSpec.should_receive(:register).with(:load, @formatter)
- MSpec.should_receive(:register).with(:unload, @formatter)
+ expect(MSpec).to receive(:register).with(:load, @formatter)
+ expect(MSpec).to receive(:register).with(:unload, @formatter)
@formatter.register
end
it "unregisters self with MSpec for :before, :after actions" do
- MSpec.should_receive(:unregister).with(:before, @formatter)
- MSpec.should_receive(:unregister).with(:after, @formatter)
+ expect(MSpec).to receive(:unregister).with(:before, @formatter)
+ expect(MSpec).to receive(:unregister).with(:after, @formatter)
@formatter.register
end
end
-describe FileFormatter, "#load" do
+RSpec.describe FileFormatter, "#load" do
before :each do
@state = ExampleState.new ContextState.new("describe"), "it"
@formatter = FileFormatter.new
@@ -31,19 +31,19 @@ describe FileFormatter, "#load" do
end
it "resets the #failure? flag to false" do
- @formatter.failure?.should be_true
+ expect(@formatter.failure?).to be_truthy
@formatter.load @state
- @formatter.failure?.should be_false
+ expect(@formatter.failure?).to be_falsey
end
it "resets the #exception? flag to false" do
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
@formatter.load @state
- @formatter.exception?.should be_false
+ expect(@formatter.exception?).to be_falsey
end
end
-describe FileFormatter, "#unload" do
+RSpec.describe FileFormatter, "#unload" do
before :each do
$stdout = @out = IOStub.new
@formatter = FileFormatter.new
@@ -56,21 +56,21 @@ describe FileFormatter, "#unload" do
it "prints a '.' if there was no exception raised" do
@formatter.unload(@state)
- @out.should == "."
+ expect(@out).to eq(".")
end
it "prints an 'F' if there was an expectation failure" do
exc = SpecExpectationNotMetError.new "failed"
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.unload(@state)
- @out.should == "F"
+ expect(@out).to eq("F")
end
it "prints an 'E' if there was an exception other than expectation failure" do
exc = MSpecExampleError.new("boom!")
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.unload(@state)
- @out.should == "E"
+ expect(@out).to eq("E")
end
it "prints an 'E' if there are mixed exceptions and exepctation failures" do
@@ -79,6 +79,6 @@ describe FileFormatter, "#unload" do
exc = MSpecExampleError.new("boom!")
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.unload(@state)
- @out.should == "E"
+ expect(@out).to eq("E")
end
end
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
diff --git a/spec/mspec/spec/runner/formatters/junit_spec.rb b/spec/mspec/spec/runner/formatters/junit_spec.rb
index 66e7d70e92..3b3da73849 100644
--- a/spec/mspec/spec/runner/formatters/junit_spec.rb
+++ b/spec/mspec/spec/runner/formatters/junit_spec.rb
@@ -2,22 +2,23 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/junit'
require 'mspec/runner/example'
+require 'mspec/helpers'
-describe JUnitFormatter, "#initialize" do
+RSpec.describe JUnitFormatter, "#initialize" do
it "permits zero arguments" do
- lambda { JUnitFormatter.new }.should_not raise_error
+ expect { JUnitFormatter.new }.not_to raise_error
end
it "accepts one argument" do
- lambda { JUnitFormatter.new nil }.should_not raise_error
+ expect { JUnitFormatter.new nil }.not_to raise_error
end
end
-describe JUnitFormatter, "#print" do
+RSpec.describe JUnitFormatter, "#print" do
before :each do
$stdout = IOStub.new
@out = IOStub.new
- File.stub(:open).and_return(@out)
+ allow(File).to receive(:open).and_return(@out)
@formatter = JUnitFormatter.new "some/file"
end
@@ -27,121 +28,132 @@ describe JUnitFormatter, "#print" do
it "writes to $stdout if #switch has not been called" do
@formatter.print "begonias"
- $stdout.should == "begonias"
- @out.should == ""
+ expect($stdout).to eq("begonias")
+ expect(@out).to eq("")
end
it "writes to the file passed to #initialize once #switch has been called" do
@formatter.switch
@formatter.print "begonias"
- $stdout.should == ""
- @out.should == "begonias"
+ expect($stdout).to eq("")
+ expect(@out).to eq("begonias")
end
it "writes to $stdout once #switch is called if no file was passed to #initialize" do
formatter = JUnitFormatter.new
formatter.switch
formatter.print "begonias"
- $stdout.should == "begonias"
- @out.should == ""
+ expect($stdout).to eq("begonias")
+ expect(@out).to eq("")
end
end
-describe JUnitFormatter, "#finish" do
+RSpec.describe JUnitFormatter, "#finish" do
before :each do
@tally = double("tally").as_null_object
@counter = double("counter").as_null_object
- @tally.stub(:counter).and_return(@counter)
- TallyAction.stub(:new).and_return(@tally)
+ allow(@tally).to receive(:counter).and_return(@counter)
+ 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("JUnitFormatter")
- $stdout = IOStub.new
context = ContextState.new "describe"
@state = ExampleState.new(context, "it")
- @formatter = JUnitFormatter.new
- @formatter.stub(:backtrace).and_return("")
- MSpec.stub(:register)
+ @formatter = JUnitFormatter.new(@out)
+ allow(@formatter).to receive(:backtrace).and_return("")
+ allow(MSpec).to receive(:register)
@formatter.register
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
- 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.after @state
end
after :each do
- $stdout = STDOUT
+ rm_r @out
end
it "calls #switch" do
- @formatter.should_receive(:switch)
+ expect(@formatter).to receive(:switch).and_call_original
@formatter.finish
end
it "outputs a failure message and backtrace" do
@formatter.finish
- $stdout.should include 'message="error in describe it" type="error"'
- $stdout.should include "MSpecExampleError: broken\n"
- $stdout.should include "path/to/some/file.rb:35:in method"
+ output = File.read(@out)
+ expect(output).to include 'message="error in describe it" type="error"'
+ expect(output).to include "MSpecExampleError: broken\n"
+ expect(output).to include "path/to/some/file.rb:35:in method"
end
it "encodes message and backtrace in latin1 for jenkins" do
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken…")
- exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in methød")
+ allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in methød")
@formatter.exception exc
@formatter.finish
- $stdout.should =~ /MSpecExampleError: broken((\.\.\.)|\?)\n/
- $stdout.should =~ /path\/to\/some\/file\.rb:35:in meth(\?|o)d/
+ output = File.binread(@out)
+ expect(output).to match(/MSpecExampleError: broken((\.\.\.)|\?)\n/)
+ expect(output).to match(/path\/to\/some\/file\.rb:35:in meth(\?|o)d/)
end
it "outputs an elapsed time" do
- @timer.should_receive(:elapsed).and_return(4.2)
+ expect(@timer).to receive(:elapsed).and_return(4.2)
@formatter.finish
- $stdout.should include 'time="4.2"'
+ output = File.read(@out)
+ expect(output).to include 'time="4.2"'
end
it "outputs overall elapsed time" do
- @timer.should_receive(:elapsed).and_return(4.2)
+ expect(@timer).to receive(:elapsed).and_return(4.2)
@formatter.finish
- $stdout.should include 'timeCount="4.2"'
+ output = File.read(@out)
+ expect(output).to include 'timeCount="4.2"'
end
it "outputs the number of examples as test count" do
- @counter.should_receive(:examples).and_return(9)
+ expect(@counter).to receive(:examples).and_return(9)
@formatter.finish
- $stdout.should include 'tests="9"'
+ output = File.read(@out)
+ expect(output).to include 'tests="9"'
end
it "outputs overall number of examples as test count" do
- @counter.should_receive(:examples).and_return(9)
+ expect(@counter).to receive(:examples).and_return(9)
@formatter.finish
- $stdout.should include 'testCount="9"'
+ output = File.read(@out)
+ expect(output).to include 'testCount="9"'
end
it "outputs a failure count" do
- @counter.should_receive(:failures).and_return(2)
+ expect(@counter).to receive(:failures).and_return(2)
@formatter.finish
- $stdout.should include 'failureCount="2"'
+ output = File.read(@out)
+ expect(output).to include 'failureCount="2"'
end
it "outputs overall failure count" do
- @counter.should_receive(:failures).and_return(2)
+ expect(@counter).to receive(:failures).and_return(2)
@formatter.finish
- $stdout.should include 'failures="2"'
+ output = File.read(@out)
+ expect(output).to include 'failures="2"'
end
it "outputs an error count" do
- @counter.should_receive(:errors).and_return(1)
+ expect(@counter).to receive(:errors).and_return(1)
@formatter.finish
- $stdout.should include 'errors="1"'
+ output = File.read(@out)
+ expect(output).to include 'errors="1"'
end
it "outputs overall error count" do
- @counter.should_receive(:errors).and_return(1)
+ expect(@counter).to receive(:errors).and_return(1)
@formatter.finish
- $stdout.should include 'errorCount="1"'
+ output = File.read(@out)
+ expect(output).to include 'errorCount="1"'
end
end
diff --git a/spec/mspec/spec/runner/formatters/method_spec.rb b/spec/mspec/spec/runner/formatters/method_spec.rb
index 77204f74c5..02bf47d538 100644
--- a/spec/mspec/spec/runner/formatters/method_spec.rb
+++ b/spec/mspec/spec/runner/formatters/method_spec.rb
@@ -4,29 +4,29 @@ require 'mspec/runner/mspec'
require 'mspec/runner/example'
require 'mspec/utils/script'
-describe MethodFormatter, "#method_type" do
+RSpec.describe MethodFormatter, "#method_type" do
before :each do
@formatter = MethodFormatter.new
end
it "returns 'class' if the separator is '.' or '::'" do
- @formatter.method_type('.').should == "class"
- @formatter.method_type('::').should == "class"
+ expect(@formatter.method_type('.')).to eq("class")
+ expect(@formatter.method_type('::')).to eq("class")
end
it "returns 'instance' if the separator is '#'" do
- @formatter.method_type('#').should == "instance"
+ expect(@formatter.method_type('#')).to eq("instance")
end
it "returns 'unknown' for all other cases" do
- @formatter.method_type(nil).should == "unknown"
+ expect(@formatter.method_type(nil)).to eq("unknown")
end
end
-describe MethodFormatter, "#before" do
+RSpec.describe MethodFormatter, "#before" do
before :each do
@formatter = MethodFormatter.new
- MSpec.stub(:register)
+ allow(MSpec).to receive(:register)
@formatter.register
end
@@ -38,32 +38,32 @@ describe MethodFormatter, "#before" do
state = ExampleState.new ContextState.new("describe"), "it"
@formatter.before state
- @formatter.tally.counter.examples.should == 0
- @formatter.tally.counter.expectations.should == 0
- @formatter.tally.counter.failures.should == 0
- @formatter.tally.counter.errors.should == 0
+ expect(@formatter.tally.counter.examples).to eq(0)
+ expect(@formatter.tally.counter.expectations).to eq(0)
+ expect(@formatter.tally.counter.failures).to eq(0)
+ expect(@formatter.tally.counter.errors).to eq(0)
end
it "records the class, method if available" do
state = ExampleState.new ContextState.new("Some#method"), "it"
@formatter.before state
key = "Some#method"
- @formatter.methods.keys.should include(key)
+ expect(@formatter.methods.keys).to include(key)
h = @formatter.methods[key]
- h[:class].should == "Some"
- h[:method].should == "method"
- h[:description].should == "Some#method it"
+ expect(h[:class]).to eq("Some")
+ expect(h[:method]).to eq("method")
+ expect(h[:description]).to eq("Some#method it")
end
it "does not record class, method unless both are available" do
state = ExampleState.new ContextState.new("Some method"), "it"
@formatter.before state
key = "Some method"
- @formatter.methods.keys.should include(key)
+ expect(@formatter.methods.keys).to include(key)
h = @formatter.methods[key]
- h[:class].should == ""
- h[:method].should == ""
- h[:description].should == "Some method it"
+ expect(h[:class]).to eq("")
+ expect(h[:method]).to eq("")
+ expect(h[:description]).to eq("Some method it")
end
it "sets the method type to unknown if class and method are not available" do
@@ -71,7 +71,7 @@ describe MethodFormatter, "#before" do
@formatter.before state
key = "Some method"
h = @formatter.methods[key]
- h[:type].should == "unknown"
+ expect(h[:type]).to eq("unknown")
end
it "sets the method type based on the class, method separator" do
@@ -79,7 +79,7 @@ describe MethodFormatter, "#before" do
state = ExampleState.new ContextState.new(k), "it"
@formatter.before state
h = @formatter.methods[k]
- h[:type].should == t
+ expect(h[:type]).to eq(t)
end
end
@@ -87,14 +87,14 @@ describe MethodFormatter, "#before" do
state = ExampleState.new ContextState.new("describe"), "it"
@formatter.exceptions << "stuff"
@formatter.before state
- @formatter.exceptions.should be_empty
+ expect(@formatter.exceptions).to be_empty
end
end
-describe MethodFormatter, "#after" do
+RSpec.describe MethodFormatter, "#after" do
before :each do
@formatter = MethodFormatter.new
- MSpec.stub(:register)
+ allow(MSpec).to receive(:register)
@formatter.register
end
@@ -109,10 +109,10 @@ describe MethodFormatter, "#after" do
@formatter.after state
h = @formatter.methods["Some#method"]
- h[:examples].should == 3
- h[:expectations].should == 4
- h[:failures].should == 2
- h[:errors].should == 1
+ expect(h[:examples]).to eq(3)
+ expect(h[:expectations]).to eq(4)
+ expect(h[:failures]).to eq(2)
+ expect(h[:errors]).to eq(1)
end
it "renders the list of exceptions" do
@@ -125,20 +125,20 @@ describe MethodFormatter, "#after" do
@formatter.after state
h = @formatter.methods["Some#method"]
- h[:exceptions].should == [
+ expect(h[:exceptions]).to eq([
%[failed\n\n],
%[failed\n\n]
- ]
+ ])
end
end
-describe MethodFormatter, "#after" do
+RSpec.describe MethodFormatter, "#after" do
before :each do
$stdout = IOStub.new
context = ContextState.new "Class#method"
@state = ExampleState.new(context, "runs")
@formatter = MethodFormatter.new
- MSpec.stub(:register)
+ allow(MSpec).to receive(:register)
@formatter.register
end
@@ -159,8 +159,7 @@ describe MethodFormatter, "#after" do
@formatter.after @state
@formatter.finish
- $stdout.should ==
-%[---
+ expect($stdout).to eq(%[---
"Class#method":
class: "Class"
method: "method"
@@ -173,6 +172,6 @@ describe MethodFormatter, "#after" do
exceptions:
- "failed\\n\\n"
- "failed\\n\\n"
-]
+])
end
end
diff --git a/spec/mspec/spec/runner/formatters/multi_spec.rb b/spec/mspec/spec/runner/formatters/multi_spec.rb
index d0ed8edc93..2d13c05836 100644
--- a/spec/mspec/spec/runner/formatters/multi_spec.rb
+++ b/spec/mspec/spec/runner/formatters/multi_spec.rb
@@ -4,20 +4,20 @@ require 'mspec/runner/formatters/multi'
require 'mspec/runner/example'
require 'yaml'
-describe MultiFormatter, "#aggregate_results" do
+RSpec.describe MultiFormatter, "#aggregate_results" do
before :each do
@stdout, $stdout = $stdout, IOStub.new
@file = double("file").as_null_object
- File.stub(:delete)
- File.stub(:read)
+ allow(File).to receive(:delete)
+ allow(File).to receive(:read)
@hash = { "files"=>1, "examples"=>1, "expectations"=>2, "failures"=>0, "errors"=>0 }
- YAML.stub(:load).and_return(@hash)
+ allow(YAML).to receive(:load).and_return(@hash)
@formatter = DottedFormatter.new.extend(MultiFormatter)
- @formatter.timer.stub(:format).and_return("Finished in 42 seconds")
+ allow(@formatter.timer).to receive(:format).and_return("Finished in 42 seconds")
end
after :each do
@@ -27,13 +27,12 @@ describe MultiFormatter, "#aggregate_results" do
it "outputs a summary without errors" do
@formatter.aggregate_results(["a", "b"])
@formatter.finish
- $stdout.should ==
-%[
+ expect($stdout).to eq(%[
Finished in 42 seconds
2 files, 2 examples, 4 expectations, 0 failures, 0 errors, 0 tagged
-]
+])
end
it "outputs a summary with errors" do
@@ -43,8 +42,7 @@ Finished in 42 seconds
]
@formatter.aggregate_results(["a"])
@formatter.finish
- $stdout.should ==
-%[
+ expect($stdout).to eq(%[
1)
Some#method works real good FAILED
@@ -65,6 +63,6 @@ foo.rb:2
Finished in 42 seconds
1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged
-]
+])
end
end
diff --git a/spec/mspec/spec/runner/formatters/specdoc_spec.rb b/spec/mspec/spec/runner/formatters/specdoc_spec.rb
index edb439fc11..54b5e2cf0d 100644
--- a/spec/mspec/spec/runner/formatters/specdoc_spec.rb
+++ b/spec/mspec/spec/runner/formatters/specdoc_spec.rb
@@ -2,19 +2,19 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/specdoc'
require 'mspec/runner/example'
-describe SpecdocFormatter do
+RSpec.describe SpecdocFormatter do
before :each do
@formatter = SpecdocFormatter.new
end
it "responds to #register by registering itself with MSpec for appropriate actions" do
- MSpec.stub(:register)
- MSpec.should_receive(:register).with(:enter, @formatter)
+ allow(MSpec).to receive(:register)
+ expect(MSpec).to receive(:register).with(:enter, @formatter)
@formatter.register
end
end
-describe SpecdocFormatter, "#enter" do
+RSpec.describe SpecdocFormatter, "#enter" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
@@ -26,11 +26,11 @@ describe SpecdocFormatter, "#enter" do
it "prints the #describe string" do
@formatter.enter("describe")
- @out.should == "\ndescribe\n"
+ expect(@out).to eq("\ndescribe\n")
end
end
-describe SpecdocFormatter, "#before" do
+RSpec.describe SpecdocFormatter, "#before" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
@@ -43,19 +43,19 @@ describe SpecdocFormatter, "#before" do
it "prints the #it string" do
@formatter.before @state
- @out.should == "- it"
+ expect(@out).to eq("- it")
end
it "resets the #exception? flag" do
exc = ExceptionState.new @state, nil, SpecExpectationNotMetError.new("disappointing")
@formatter.exception exc
- @formatter.exception?.should be_true
+ expect(@formatter.exception?).to be_truthy
@formatter.before @state
- @formatter.exception?.should be_false
+ expect(@formatter.exception?).to be_falsey
end
end
-describe SpecdocFormatter, "#exception" do
+RSpec.describe SpecdocFormatter, "#exception" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
@@ -70,13 +70,13 @@ describe SpecdocFormatter, "#exception" do
it "prints 'ERROR' if an exception is not an SpecExpectationNotMetError" do
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
@formatter.exception exc
- @out.should == " (ERROR - 1)"
+ expect(@out).to eq(" (ERROR - 1)")
end
it "prints 'FAILED' if an exception is an SpecExpectationNotMetError" do
exc = ExceptionState.new @state, nil, SpecExpectationNotMetError.new("disappointing")
@formatter.exception exc
- @out.should == " (FAILED - 1)"
+ expect(@out).to eq(" (FAILED - 1)")
end
it "prints the #it string if an exception has already been raised" do
@@ -84,11 +84,11 @@ describe SpecdocFormatter, "#exception" do
@formatter.exception exc
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
@formatter.exception exc
- @out.should == " (FAILED - 1)\n- it (ERROR - 2)"
+ expect(@out).to eq(" (FAILED - 1)\n- it (ERROR - 2)")
end
end
-describe SpecdocFormatter, "#after" do
+RSpec.describe SpecdocFormatter, "#after" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
@@ -101,6 +101,6 @@ describe SpecdocFormatter, "#after" do
it "prints a newline character" do
@formatter.after @state
- @out.should == "\n"
+ expect(@out).to eq("\n")
end
end
diff --git a/spec/mspec/spec/runner/formatters/spinner_spec.rb b/spec/mspec/spec/runner/formatters/spinner_spec.rb
index a122620e39..5c93d38822 100644
--- a/spec/mspec/spec/runner/formatters/spinner_spec.rb
+++ b/spec/mspec/spec/runner/formatters/spinner_spec.rb
@@ -3,7 +3,7 @@ require 'mspec/runner/formatters/spinner'
require 'mspec/runner/mspec'
require 'mspec/runner/example'
-describe SpinnerFormatter, "#initialize" do
+RSpec.describe SpinnerFormatter, "#initialize" do
it "permits zero arguments" do
SpinnerFormatter.new
end
@@ -13,33 +13,33 @@ describe SpinnerFormatter, "#initialize" do
end
end
-describe SpinnerFormatter, "#register" do
+RSpec.describe SpinnerFormatter, "#register" do
before :each do
@formatter = SpinnerFormatter.new
- MSpec.stub(:register)
+ allow(MSpec).to receive(:register)
end
it "registers self with MSpec for appropriate actions" do
- MSpec.should_receive(:register).with(:start, @formatter)
- MSpec.should_receive(:register).with(:unload, @formatter)
- MSpec.should_receive(:register).with(:after, @formatter)
- MSpec.should_receive(:register).with(:finish, @formatter)
+ expect(MSpec).to receive(:register).with(:start, @formatter)
+ expect(MSpec).to receive(:register).with(:unload, @formatter)
+ expect(MSpec).to receive(:register).with(:after, @formatter)
+ expect(MSpec).to receive(:register).with(:finish, @formatter)
@formatter.register
end
it "creates TimerAction and TallyAction" do
timer = double("timer")
tally = double("tally")
- timer.should_receive(:register)
- tally.should_receive(:register)
- tally.should_receive(:counter)
- TimerAction.should_receive(:new).and_return(timer)
- TallyAction.should_receive(:new).and_return(tally)
+ expect(timer).to receive(:register)
+ expect(tally).to receive(:register)
+ expect(tally).to receive(:counter)
+ expect(TimerAction).to receive(:new).and_return(timer)
+ expect(TallyAction).to receive(:new).and_return(tally)
@formatter.register
end
end
-describe SpinnerFormatter, "#print" do
+RSpec.describe SpinnerFormatter, "#print" do
after :each do
$stdout = STDOUT
end
@@ -48,11 +48,11 @@ describe SpinnerFormatter, "#print" do
$stdout = IOStub.new
formatter = SpinnerFormatter.new "some/file"
formatter.print "begonias"
- $stdout.should == "begonias"
+ expect($stdout).to eq("begonias")
end
end
-describe SpinnerFormatter, "#after" do
+RSpec.describe SpinnerFormatter, "#after" do
before :each do
$stdout = IOStub.new
MSpec.store(:files, ["a", "b", "c", "d"])
@@ -78,6 +78,6 @@ describe SpinnerFormatter, "#after" do
output = "\r[/ | 0% | 00:00:00] #{green} 0F #{green} 0E#{reset} " \
"\r[- | 0% | 00:00:00] #{green} 0F #{green} 0E#{reset} " \
"\r[\\ | ========== 25% | 00:00:00] #{green} 0F #{green} 0E#{reset} "
- $stdout.should == output
+ expect($stdout).to eq(output)
end
end
diff --git a/spec/mspec/spec/runner/formatters/summary_spec.rb b/spec/mspec/spec/runner/formatters/summary_spec.rb
index 16a156b695..c87d940042 100644
--- a/spec/mspec/spec/runner/formatters/summary_spec.rb
+++ b/spec/mspec/spec/runner/formatters/summary_spec.rb
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/summary'
require 'mspec/runner/example'
-describe SummaryFormatter, "#after" do
+RSpec.describe SummaryFormatter, "#after" do
before :each do
$stdout = @out = IOStub.new
@formatter = SummaryFormatter.new
@@ -21,6 +21,6 @@ describe SummaryFormatter, "#after" do
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
@formatter.exception exc
@formatter.after(@state)
- @out.should == ""
+ expect(@out).to eq("")
end
end
diff --git a/spec/mspec/spec/runner/formatters/unit_spec.rb b/spec/mspec/spec/runner/formatters/unit_spec.rb
index 18167a32b8..d349e6871d 100644
--- a/spec/mspec/spec/runner/formatters/unit_spec.rb
+++ b/spec/mspec/spec/runner/formatters/unit_spec.rb
@@ -3,17 +3,17 @@ require 'mspec/runner/formatters/unit'
require 'mspec/runner/example'
require 'mspec/utils/script'
-describe UnitdiffFormatter, "#finish" do
+RSpec.describe UnitdiffFormatter, "#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)
$stdout = @out = IOStub.new
context = ContextState.new "describe"
@state = ExampleState.new(context, "it")
- MSpec.stub(:register)
+ allow(MSpec).to receive(:register)
@formatter = UnitdiffFormatter.new
@formatter.register
end
@@ -27,39 +27,38 @@ describe UnitdiffFormatter, "#finish" do
@formatter.exception exc
@formatter.after @state
@formatter.finish
- @out.should =~ /^1\)\ndescribe it ERROR$/
+ expect(@out).to match(/^1\)\ndescribe it ERROR$/)
end
it "prints a backtrace for an exception" do
exc = ExceptionState.new @state, nil, Exception.new("broken")
- 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[path/to/some/file.rb:35:in method$]
+ expect(@out).to match(%r[path/to/some/file.rb:35:in method$])
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 =~ /^Finished in 2.0 seconds$/
+ expect(@out).to match(/^Finished in 2.0 seconds$/)
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 =~ /^1 example, 0 failures$/
+ expect(@out).to match(/^1 example, 0 failures$/)
end
it "prints errors, backtraces, elapsed time, and tallies" do
exc = ExceptionState.new @state, nil, Exception.new("broken")
- 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.after @state
- @timer.should_receive(:format).and_return("Finished in 2.0 seconds")
- @tally.should_receive(:format).and_return("1 example, 0 failures")
+ expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
+ expect(@tally).to receive(:format).and_return("1 example, 0 failures")
@formatter.finish
- @out.should ==
-%[E
+ expect(@out).to eq(%[E
Finished in 2.0 seconds
@@ -69,6 +68,6 @@ Exception: broken:
path/to/some/file.rb:35:in method
1 example, 0 failures
-]
+])
end
end
diff --git a/spec/mspec/spec/runner/formatters/yaml_spec.rb b/spec/mspec/spec/runner/formatters/yaml_spec.rb
index eb4d99f74c..2e334fdbb9 100644
--- a/spec/mspec/spec/runner/formatters/yaml_spec.rb
+++ b/spec/mspec/spec/runner/formatters/yaml_spec.rb
@@ -1,8 +1,9 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/yaml'
require 'mspec/runner/example'
+require 'mspec/helpers'
-describe YamlFormatter, "#initialize" do
+RSpec.describe YamlFormatter, "#initialize" do
it "permits zero arguments" do
YamlFormatter.new
end
@@ -12,11 +13,11 @@ describe YamlFormatter, "#initialize" do
end
end
-describe YamlFormatter, "#print" do
+RSpec.describe YamlFormatter, "#print" do
before :each do
$stdout = IOStub.new
@out = IOStub.new
- File.stub(:open).and_return(@out)
+ allow(File).to receive(:open).and_return(@out)
@formatter = YamlFormatter.new "some/file"
end
@@ -26,100 +27,108 @@ describe YamlFormatter, "#print" do
it "writes to $stdout if #switch has not been called" do
@formatter.print "begonias"
- $stdout.should == "begonias"
- @out.should == ""
+ expect($stdout).to eq("begonias")
+ expect(@out).to eq("")
end
it "writes to the file passed to #initialize once #switch has been called" do
@formatter.switch
@formatter.print "begonias"
- $stdout.should == ""
- @out.should == "begonias"
+ expect($stdout).to eq("")
+ expect(@out).to eq("begonias")
end
it "writes to $stdout once #switch is called if no file was passed to #initialize" do
formatter = YamlFormatter.new
formatter.switch
formatter.print "begonias"
- $stdout.should == "begonias"
- @out.should == ""
+ expect($stdout).to eq("begonias")
+ expect(@out).to eq("")
end
end
-describe YamlFormatter, "#finish" do
+RSpec.describe YamlFormatter, "#finish" do
before :each do
@tally = double("tally").as_null_object
@counter = double("counter").as_null_object
- @tally.stub(:counter).and_return(@counter)
- TallyAction.stub(:new).and_return(@tally)
+ allow(@tally).to receive(:counter).and_return(@counter)
+ 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("YamlFormatter")
- $stdout = IOStub.new
context = ContextState.new "describe"
@state = ExampleState.new(context, "it")
- @formatter = YamlFormatter.new
- @formatter.stub(:backtrace).and_return("")
- MSpec.stub(:register)
+ @formatter = YamlFormatter.new(@out)
+ allow(@formatter).to receive(:backtrace).and_return("")
+ allow(MSpec).to receive(:register)
@formatter.register
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
- 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.after @state
end
after :each do
- $stdout = STDOUT
+ rm_r @out
end
it "calls #switch" do
- @formatter.should_receive(:switch)
+ expect(@formatter).to receive(:switch).and_call_original
@formatter.finish
end
it "outputs a failure message and backtrace" do
@formatter.finish
- $stdout.should include "describe it ERROR"
- $stdout.should include "MSpecExampleError: broken\\n"
- $stdout.should include "path/to/some/file.rb:35:in method"
+ output = File.read(@out)
+ expect(output).to include "describe it ERROR"
+ expect(output).to include "MSpecExampleError: broken\\n"
+ expect(output).to include "path/to/some/file.rb:35:in method"
end
it "outputs an elapsed time" do
- @timer.should_receive(:elapsed).and_return(4.2)
+ expect(@timer).to receive(:elapsed).and_return(4.2)
@formatter.finish
- $stdout.should include "time: 4.2"
+ output = File.read(@out)
+ expect(output).to include "time: 4.2"
end
it "outputs a file count" do
- @counter.should_receive(:files).and_return(3)
+ expect(@counter).to receive(:files).and_return(3)
@formatter.finish
- $stdout.should include "files: 3"
+ output = File.read(@out)
+ expect(output).to include "files: 3"
end
it "outputs an example count" do
- @counter.should_receive(:examples).and_return(3)
+ expect(@counter).to receive(:examples).and_return(3)
@formatter.finish
- $stdout.should include "examples: 3"
+ output = File.read(@out)
+ expect(output).to include "examples: 3"
end
it "outputs an expectation count" do
- @counter.should_receive(:expectations).and_return(9)
+ expect(@counter).to receive(:expectations).and_return(9)
@formatter.finish
- $stdout.should include "expectations: 9"
+ output = File.read(@out)
+ expect(output).to include "expectations: 9"
end
it "outputs a failure count" do
- @counter.should_receive(:failures).and_return(2)
+ expect(@counter).to receive(:failures).and_return(2)
@formatter.finish
- $stdout.should include "failures: 2"
+ output = File.read(@out)
+ expect(output).to include "failures: 2"
end
it "outputs an error count" do
- @counter.should_receive(:errors).and_return(1)
+ expect(@counter).to receive(:errors).and_return(1)
@formatter.finish
- $stdout.should include "errors: 1"
+ output = File.read(@out)
+ expect(output).to include "errors: 1"
end
end