1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/specdoc'
require 'mspec/runner/example'
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)
@formatter.register
end
end
describe SpecdocFormatter, "#enter" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
end
after :each do
$stdout = STDOUT
end
it "prints the #describe string" do
@formatter.enter("describe")
@out.should == "\ndescribe\n"
end
end
describe SpecdocFormatter, "#before" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
@state = ExampleState.new ContextState.new("describe"), "it"
end
after :each do
$stdout = STDOUT
end
it "prints the #it string" do
@formatter.before @state
@out.should == "- it"
end
it "resets the #exception? flag" do
exc = ExceptionState.new @state, nil, SpecExpectationNotMetError.new("disappointing")
@formatter.exception exc
@formatter.exception?.should be_true
@formatter.before @state
@formatter.exception?.should be_false
end
end
describe SpecdocFormatter, "#exception" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
context = ContextState.new "describe"
@state = ExampleState.new context, "it"
end
after :each do
$stdout = STDOUT
end
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)"
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)"
end
it "prints the #it string if an exception has already been raised" do
exc = ExceptionState.new @state, nil, SpecExpectationNotMetError.new("disappointing")
@formatter.exception exc
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
@formatter.exception exc
@out.should == " (FAILED - 1)\n- it (ERROR - 2)"
end
end
describe SpecdocFormatter, "#after" do
before :each do
$stdout = @out = IOStub.new
@formatter = SpecdocFormatter.new
@state = ExampleState.new "describe", "it"
end
after :each do
$stdout = STDOUT
end
it "prints a newline character" do
@formatter.after @state
@out.should == "\n"
end
end
|