mspec 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +93 -0
- data/lib/mspec/commands/mspec-ci.rb +2 -0
- data/lib/mspec/matchers.rb +4 -3
- data/lib/mspec/matchers/equal_element.rb +78 -0
- data/lib/mspec/runner/context.rb +138 -52
- data/lib/mspec/runner/example.rb +17 -20
- data/lib/mspec/runner/mspec.rb +38 -13
- data/lib/mspec/runner/object.rb +5 -1
- data/lib/mspec/runner/shared.rb +6 -6
- data/lib/mspec/version.rb +1 -1
- data/spec/commands/mspec_ci_spec.rb +14 -0
- data/spec/matchers/equal_element_spec.rb +75 -0
- data/spec/runner/actions/debug_spec.rb +2 -1
- data/spec/runner/actions/gdb_spec.rb +1 -1
- data/spec/runner/actions/tag_spec.rb +7 -4
- data/spec/runner/context_spec.rb +422 -57
- data/spec/runner/example_spec.rb +53 -37
- data/spec/runner/exception_spec.rb +9 -5
- data/spec/runner/formatters/dotted_spec.rb +4 -3
- data/spec/runner/formatters/html_spec.rb +4 -3
- data/spec/runner/formatters/specdoc_spec.rb +3 -2
- data/spec/runner/formatters/summary_spec.rb +2 -1
- data/spec/runner/formatters/unit_spec.rb +2 -1
- data/spec/runner/formatters/yaml_spec.rb +2 -1
- data/spec/runner/mspec_spec.rb +87 -23
- data/spec/runner/shared_spec.rb +14 -28
- metadata +3 -1
data/spec/runner/example_spec.rb
CHANGED
@@ -5,24 +5,27 @@ require 'mspec/mocks/mock'
|
|
5
5
|
require 'mspec/runner/example'
|
6
6
|
|
7
7
|
describe ExampleState do
|
8
|
-
it "is initialized with the
|
9
|
-
|
8
|
+
it "is initialized with the ContextState, #it string, and #it block" do
|
9
|
+
prc = lambda { }
|
10
|
+
context = ContextState.new ""
|
11
|
+
ExampleState.new(context, "does", prc).should be_kind_of(ExampleState)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
15
|
describe ExampleState, "#describe" do
|
14
16
|
before :each do
|
15
|
-
@
|
17
|
+
@context = ContextState.new Object, "#to_s"
|
18
|
+
@state = ExampleState.new @context, "it"
|
16
19
|
end
|
17
20
|
|
18
|
-
it "returns the
|
19
|
-
@state.describe.should ==
|
21
|
+
it "returns the ContextState#description" do
|
22
|
+
@state.describe.should == @context.description
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
26
|
describe ExampleState, "#it" do
|
24
27
|
before :each do
|
25
|
-
@state = ExampleState.new("describe", "it"
|
28
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
26
29
|
end
|
27
30
|
|
28
31
|
it "returns the argument to the #it block" do
|
@@ -30,67 +33,80 @@ describe ExampleState, "#it" do
|
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
|
-
describe ExampleState, "#
|
36
|
+
describe ExampleState, "#context=" do
|
37
|
+
before :each do
|
38
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
39
|
+
@context = ContextState.new "New#context"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets the containing ContextState" do
|
43
|
+
@state.context = @context
|
44
|
+
@state.context.should == @context
|
45
|
+
end
|
46
|
+
|
47
|
+
it "resets the description" do
|
48
|
+
@state.description.should == "describe it"
|
49
|
+
@state.context = @context
|
50
|
+
@state.description.should == "New#context it"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ExampleState, "#example" do
|
55
|
+
before :each do
|
56
|
+
@proc = lambda { }
|
57
|
+
@state = ExampleState.new ContextState.new("describe"), "it", @proc
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns the #it block" do
|
61
|
+
@state.example.should == @proc
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ExampleState, "#filtered?" do
|
34
66
|
before :each do
|
35
67
|
MSpec.store :include, nil
|
36
68
|
MSpec.store :exclude, nil
|
37
69
|
|
38
|
-
@state = ExampleState.new("describe", "it"
|
70
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
39
71
|
@filter = mock("filter")
|
40
72
|
end
|
41
73
|
|
42
|
-
it "returns
|
43
|
-
@state.
|
74
|
+
it "returns false if MSpec include filters list is empty" do
|
75
|
+
@state.filtered?.should == false
|
44
76
|
end
|
45
77
|
|
46
|
-
it "returns
|
78
|
+
it "returns false if MSpec include filters match this spec" do
|
47
79
|
@filter.should_receive(:===).and_return(true)
|
48
80
|
MSpec.register :include, @filter
|
49
|
-
@state.
|
81
|
+
@state.filtered?.should == false
|
50
82
|
end
|
51
83
|
|
52
|
-
it "returns
|
84
|
+
it "returns true if MSpec include filters do not match this spec" do
|
53
85
|
@filter.should_receive(:===).and_return(false)
|
54
86
|
MSpec.register :include, @filter
|
55
|
-
@state.
|
87
|
+
@state.filtered?.should == true
|
56
88
|
end
|
57
89
|
|
58
|
-
it "returns
|
59
|
-
@state.
|
90
|
+
it "returns false if MSpec exclude filters list is empty" do
|
91
|
+
@state.filtered?.should == false
|
60
92
|
end
|
61
93
|
|
62
|
-
it "returns
|
94
|
+
it "returns false if MSpec exclude filters do not match this spec" do
|
63
95
|
@filter.should_receive(:===).and_return(false)
|
64
96
|
MSpec.register :exclude, @filter
|
65
|
-
@state.
|
97
|
+
@state.filtered?.should == false
|
66
98
|
end
|
67
99
|
|
68
|
-
it "returns
|
100
|
+
it "returns true if MSpec exclude filters match this spec" do
|
69
101
|
@filter.should_receive(:===).and_return(true)
|
70
102
|
MSpec.register :exclude, @filter
|
71
|
-
@state.
|
103
|
+
@state.filtered?.should == true
|
72
104
|
end
|
73
105
|
|
74
|
-
it "returns
|
106
|
+
it "returns true if MSpec include and exclude filters match this spec" do
|
75
107
|
@filter.should_receive(:===).twice.and_return(true)
|
76
108
|
MSpec.register :include, @filter
|
77
109
|
MSpec.register :exclude, @filter
|
78
|
-
@state.unfiltered?.should == false
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe ExampleState, "#filtered?" do
|
83
|
-
before :each do
|
84
|
-
@state = ExampleState.new("describe", "it")
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns true if #unfiltered returns false" do
|
88
|
-
@state.should_receive(:unfiltered?).and_return(false)
|
89
110
|
@state.filtered?.should == true
|
90
111
|
end
|
91
|
-
|
92
|
-
it "returns false if #unfiltered returns true" do
|
93
|
-
@state.should_receive(:unfiltered?).and_return(true)
|
94
|
-
@state.filtered?.should == false
|
95
|
-
end
|
96
112
|
end
|
@@ -5,7 +5,8 @@ require 'mspec/runner/exception'
|
|
5
5
|
|
6
6
|
describe ExceptionState, "#initialize" do
|
7
7
|
it "takes a state, location (e.g. before :each), and exception" do
|
8
|
-
|
8
|
+
context = ContextState.new "Class#method"
|
9
|
+
state = ExampleState.new context, "does something"
|
9
10
|
exc = Exception.new "Fail!"
|
10
11
|
ExceptionState.new(state, "location", exc).should be_kind_of(ExceptionState)
|
11
12
|
end
|
@@ -13,7 +14,8 @@ end
|
|
13
14
|
|
14
15
|
describe ExceptionState, "#description" do
|
15
16
|
before :each do
|
16
|
-
|
17
|
+
context = ContextState.new "Class#method"
|
18
|
+
@state = ExampleState.new context, "does something"
|
17
19
|
end
|
18
20
|
|
19
21
|
it "returns the state description if state was not nil" do
|
@@ -34,7 +36,8 @@ end
|
|
34
36
|
|
35
37
|
describe ExceptionState, "#describe" do
|
36
38
|
before :each do
|
37
|
-
|
39
|
+
context = ContextState.new "Class#method"
|
40
|
+
@state = ExampleState.new context, "does something"
|
38
41
|
end
|
39
42
|
|
40
43
|
it "returns the ExampleState#describe string if created with a non-nil state" do
|
@@ -48,7 +51,8 @@ end
|
|
48
51
|
|
49
52
|
describe ExceptionState, "#it" do
|
50
53
|
before :each do
|
51
|
-
|
54
|
+
context = ContextState.new "Class#method"
|
55
|
+
@state = ExampleState.new context, "does something"
|
52
56
|
end
|
53
57
|
|
54
58
|
it "returns the ExampleState#it string if created with a non-nil state" do
|
@@ -62,7 +66,7 @@ end
|
|
62
66
|
|
63
67
|
describe ExceptionState, "#failure?" do
|
64
68
|
before :each do
|
65
|
-
@state = ExampleState.new "C#m", "works"
|
69
|
+
@state = ExampleState.new ContextState.new("C#m"), "works"
|
66
70
|
end
|
67
71
|
|
68
72
|
it "returns true if the exception is an ExpectationNotMetError" do
|
@@ -145,7 +145,7 @@ end
|
|
145
145
|
|
146
146
|
describe DottedFormatter, "#before" do
|
147
147
|
before :each do
|
148
|
-
@state = ExampleState.new("describe", "it"
|
148
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
149
149
|
@formatter = DottedFormatter.new
|
150
150
|
@formatter.exception ExceptionState.new(nil, nil, ExpectationNotMetError.new("Failed!"))
|
151
151
|
end
|
@@ -167,7 +167,7 @@ describe DottedFormatter, "#after" do
|
|
167
167
|
before :each do
|
168
168
|
$stdout = @out = IOStub.new
|
169
169
|
@formatter = DottedFormatter.new
|
170
|
-
@state = ExampleState.new("describe", "it"
|
170
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
171
171
|
end
|
172
172
|
|
173
173
|
after :each do
|
@@ -211,7 +211,8 @@ describe DottedFormatter, "#finish" do
|
|
211
211
|
TimerAction.stub!(:new).and_return(@timer)
|
212
212
|
|
213
213
|
$stdout = @out = IOStub.new
|
214
|
-
|
214
|
+
context = ContextState.new "Class#method"
|
215
|
+
@state = ExampleState.new(context, "runs")
|
215
216
|
MSpec.stub!(:register)
|
216
217
|
@formatter = DottedFormatter.new
|
217
218
|
@formatter.register
|
@@ -95,7 +95,7 @@ describe HtmlFormatter, "#exception" do
|
|
95
95
|
$stdout = @out = IOStub.new
|
96
96
|
@formatter = HtmlFormatter.new
|
97
97
|
@formatter.register
|
98
|
-
@state = ExampleState.new("describe", "it"
|
98
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
99
99
|
end
|
100
100
|
|
101
101
|
after :each do
|
@@ -119,7 +119,7 @@ describe HtmlFormatter, "#after" do
|
|
119
119
|
$stdout = @out = IOStub.new
|
120
120
|
@formatter = HtmlFormatter.new
|
121
121
|
@formatter.register
|
122
|
-
@state = ExampleState.new("describe", "it"
|
122
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
123
123
|
end
|
124
124
|
|
125
125
|
after :each do
|
@@ -148,7 +148,8 @@ describe HtmlFormatter, "#finish" do
|
|
148
148
|
TimerAction.stub!(:new).and_return(@timer)
|
149
149
|
|
150
150
|
$stdout = @out = IOStub.new
|
151
|
-
|
151
|
+
context = ContextState.new "describe"
|
152
|
+
@state = ExampleState.new(context, "it")
|
152
153
|
MSpec.stub!(:register)
|
153
154
|
@formatter = HtmlFormatter.new
|
154
155
|
@formatter.register
|
@@ -34,7 +34,7 @@ describe SpecdocFormatter, "#before" do
|
|
34
34
|
before :each do
|
35
35
|
$stdout = @out = IOStub.new
|
36
36
|
@formatter = SpecdocFormatter.new
|
37
|
-
@state = ExampleState.new "describe", "it"
|
37
|
+
@state = ExampleState.new ContextState.new("describe"), "it"
|
38
38
|
end
|
39
39
|
|
40
40
|
after :each do
|
@@ -59,7 +59,8 @@ describe SpecdocFormatter, "#exception" do
|
|
59
59
|
before :each do
|
60
60
|
$stdout = @out = IOStub.new
|
61
61
|
@formatter = SpecdocFormatter.new
|
62
|
-
|
62
|
+
context = ContextState.new "describe"
|
63
|
+
@state = ExampleState.new context, "it"
|
63
64
|
end
|
64
65
|
|
65
66
|
after :each do
|
@@ -7,7 +7,8 @@ describe SummaryFormatter, "#after" do
|
|
7
7
|
$stdout = @out = IOStub.new
|
8
8
|
@formatter = SummaryFormatter.new
|
9
9
|
@formatter.register
|
10
|
-
|
10
|
+
context = ContextState.new "describe"
|
11
|
+
@state = ExampleState.new(context, "it")
|
11
12
|
end
|
12
13
|
|
13
14
|
after :each do
|
@@ -10,7 +10,8 @@ describe UnitdiffFormatter, "#finish" do
|
|
10
10
|
TimerAction.stub!(:new).and_return(@timer)
|
11
11
|
|
12
12
|
$stdout = @out = IOStub.new
|
13
|
-
|
13
|
+
context = ContextState.new "describe"
|
14
|
+
@state = ExampleState.new(context, "it")
|
14
15
|
MSpec.stub!(:register)
|
15
16
|
@formatter = UnitdiffFormatter.new
|
16
17
|
@formatter.register
|
@@ -57,7 +57,8 @@ describe YamlFormatter, "#finish" do
|
|
57
57
|
TimerAction.stub!(:new).and_return(@timer)
|
58
58
|
|
59
59
|
$stdout = IOStub.new
|
60
|
-
|
60
|
+
context = ContextState.new "describe"
|
61
|
+
@state = ExampleState.new(context, "it")
|
61
62
|
|
62
63
|
@formatter = YamlFormatter.new
|
63
64
|
@formatter.stub!(:backtrace).and_return("")
|
data/spec/runner/mspec_spec.rb
CHANGED
@@ -87,11 +87,12 @@ end
|
|
87
87
|
|
88
88
|
describe MSpec, ".protect" do
|
89
89
|
before :each do
|
90
|
-
MSpec.
|
91
|
-
@
|
92
|
-
@cs = ContextState.new
|
90
|
+
MSpec.clear_current
|
91
|
+
@cs = ContextState.new "C#m"
|
93
92
|
@cs.stub!(:state).and_return(@es)
|
94
|
-
MSpec.
|
93
|
+
@cs.parent = MSpec.current
|
94
|
+
|
95
|
+
@es = ExampleState.new @cs, "runs"
|
95
96
|
ScratchPad.record Exception.new("Sharp!")
|
96
97
|
end
|
97
98
|
|
@@ -107,6 +108,15 @@ describe MSpec, ".protect" do
|
|
107
108
|
MSpec.protect("") { raise Exception, "Now you see me..." }
|
108
109
|
end
|
109
110
|
|
111
|
+
it "does not rescue SystemExit" do
|
112
|
+
begin
|
113
|
+
MSpec.protect("") { exit 1 }
|
114
|
+
rescue SystemExit
|
115
|
+
ScratchPad.record :system_exit
|
116
|
+
end
|
117
|
+
ScratchPad.recorded.should == :system_exit
|
118
|
+
end
|
119
|
+
|
110
120
|
it "calls all the exception actions" do
|
111
121
|
exc = ExceptionState.new @es, "testing", ScratchPad.recorded
|
112
122
|
ExceptionState.stub!(:new).and_return(exc)
|
@@ -123,18 +133,43 @@ describe MSpec, ".protect" do
|
|
123
133
|
end
|
124
134
|
end
|
125
135
|
|
126
|
-
describe MSpec, ".
|
127
|
-
|
128
|
-
MSpec.
|
136
|
+
describe MSpec, ".register_current" do
|
137
|
+
before :each do
|
138
|
+
MSpec.clear_current
|
139
|
+
end
|
140
|
+
|
141
|
+
it "sets the value returned by MSpec.current" do
|
142
|
+
MSpec.current.should be_nil
|
143
|
+
MSpec.register_current :a
|
144
|
+
MSpec.current.should == :a
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe MSpec, ".clear_current" do
|
149
|
+
it "sets the value returned by MSpec.current to nil" do
|
150
|
+
MSpec.register_current :a
|
151
|
+
MSpec.current.should_not be_nil
|
152
|
+
MSpec.clear_current
|
153
|
+
MSpec.current.should be_nil
|
129
154
|
end
|
130
155
|
end
|
131
156
|
|
132
157
|
describe MSpec, ".current" do
|
133
|
-
|
134
|
-
MSpec.
|
135
|
-
|
136
|
-
|
137
|
-
|
158
|
+
before :each do
|
159
|
+
MSpec.clear_current
|
160
|
+
end
|
161
|
+
|
162
|
+
it "returns nil if no ContextState has been registered" do
|
163
|
+
MSpec.current.should be_nil
|
164
|
+
end
|
165
|
+
|
166
|
+
it "returns the most recently registered ContextState" do
|
167
|
+
first = ContextState.new ""
|
168
|
+
second = ContextState.new ""
|
169
|
+
MSpec.register_current first
|
170
|
+
MSpec.current.should == first
|
171
|
+
MSpec.register_current second
|
172
|
+
MSpec.current.should == second
|
138
173
|
end
|
139
174
|
end
|
140
175
|
|
@@ -187,23 +222,32 @@ end
|
|
187
222
|
|
188
223
|
describe MSpec, ".describe" do
|
189
224
|
before :each do
|
190
|
-
MSpec.
|
225
|
+
MSpec.clear_current
|
226
|
+
@cs = ContextState.new ""
|
227
|
+
ContextState.stub!(:new).and_return(@cs)
|
228
|
+
MSpec.stub!(:current).and_return(nil)
|
229
|
+
MSpec.stub!(:register_current)
|
191
230
|
end
|
192
231
|
|
193
|
-
it "
|
194
|
-
|
195
|
-
|
232
|
+
it "creates a new ContextState for the block" do
|
233
|
+
ContextState.should_receive(:new).and_return(@cs)
|
234
|
+
MSpec.describe(Object) { }
|
196
235
|
end
|
197
236
|
|
198
|
-
it "
|
199
|
-
|
200
|
-
|
237
|
+
it "accepts an optional second argument" do
|
238
|
+
ContextState.should_receive(:new).and_return(@cs)
|
239
|
+
MSpec.describe(Object, "msg") { }
|
201
240
|
end
|
202
241
|
|
203
|
-
it "
|
204
|
-
MSpec.
|
205
|
-
|
206
|
-
|
242
|
+
it "registers the newly created ContextState" do
|
243
|
+
MSpec.should_receive(:register_current).with(@cs).twice
|
244
|
+
MSpec.describe(Object) { }
|
245
|
+
end
|
246
|
+
|
247
|
+
it "invokes the ContextState#describe method" do
|
248
|
+
prc = lambda { }
|
249
|
+
@cs.should_receive(:describe).with(&prc)
|
250
|
+
MSpec.describe(Object, "msg", &prc)
|
207
251
|
end
|
208
252
|
end
|
209
253
|
|
@@ -419,3 +463,23 @@ describe MSpec, ".clear_expectations" do
|
|
419
463
|
MSpec.expectation?.should be_false
|
420
464
|
end
|
421
465
|
end
|
466
|
+
|
467
|
+
describe MSpec, ".register_shared" do
|
468
|
+
it "stores a shared ContextState by description" do
|
469
|
+
parent = ContextState.new "container"
|
470
|
+
state = ContextState.new "shared"
|
471
|
+
state.parent = parent
|
472
|
+
prc = lambda { }
|
473
|
+
state.describe(&prc)
|
474
|
+
MSpec.register_shared(state)
|
475
|
+
MSpec.retrieve(:shared)["shared"].should == state
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
describe MSpec, ".retrieve_shared" do
|
480
|
+
it "retrieves the shared ContextState matching description" do
|
481
|
+
state = ContextState.new ""
|
482
|
+
MSpec.retrieve(:shared)["shared"] = state
|
483
|
+
MSpec.retrieve_shared(:shared).should == state
|
484
|
+
end
|
485
|
+
end
|