mspec 1.1.1 → 1.2.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/Rakefile +1 -1
- data/lib/mspec/runner/actions/tag.rb +41 -7
- data/lib/mspec/runner/actions/tally.rb +16 -7
- data/lib/mspec/runner/{state.rb → context.rb} +22 -54
- data/lib/mspec/runner/example.rb +37 -0
- data/lib/mspec/runner/exception.rb +39 -0
- data/lib/mspec/runner/formatters/dotted.rb +61 -45
- data/lib/mspec/runner/formatters/html.rb +16 -22
- data/lib/mspec/runner/formatters/specdoc.rb +24 -11
- data/lib/mspec/runner/formatters/spinner.rb +20 -10
- data/lib/mspec/runner/formatters/summary.rb +4 -1
- data/lib/mspec/runner/formatters/unit.rb +5 -9
- data/lib/mspec/runner/formatters/yaml.rb +11 -10
- data/lib/mspec/runner/mspec.rb +15 -16
- data/lib/mspec/version.rb +1 -1
- data/spec/runner/actions/debug_spec.rb +2 -2
- data/spec/runner/actions/gdb_spec.rb +2 -2
- data/spec/runner/actions/tag_spec.rb +76 -22
- data/spec/runner/actions/tally_spec.rb +26 -6
- data/spec/runner/{state_spec.rb → context_spec.rb} +80 -167
- data/spec/runner/example_spec.rb +96 -0
- data/spec/runner/exception_spec.rb +110 -0
- data/spec/runner/formatters/dotted_spec.rb +117 -27
- data/spec/runner/formatters/html_spec.rb +44 -21
- data/spec/runner/formatters/specdoc_spec.rb +52 -12
- data/spec/runner/formatters/spinner_spec.rb +2 -2
- data/spec/runner/formatters/summary_spec.rb +7 -11
- data/spec/runner/formatters/unit_spec.rb +12 -11
- data/spec/runner/formatters/yaml_spec.rb +7 -6
- data/spec/runner/mspec_spec.rb +28 -29
- metadata +7 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'mspec/runner/formatters/specdoc'
|
3
|
-
require 'mspec/runner/
|
3
|
+
require 'mspec/runner/example'
|
4
4
|
|
5
5
|
describe SpecdocFormatter do
|
6
6
|
before :each do
|
@@ -30,28 +30,68 @@ describe SpecdocFormatter, "#enter" do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe SpecdocFormatter, "#
|
33
|
+
describe SpecdocFormatter, "#before" do
|
34
34
|
before :each do
|
35
35
|
$stdout = @out = IOStub.new
|
36
36
|
@formatter = SpecdocFormatter.new
|
37
|
-
@state =
|
37
|
+
@state = ExampleState.new "describe", "it"
|
38
38
|
end
|
39
39
|
|
40
40
|
after :each do
|
41
41
|
$stdout = STDOUT
|
42
42
|
end
|
43
43
|
|
44
|
-
it "prints the #it
|
45
|
-
@formatter.
|
46
|
-
@out.should == "- it
|
44
|
+
it "prints the #it string" do
|
45
|
+
@formatter.before @state
|
46
|
+
@out.should == "- it"
|
47
47
|
end
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
@
|
52
|
-
@
|
53
|
-
@
|
50
|
+
describe SpecdocFormatter, "#exception" do
|
51
|
+
before :each do
|
52
|
+
$stdout = @out = IOStub.new
|
53
|
+
@formatter = SpecdocFormatter.new
|
54
|
+
@state = ExampleState.new "describe", "it"
|
55
|
+
end
|
56
|
+
|
57
|
+
after :each do
|
58
|
+
$stdout = STDOUT
|
59
|
+
end
|
60
|
+
|
61
|
+
it "prints 'ERROR' if an exception is not an ExpectationNotMetError" do
|
62
|
+
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
|
63
|
+
@formatter.exception exc
|
64
|
+
@out.should == " (ERROR - 1)"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "prints 'FAILED' if an exception is an ExpectationNotMetError" do
|
68
|
+
exc = ExceptionState.new @state, nil, ExpectationNotMetError.new("disappointing")
|
69
|
+
@formatter.exception exc
|
70
|
+
@out.should == " (FAILED - 1)"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "prints the #it string if an exception has already been raised" do
|
74
|
+
exc = ExceptionState.new @state, nil, ExpectationNotMetError.new("disappointing")
|
75
|
+
@formatter.exception exc
|
76
|
+
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
|
77
|
+
@formatter.exception exc
|
78
|
+
@out.should == " (FAILED - 1)\n- it (ERROR - 2)"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe SpecdocFormatter, "#after" do
|
83
|
+
before :each do
|
84
|
+
$stdout = @out = IOStub.new
|
85
|
+
@formatter = SpecdocFormatter.new
|
86
|
+
@state = ExampleState.new "describe", "it"
|
87
|
+
end
|
88
|
+
|
89
|
+
after :each do
|
90
|
+
$stdout = STDOUT
|
91
|
+
end
|
92
|
+
|
93
|
+
it "prints a newline character" do
|
54
94
|
@formatter.after @state
|
55
|
-
@out.should == "
|
95
|
+
@out.should == "\n"
|
56
96
|
end
|
57
97
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'mspec/runner/formatters/spinner'
|
3
3
|
require 'mspec/runner/mspec'
|
4
|
-
require 'mspec/runner/
|
4
|
+
require 'mspec/runner/example'
|
5
5
|
|
6
6
|
describe SpinnerFormatter, "#initialize" do
|
7
7
|
it "permits zero arguments" do
|
@@ -58,7 +58,7 @@ describe SpinnerFormatter, "#after" do
|
|
58
58
|
MSpec.stub!(:retrieve).and_return(["a", "b"])
|
59
59
|
@formatter = SpinnerFormatter.new
|
60
60
|
@formatter.register
|
61
|
-
@state =
|
61
|
+
@state = ExampleState.new("describe", "it")
|
62
62
|
end
|
63
63
|
|
64
64
|
after :each do
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'mspec/runner/formatters/summary'
|
3
|
-
require 'mspec/runner/
|
3
|
+
require 'mspec/runner/example'
|
4
4
|
|
5
5
|
describe SummaryFormatter, "#after" do
|
6
6
|
before :each do
|
7
7
|
$stdout = @out = IOStub.new
|
8
8
|
@formatter = SummaryFormatter.new
|
9
|
-
@
|
9
|
+
@formatter.register
|
10
|
+
@state = ExampleState.new("describe", "it")
|
10
11
|
end
|
11
12
|
|
12
13
|
after :each do
|
@@ -14,15 +15,10 @@ describe SummaryFormatter, "#after" do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
it "does not print anything" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
TallyAction.stub!(:new).and_return(tally)
|
22
|
-
|
23
|
-
@formatter.register
|
24
|
-
@state.exceptions << ExpectationNotMetError.new("disappointing")
|
25
|
-
@state.exceptions << Exception.new("painful")
|
18
|
+
exc = ExceptionState.new @state, nil, ExpectationNotMetError.new("disappointing")
|
19
|
+
@formatter.exception exc
|
20
|
+
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
|
21
|
+
@formatter.exception exc
|
26
22
|
@formatter.after(@state)
|
27
23
|
@out.should == ""
|
28
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'mspec/runner/formatters/unit'
|
3
|
-
require 'mspec/runner/
|
3
|
+
require 'mspec/runner/example'
|
4
4
|
|
5
5
|
describe UnitdiffFormatter, "#finish" do
|
6
6
|
before :each do
|
@@ -10,7 +10,7 @@ describe UnitdiffFormatter, "#finish" do
|
|
10
10
|
TimerAction.stub!(:new).and_return(@timer)
|
11
11
|
|
12
12
|
$stdout = @out = IOStub.new
|
13
|
-
@state =
|
13
|
+
@state = ExampleState.new("describe", "it")
|
14
14
|
MSpec.stub!(:register)
|
15
15
|
@formatter = UnitdiffFormatter.new
|
16
16
|
@formatter.register
|
@@ -21,16 +21,17 @@ describe UnitdiffFormatter, "#finish" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "prints a failure message for an exception" do
|
24
|
-
@state
|
24
|
+
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
|
25
|
+
@formatter.exception exc
|
25
26
|
@formatter.after @state
|
26
27
|
@formatter.finish
|
27
28
|
@out.should =~ /^1\)\ndescribe it ERROR$/
|
28
29
|
end
|
29
30
|
|
30
31
|
it "prints a backtrace for an exception" do
|
31
|
-
@
|
32
|
-
|
33
|
-
@formatter.
|
32
|
+
exc = ExceptionState.new @state, nil, Exception.new("broken")
|
33
|
+
exc.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
34
|
+
@formatter.exception exc
|
34
35
|
@formatter.finish
|
35
36
|
@out.should =~ %r[path/to/some/file.rb:35:in method$]
|
36
37
|
end
|
@@ -48,11 +49,12 @@ describe UnitdiffFormatter, "#finish" do
|
|
48
49
|
end
|
49
50
|
|
50
51
|
it "prints errors, backtraces, elapsed time, and tallies" do
|
51
|
-
@state
|
52
|
-
|
52
|
+
exc = ExceptionState.new @state, nil, Exception.new("broken")
|
53
|
+
exc.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
54
|
+
@formatter.exception exc
|
55
|
+
@formatter.after @state
|
53
56
|
@timer.should_receive(:format).and_return("Finished in 2.0 seconds")
|
54
57
|
@tally.should_receive(:format).and_return("1 example, 0 failures")
|
55
|
-
@formatter.after @state
|
56
58
|
@formatter.finish
|
57
59
|
@out.should ==
|
58
60
|
%[E
|
@@ -61,8 +63,7 @@ Finished in 2.0 seconds
|
|
61
63
|
|
62
64
|
1)
|
63
65
|
describe it ERROR
|
64
|
-
Exception
|
65
|
-
broken:
|
66
|
+
Exception: broken:
|
66
67
|
path/to/some/file.rb:35:in method
|
67
68
|
|
68
69
|
1 example, 0 failures
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'mspec/runner/formatters/yaml'
|
3
|
-
require 'mspec/runner/
|
3
|
+
require 'mspec/runner/example'
|
4
4
|
|
5
5
|
describe YamlFormatter, "#initialize" do
|
6
6
|
it "permits zero arguments" do
|
@@ -57,13 +57,16 @@ describe YamlFormatter, "#finish" do
|
|
57
57
|
TimerAction.stub!(:new).and_return(@timer)
|
58
58
|
|
59
59
|
$stdout = IOStub.new
|
60
|
-
@state =
|
61
|
-
@state.exceptions << ["msg", MSpecExampleError.new("broken")]
|
60
|
+
@state = ExampleState.new("describe", "it")
|
62
61
|
|
63
62
|
@formatter = YamlFormatter.new
|
64
63
|
@formatter.stub!(:backtrace).and_return("")
|
65
64
|
MSpec.stub!(:register)
|
66
65
|
@formatter.register
|
66
|
+
|
67
|
+
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
|
68
|
+
exc.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
69
|
+
@formatter.exception exc
|
67
70
|
@formatter.after @state
|
68
71
|
end
|
69
72
|
|
@@ -77,11 +80,9 @@ describe YamlFormatter, "#finish" do
|
|
77
80
|
end
|
78
81
|
|
79
82
|
it "outputs a failure message and backtrace" do
|
80
|
-
@formatter.should_receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
81
83
|
@formatter.finish
|
82
84
|
$stdout.should =~ /describe it ERROR/
|
83
|
-
$stdout.should =~ /MSpecExampleError
|
84
|
-
$stdout.should =~ /MSpecExampleError: broken/
|
85
|
+
$stdout.should =~ /MSpecExampleError: broken\\n/
|
85
86
|
$stdout.should =~ %r[path/to/some/file.rb:35:in method]
|
86
87
|
end
|
87
88
|
|
data/spec/runner/mspec_spec.rb
CHANGED
@@ -87,39 +87,38 @@ end
|
|
87
87
|
|
88
88
|
describe MSpec, ".protect" do
|
89
89
|
before :each do
|
90
|
-
|
91
|
-
@
|
92
|
-
@
|
93
|
-
@
|
94
|
-
@
|
95
|
-
ScratchPad.record
|
90
|
+
MSpec.stack.clear
|
91
|
+
@es = ExampleState.new "C#m", "runs"
|
92
|
+
@cs = ContextState.new
|
93
|
+
@cs.stub!(:state).and_return(@es)
|
94
|
+
MSpec.stack.push @cs
|
95
|
+
ScratchPad.record Exception.new("Sharp!")
|
96
96
|
end
|
97
97
|
|
98
|
-
it "
|
99
|
-
MSpec.
|
100
|
-
lambda {
|
101
|
-
MSpec.protect("") { raise Exception, "Now you see me..." }
|
102
|
-
}.should_not raise_error
|
98
|
+
it "returns true if no exception is raised" do
|
99
|
+
MSpec.protect("passed") { 1 }.should be_true
|
103
100
|
end
|
104
101
|
|
105
|
-
it "
|
106
|
-
MSpec.
|
107
|
-
MSpec.protect("testing") { raise ScratchPad.recorded }
|
108
|
-
@ss.exceptions.should == [["testing", ScratchPad.recorded]]
|
102
|
+
it "returns false if an exception is raised" do
|
103
|
+
MSpec.protect("testing") { raise ScratchPad.recorded }.should be_false
|
109
104
|
end
|
110
105
|
|
111
|
-
it "
|
112
|
-
|
113
|
-
|
114
|
-
|
106
|
+
it "rescues any exceptions raised when evaluating the block argument" do
|
107
|
+
MSpec.protect("") { raise Exception, "Now you see me..." }
|
108
|
+
end
|
109
|
+
|
110
|
+
it "calls all the exception actions" do
|
111
|
+
exc = ExceptionState.new @es, "testing", ScratchPad.recorded
|
112
|
+
ExceptionState.stub!(:new).and_return(exc)
|
113
|
+
action = mock("exception")
|
114
|
+
action.should_receive(:exception).with(exc)
|
115
|
+
MSpec.register :exception, action
|
115
116
|
MSpec.protect("testing") { raise ScratchPad.recorded }
|
117
|
+
MSpec.unregister :exception, action
|
116
118
|
end
|
117
119
|
|
118
|
-
it "
|
119
|
-
|
120
|
-
STDERR.should_receive(:write).with("\nAn exception occurred in testing:\nException: \"Sharp!\"\n")
|
121
|
-
@rs.stub!(:state).and_return(nil)
|
122
|
-
MSpec.stack.push @rs
|
120
|
+
it "registers a non-zero exit code when an exception is raised" do
|
121
|
+
MSpec.should_receive(:register_exit).with(1)
|
123
122
|
MSpec.protect("testing") { raise ScratchPad.recorded }
|
124
123
|
end
|
125
124
|
end
|
@@ -193,17 +192,17 @@ describe MSpec, ".describe" do
|
|
193
192
|
|
194
193
|
it "accepts one argument" do
|
195
194
|
MSpec.describe(Object) { ScratchPad.record MSpec.current }
|
196
|
-
ScratchPad.recorded.should be_kind_of(
|
195
|
+
ScratchPad.recorded.should be_kind_of(ContextState)
|
197
196
|
end
|
198
197
|
|
199
|
-
it "pushes a new
|
198
|
+
it "pushes a new ContextState instance on the stack" do
|
200
199
|
MSpec.describe(Object, "msg") { ScratchPad.record MSpec.current }
|
201
|
-
ScratchPad.recorded.should be_kind_of(
|
200
|
+
ScratchPad.recorded.should be_kind_of(ContextState)
|
202
201
|
end
|
203
202
|
|
204
|
-
it "pops the
|
203
|
+
it "pops the ContextState instance off the stack when finished" do
|
205
204
|
MSpec.describe(Object, "msg") { ScratchPad.record MSpec.current }
|
206
|
-
ScratchPad.recorded.should be_kind_of(
|
205
|
+
ScratchPad.recorded.should be_kind_of(ContextState)
|
207
206
|
MSpec.stack.should == []
|
208
207
|
end
|
209
208
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Ford
|
@@ -85,6 +85,9 @@ files:
|
|
85
85
|
- lib/mspec/runner/actions/tally.rb
|
86
86
|
- lib/mspec/runner/actions/timer.rb
|
87
87
|
- lib/mspec/runner/actions.rb
|
88
|
+
- lib/mspec/runner/context.rb
|
89
|
+
- lib/mspec/runner/example.rb
|
90
|
+
- lib/mspec/runner/exception.rb
|
88
91
|
- lib/mspec/runner/filters/match.rb
|
89
92
|
- lib/mspec/runner/filters/profile.rb
|
90
93
|
- lib/mspec/runner/filters/regexp.rb
|
@@ -101,7 +104,6 @@ files:
|
|
101
104
|
- lib/mspec/runner/mspec.rb
|
102
105
|
- lib/mspec/runner/object.rb
|
103
106
|
- lib/mspec/runner/shared.rb
|
104
|
-
- lib/mspec/runner/state.rb
|
105
107
|
- lib/mspec/runner/tag.rb
|
106
108
|
- lib/mspec/runner.rb
|
107
109
|
- lib/mspec/utils/name_map.rb
|
@@ -163,6 +165,9 @@ files:
|
|
163
165
|
- spec/runner/actions/tag_spec.rb
|
164
166
|
- spec/runner/actions/tally_spec.rb
|
165
167
|
- spec/runner/actions/timer_spec.rb
|
168
|
+
- spec/runner/context_spec.rb
|
169
|
+
- spec/runner/example_spec.rb
|
170
|
+
- spec/runner/exception_spec.rb
|
166
171
|
- spec/runner/filters/match_spec.rb
|
167
172
|
- spec/runner/filters/profile_spec.rb
|
168
173
|
- spec/runner/filters/regexp_spec.rb
|
@@ -176,7 +181,6 @@ files:
|
|
176
181
|
- spec/runner/formatters/yaml_spec.rb
|
177
182
|
- spec/runner/mspec_spec.rb
|
178
183
|
- spec/runner/shared_spec.rb
|
179
|
-
- spec/runner/state_spec.rb
|
180
184
|
- spec/runner/tag_spec.rb
|
181
185
|
- spec/spec_helper.rb
|
182
186
|
- spec/utils/name_map_spec.rb
|