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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/method'
require 'mspec/runner/mspec'
require 'mspec/runner/example'
require 'mspec/utils/script'
RSpec.describe MethodFormatter, "#method_type" do
before :each do
@formatter = MethodFormatter.new
end
it "returns 'class' if the separator is '.' or '::'" do
expect(@formatter.method_type('.')).to eq("class")
expect(@formatter.method_type('::')).to eq("class")
end
it "returns 'instance' if the separator is '#'" do
expect(@formatter.method_type('#')).to eq("instance")
end
it "returns 'unknown' for all other cases" do
expect(@formatter.method_type(nil)).to eq("unknown")
end
end
RSpec.describe MethodFormatter, "#before" do
before :each do
@formatter = MethodFormatter.new
allow(MSpec).to receive(:register)
@formatter.register
end
it "resets the tally counters to 0" do
@formatter.tally.counter.examples = 3
@formatter.tally.counter.expectations = 4
@formatter.tally.counter.failures = 2
@formatter.tally.counter.errors = 1
state = ExampleState.new ContextState.new("describe"), "it"
@formatter.before state
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"
expect(@formatter.methods.keys).to include(key)
h = @formatter.methods[key]
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"
expect(@formatter.methods.keys).to include(key)
h = @formatter.methods[key]
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
state = ExampleState.new ContextState.new("Some method"), "it"
@formatter.before state
key = "Some method"
h = @formatter.methods[key]
expect(h[:type]).to eq("unknown")
end
it "sets the method type based on the class, method separator" do
[["C#m", "instance"], ["C.m", "class"], ["C::m", "class"]].each do |k, t|
state = ExampleState.new ContextState.new(k), "it"
@formatter.before state
h = @formatter.methods[k]
expect(h[:type]).to eq(t)
end
end
it "clears the list of exceptions" do
state = ExampleState.new ContextState.new("describe"), "it"
@formatter.exceptions << "stuff"
@formatter.before state
expect(@formatter.exceptions).to be_empty
end
end
RSpec.describe MethodFormatter, "#after" do
before :each do
@formatter = MethodFormatter.new
allow(MSpec).to receive(:register)
@formatter.register
end
it "sets the tally counts" do
state = ExampleState.new ContextState.new("Some#method"), "it"
@formatter.before state
@formatter.tally.counter.examples = 3
@formatter.tally.counter.expectations = 4
@formatter.tally.counter.failures = 2
@formatter.tally.counter.errors = 1
@formatter.after state
h = @formatter.methods["Some#method"]
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
state = ExampleState.new ContextState.new("Some#method"), "it"
@formatter.before state
exc = SpecExpectationNotMetError.new "failed"
@formatter.exception ExceptionState.new(state, nil, exc)
@formatter.exception ExceptionState.new(state, nil, exc)
@formatter.after state
h = @formatter.methods["Some#method"]
expect(h[:exceptions]).to eq([
%[failed\n\n],
%[failed\n\n]
])
end
end
RSpec.describe MethodFormatter, "#after" do
before :each do
$stdout = IOStub.new
context = ContextState.new "Class#method"
@state = ExampleState.new(context, "runs")
@formatter = MethodFormatter.new
allow(MSpec).to receive(:register)
@formatter.register
end
after :each do
$stdout = STDOUT
end
it "prints a summary of the results of an example in YAML format" do
@formatter.before @state
@formatter.tally.counter.examples = 3
@formatter.tally.counter.expectations = 4
@formatter.tally.counter.failures = 2
@formatter.tally.counter.errors = 1
exc = SpecExpectationNotMetError.new "failed"
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.exception ExceptionState.new(@state, nil, exc)
@formatter.after @state
@formatter.finish
expect($stdout).to eq(%[---
"Class#method":
class: "Class"
method: "method"
type: instance
description: "Class#method runs"
examples: 3
expectations: 4
failures: 2
errors: 1
exceptions:
- "failed\\n\\n"
- "failed\\n\\n"
])
end
end
|