1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require 'mspec/runner/formatters/specdoc'
3 require 'mspec/runner/example'
5 describe SpecdocFormatter do
7 @formatter = SpecdocFormatter.new
10 it "responds to #register by registering itself with MSpec for appropriate actions" do
11 MSpec.stub!(:register)
12 MSpec.should_receive(:register).with(:enter, @formatter)
17 describe SpecdocFormatter, "#enter" do
19 $stdout = @out = IOStub.new
20 @formatter = SpecdocFormatter.new
27 it "prints the #describe string" do
28 @formatter.enter("describe")
29 @out.should == "\ndescribe\n"
33 describe SpecdocFormatter, "#before" do
35 $stdout = @out = IOStub.new
36 @formatter = SpecdocFormatter.new
37 @state = ExampleState.new ContextState.new("describe"), "it"
44 it "prints the #it string" do
45 @formatter.before @state
49 it "resets the #exception? flag" do
50 exc = ExceptionState.new @state, nil, ExpectationNotMetError.new("disappointing")
51 @formatter.exception exc
52 @formatter.exception?.should be_true
53 @formatter.before @state
54 @formatter.exception?.should be_false
58 describe SpecdocFormatter, "#exception" do
60 $stdout = @out = IOStub.new
61 @formatter = SpecdocFormatter.new
62 context = ContextState.new "describe"
63 @state = ExampleState.new context, "it"
70 it "prints 'ERROR' if an exception is not an ExpectationNotMetError" do
71 exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
72 @formatter.exception exc
73 @out.should == " (ERROR - 1)"
76 it "prints 'FAILED' if an exception is an ExpectationNotMetError" do
77 exc = ExceptionState.new @state, nil, ExpectationNotMetError.new("disappointing")
78 @formatter.exception exc
79 @out.should == " (FAILED - 1)"
82 it "prints the #it string if an exception has already been raised" do
83 exc = ExceptionState.new @state, nil, ExpectationNotMetError.new("disappointing")
84 @formatter.exception exc
85 exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
86 @formatter.exception exc
87 @out.should == " (FAILED - 1)\n- it (ERROR - 2)"
91 describe SpecdocFormatter, "#after" do
93 $stdout = @out = IOStub.new
94 @formatter = SpecdocFormatter.new
95 @state = ExampleState.new "describe", "it"
102 it "prints a newline character" do
103 @formatter.after @state