1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require 'mspec/runner/formatters/unit'
3 require 'mspec/runner/example'
5 describe UnitdiffFormatter, "#finish" do
7 @tally = mock("tally", :null_object => true)
8 TallyAction.stub!(:new).and_return(@tally)
9 @timer = mock("timer", :null_object => true)
10 TimerAction.stub!(:new).and_return(@timer)
12 $stdout = @out = IOStub.new
13 context = ContextState.new "describe"
14 @state = ExampleState.new(context, "it")
15 MSpec.stub!(:register)
16 @formatter = UnitdiffFormatter.new
24 it "prints a failure message for an exception" do
25 exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
26 @formatter.exception exc
27 @formatter.after @state
29 @out.should =~ /^1\)\ndescribe it ERROR$/
32 it "prints a backtrace for an exception" do
33 exc = ExceptionState.new @state, nil, Exception.new("broken")
34 exc.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
35 @formatter.exception exc
37 @out.should =~ %r[path/to/some/file.rb:35:in method$]
40 it "prints a summary of elapsed time" do
41 @timer.should_receive(:format).and_return("Finished in 2.0 seconds")
43 @out.should =~ /^Finished in 2.0 seconds$/
46 it "prints a tally of counts" do
47 @tally.should_receive(:format).and_return("1 example, 0 failures")
49 @out.should =~ /^1 example, 0 failures$/
52 it "prints errors, backtraces, elapsed time, and tallies" do
53 exc = ExceptionState.new @state, nil, Exception.new("broken")
54 exc.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
55 @formatter.exception exc
56 @formatter.after @state
57 @timer.should_receive(:format).and_return("Finished in 2.0 seconds")
58 @tally.should_receive(:format).and_return("1 example, 0 failures")
63 Finished in 2.0 seconds
68 path/to/some/file.rb:35:in method