mspec 1.0.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.
Files changed (162) hide show
  1. data/LICENSE +22 -0
  2. data/README +101 -0
  3. data/Rakefile +44 -0
  4. data/bin/mkspec +7 -0
  5. data/bin/mspec +7 -0
  6. data/bin/mspec-ci +8 -0
  7. data/bin/mspec-run +8 -0
  8. data/bin/mspec-tag +8 -0
  9. data/lib/mspec.rb +6 -0
  10. data/lib/mspec/commands/mkspec.rb +147 -0
  11. data/lib/mspec/commands/mspec-ci.rb +71 -0
  12. data/lib/mspec/commands/mspec-run.rb +80 -0
  13. data/lib/mspec/commands/mspec-tag.rb +87 -0
  14. data/lib/mspec/commands/mspec.rb +143 -0
  15. data/lib/mspec/expectations.rb +2 -0
  16. data/lib/mspec/expectations/expectations.rb +12 -0
  17. data/lib/mspec/expectations/should.rb +23 -0
  18. data/lib/mspec/guards.rb +13 -0
  19. data/lib/mspec/guards/bug.rb +27 -0
  20. data/lib/mspec/guards/compliance.rb +18 -0
  21. data/lib/mspec/guards/conflict.rb +16 -0
  22. data/lib/mspec/guards/endian.rb +40 -0
  23. data/lib/mspec/guards/extensions.rb +12 -0
  24. data/lib/mspec/guards/guard.rb +120 -0
  25. data/lib/mspec/guards/noncompliance.rb +12 -0
  26. data/lib/mspec/guards/platform.rb +38 -0
  27. data/lib/mspec/guards/quarantine.rb +15 -0
  28. data/lib/mspec/guards/runner.rb +30 -0
  29. data/lib/mspec/guards/superuser.rb +15 -0
  30. data/lib/mspec/guards/support.rb +12 -0
  31. data/lib/mspec/guards/version.rb +40 -0
  32. data/lib/mspec/helpers.rb +6 -0
  33. data/lib/mspec/helpers/bignum.rb +5 -0
  34. data/lib/mspec/helpers/const_lookup.rb +5 -0
  35. data/lib/mspec/helpers/flunk.rb +5 -0
  36. data/lib/mspec/helpers/io.rb +13 -0
  37. data/lib/mspec/helpers/scratch.rb +17 -0
  38. data/lib/mspec/helpers/tmp.rb +32 -0
  39. data/lib/mspec/matchers.rb +16 -0
  40. data/lib/mspec/matchers/base.rb +95 -0
  41. data/lib/mspec/matchers/be_ancestor_of.rb +24 -0
  42. data/lib/mspec/matchers/be_close.rb +27 -0
  43. data/lib/mspec/matchers/be_empty.rb +20 -0
  44. data/lib/mspec/matchers/be_false.rb +20 -0
  45. data/lib/mspec/matchers/be_kind_of.rb +24 -0
  46. data/lib/mspec/matchers/be_nil.rb +20 -0
  47. data/lib/mspec/matchers/be_true.rb +20 -0
  48. data/lib/mspec/matchers/complain.rb +56 -0
  49. data/lib/mspec/matchers/eql.rb +26 -0
  50. data/lib/mspec/matchers/equal.rb +26 -0
  51. data/lib/mspec/matchers/equal_utf16.rb +34 -0
  52. data/lib/mspec/matchers/include.rb +32 -0
  53. data/lib/mspec/matchers/output.rb +67 -0
  54. data/lib/mspec/matchers/output_to_fd.rb +71 -0
  55. data/lib/mspec/matchers/raise_error.rb +48 -0
  56. data/lib/mspec/mocks.rb +3 -0
  57. data/lib/mspec/mocks/mock.rb +123 -0
  58. data/lib/mspec/mocks/object.rb +28 -0
  59. data/lib/mspec/mocks/proxy.rb +112 -0
  60. data/lib/mspec/runner.rb +13 -0
  61. data/lib/mspec/runner/actions.rb +6 -0
  62. data/lib/mspec/runner/actions/debug.rb +17 -0
  63. data/lib/mspec/runner/actions/filter.rb +40 -0
  64. data/lib/mspec/runner/actions/gdb.rb +17 -0
  65. data/lib/mspec/runner/actions/tag.rb +97 -0
  66. data/lib/mspec/runner/actions/tally.rb +80 -0
  67. data/lib/mspec/runner/actions/timer.rb +22 -0
  68. data/lib/mspec/runner/filters.rb +4 -0
  69. data/lib/mspec/runner/filters/match.rb +22 -0
  70. data/lib/mspec/runner/filters/profile.rb +54 -0
  71. data/lib/mspec/runner/filters/regexp.rb +7 -0
  72. data/lib/mspec/runner/filters/tag.rb +29 -0
  73. data/lib/mspec/runner/formatters.rb +7 -0
  74. data/lib/mspec/runner/formatters/dotted.rb +81 -0
  75. data/lib/mspec/runner/formatters/html.rb +87 -0
  76. data/lib/mspec/runner/formatters/specdoc.rb +27 -0
  77. data/lib/mspec/runner/formatters/spinner.rb +89 -0
  78. data/lib/mspec/runner/formatters/summary.rb +8 -0
  79. data/lib/mspec/runner/formatters/unit.rb +25 -0
  80. data/lib/mspec/runner/formatters/yaml.rb +43 -0
  81. data/lib/mspec/runner/mspec.rb +232 -0
  82. data/lib/mspec/runner/object.rb +20 -0
  83. data/lib/mspec/runner/shared.rb +12 -0
  84. data/lib/mspec/runner/state.rb +116 -0
  85. data/lib/mspec/runner/tag.rb +20 -0
  86. data/lib/mspec/utils/name_map.rb +130 -0
  87. data/lib/mspec/utils/options.rb +344 -0
  88. data/lib/mspec/utils/script.rb +77 -0
  89. data/lib/mspec/version.rb +3 -0
  90. data/spec/commands/mkspec_spec.rb +321 -0
  91. data/spec/commands/mspec_ci_spec.rb +139 -0
  92. data/spec/commands/mspec_run_spec.rb +146 -0
  93. data/spec/commands/mspec_spec.rb +359 -0
  94. data/spec/commands/mspec_tag_spec.rb +131 -0
  95. data/spec/expectations/expectations_spec.rb +16 -0
  96. data/spec/expectations/should_spec.rb +99 -0
  97. data/spec/guards/bug_spec.rb +137 -0
  98. data/spec/guards/compliance_spec.rb +70 -0
  99. data/spec/guards/conflict_spec.rb +20 -0
  100. data/spec/guards/endian_spec.rb +42 -0
  101. data/spec/guards/extensions_spec.rb +36 -0
  102. data/spec/guards/guard_spec.rb +355 -0
  103. data/spec/guards/noncompliance_spec.rb +36 -0
  104. data/spec/guards/platform_spec.rb +84 -0
  105. data/spec/guards/quarantine_spec.rb +19 -0
  106. data/spec/guards/runner_spec.rb +75 -0
  107. data/spec/guards/superuser_spec.rb +22 -0
  108. data/spec/guards/support_spec.rb +22 -0
  109. data/spec/guards/version_spec.rb +133 -0
  110. data/spec/helpers/bignum_spec.rb +11 -0
  111. data/spec/helpers/const_lookup_spec.rb +19 -0
  112. data/spec/helpers/flunk_spec.rb +15 -0
  113. data/spec/helpers/io_spec.rb +34 -0
  114. data/spec/helpers/scratch_spec.rb +22 -0
  115. data/spec/helpers/tmp_spec.rb +72 -0
  116. data/spec/matchers/base_spec.rb +180 -0
  117. data/spec/matchers/be_ancestor_of_spec.rb +28 -0
  118. data/spec/matchers/be_close_spec.rb +46 -0
  119. data/spec/matchers/be_empty_spec.rb +26 -0
  120. data/spec/matchers/be_false_spec.rb +28 -0
  121. data/spec/matchers/be_kind_of_spec.rb +29 -0
  122. data/spec/matchers/be_nil_spec.rb +27 -0
  123. data/spec/matchers/be_true_spec.rb +28 -0
  124. data/spec/matchers/complain_spec.rb +52 -0
  125. data/spec/matchers/eql_spec.rb +33 -0
  126. data/spec/matchers/equal_spec.rb +33 -0
  127. data/spec/matchers/equal_utf16_spec.rb +47 -0
  128. data/spec/matchers/include_spec.rb +37 -0
  129. data/spec/matchers/output_spec.rb +74 -0
  130. data/spec/matchers/output_to_fd_spec.rb +33 -0
  131. data/spec/matchers/raise_error_spec.rb +56 -0
  132. data/spec/mocks/mock_spec.rb +272 -0
  133. data/spec/mocks/proxy_spec.rb +259 -0
  134. data/spec/runner/actions/debug_spec.rb +61 -0
  135. data/spec/runner/actions/filter_spec.rb +84 -0
  136. data/spec/runner/actions/gdb_spec.rb +61 -0
  137. data/spec/runner/actions/tag_spec.rb +253 -0
  138. data/spec/runner/actions/tally_spec.rb +107 -0
  139. data/spec/runner/actions/timer_spec.rb +42 -0
  140. data/spec/runner/filters/a.yaml +4 -0
  141. data/spec/runner/filters/b.yaml +11 -0
  142. data/spec/runner/filters/match_spec.rb +44 -0
  143. data/spec/runner/filters/profile_spec.rb +117 -0
  144. data/spec/runner/filters/regexp_spec.rb +13 -0
  145. data/spec/runner/filters/tag_spec.rb +77 -0
  146. data/spec/runner/formatters/dotted_spec.rb +184 -0
  147. data/spec/runner/formatters/html_spec.rb +191 -0
  148. data/spec/runner/formatters/specdoc_spec.rb +57 -0
  149. data/spec/runner/formatters/spinner_spec.rb +78 -0
  150. data/spec/runner/formatters/summary_spec.rb +29 -0
  151. data/spec/runner/formatters/unit_spec.rb +71 -0
  152. data/spec/runner/formatters/yaml_spec.rb +123 -0
  153. data/spec/runner/mspec_spec.rb +393 -0
  154. data/spec/runner/shared_spec.rb +41 -0
  155. data/spec/runner/state_spec.rb +535 -0
  156. data/spec/runner/tag_spec.rb +93 -0
  157. data/spec/runner/tags.txt +3 -0
  158. data/spec/spec_helper.rb +46 -0
  159. data/spec/utils/name_map_spec.rb +178 -0
  160. data/spec/utils/options_spec.rb +862 -0
  161. data/spec/utils/script_spec.rb +240 -0
  162. metadata +217 -0
@@ -0,0 +1,191 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/guards/guard'
3
+ require 'mspec/runner/formatters/html'
4
+ require 'mspec/runner/mspec'
5
+ require 'mspec/runner/state'
6
+
7
+ describe HtmlFormatter do
8
+ before :each do
9
+ @formatter = HtmlFormatter.new
10
+ end
11
+
12
+ it "responds to #register by registering itself with MSpec for appropriate actions" do
13
+ MSpec.stub!(:register)
14
+ MSpec.should_receive(:register).with(:start, @formatter)
15
+ MSpec.should_receive(:register).with(:enter, @formatter)
16
+ MSpec.should_receive(:register).with(:leave, @formatter)
17
+ @formatter.register
18
+ end
19
+ end
20
+
21
+ describe HtmlFormatter, "#start" do
22
+ before :each do
23
+ $stdout = @out = IOStub.new
24
+ @formatter = HtmlFormatter.new
25
+ end
26
+
27
+ after :each do
28
+ $stdout = STDOUT
29
+ end
30
+
31
+ it "prints the HTML head" do
32
+ @formatter.start
33
+ ruby_name = RUBY_NAME
34
+ ruby_name.should =~ /^ruby/
35
+ @out.should ==
36
+ %[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
37
+ "http://www.w3.org/TR/html4/strict.dtd">
38
+ <html>
39
+ <head>
40
+ <title>Spec Output For #{ruby_name} (1.8.6)</title>
41
+ <style type="text/css">
42
+ ul {
43
+ list-style: none;
44
+ }
45
+ .fail {
46
+ color: red;
47
+ }
48
+ .pass {
49
+ color: green;
50
+ }
51
+ #details :target {
52
+ background-color: #ffffe0;
53
+ }
54
+ </style>
55
+ </head>
56
+ <body>
57
+ ]
58
+ end
59
+ end
60
+
61
+ describe HtmlFormatter, "#enter" do
62
+ before :each do
63
+ $stdout = @out = IOStub.new
64
+ @formatter = HtmlFormatter.new
65
+ end
66
+
67
+ after :each do
68
+ $stdout = STDOUT
69
+ end
70
+
71
+ it "prints the #describe string" do
72
+ @formatter.enter "describe"
73
+ @out.should == "<div><p>describe</p>\n<ul>\n"
74
+ end
75
+ end
76
+
77
+ describe HtmlFormatter, "#leave" do
78
+ before :each do
79
+ $stdout = @out = IOStub.new
80
+ @formatter = HtmlFormatter.new
81
+ end
82
+
83
+ after :each do
84
+ $stdout = STDOUT
85
+ end
86
+
87
+ it "prints the closing tags for the #describe string" do
88
+ @formatter.leave
89
+ @out.should == "</ul>\n</div>\n"
90
+ end
91
+ end
92
+
93
+ describe HtmlFormatter, "#after" do
94
+ before :each do
95
+ $stdout = @out = IOStub.new
96
+ @formatter = HtmlFormatter.new
97
+ @state = SpecState.new("describe", "it")
98
+ end
99
+
100
+ after :each do
101
+ $stdout = STDOUT
102
+ end
103
+
104
+ it "prints the #it once when there are no exceptions raised" do
105
+ @formatter.after @state
106
+ @out.should == %[<li class="pass">- it</li>\n]
107
+ end
108
+
109
+ it "prints the #it string once for each exception raised" do
110
+ @formatter.register
111
+ @state.exceptions << ["msg", ExpectationNotMetError.new("disappointing")]
112
+ @state.exceptions << ["msg", MSpecExampleError.new("painful")]
113
+ @formatter.tally.after @state
114
+ @formatter.after @state
115
+ @out.should ==
116
+ %[<li class="fail">- it (<a href="#details-1">FAILED - 1</a>)</li>
117
+ <li class="fail">- it (<a href="#details-2">ERROR - 2</a>)</li>
118
+ ]
119
+ end
120
+ end
121
+
122
+ describe HtmlFormatter, "#finish" do
123
+ before :each do
124
+ @tally = mock("tally", :null_object => true)
125
+ TallyAction.stub!(:new).and_return(@tally)
126
+ @timer = mock("timer", :null_object => true)
127
+ TimerAction.stub!(:new).and_return(@timer)
128
+
129
+ $stdout = @out = IOStub.new
130
+ @state = SpecState.new("describe", "it")
131
+ MSpec.stub!(:register)
132
+ @formatter = HtmlFormatter.new
133
+ @formatter.register
134
+ @exception = MSpecExampleError.new("broken")
135
+ @exception.stub!(:backtrace).and_return(["file.rb:1", "file.rb:2"])
136
+ end
137
+
138
+ after :each do
139
+ $stdout = STDOUT
140
+ end
141
+
142
+ it "prints a failure message for an exception" do
143
+ @state.exceptions << ["msg", @exception]
144
+ @formatter.instance_variable_set :@states, [@state]
145
+ @formatter.finish
146
+ @out.should =~ %r[<p>describe it ERROR</p>]
147
+ end
148
+
149
+ it "prints a backtrace for an exception" do
150
+ @formatter.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
151
+ @state.exceptions << ["msg", @exception]
152
+ @formatter.instance_variable_set :@states, [@state]
153
+ @formatter.finish
154
+ @out.should =~ %r[<pre>.*path/to/some/file.rb:35:in method.*</pre>]m
155
+ end
156
+
157
+ it "prints a summary of elapsed time" do
158
+ @timer.should_receive(:format).and_return("Finished in 2.0 seconds")
159
+ @formatter.finish
160
+ @out.should =~ %r[<p>Finished in 2.0 seconds</p>\n]
161
+ end
162
+
163
+ it "prints a tally of counts" do
164
+ @tally.should_receive(:format).and_return("1 example, 0 failures")
165
+ @formatter.finish
166
+ @out.should =~ %r[<p class="pass">1 example, 0 failures</p>]
167
+ end
168
+
169
+ it "prints errors, backtraces, elapsed time, and tallies" do
170
+ @state.exceptions << ["msg", @exception]
171
+ @formatter.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
172
+ @timer.should_receive(:format).and_return("Finished in 2.0 seconds")
173
+ @tally.should_receive(:format).and_return("1 example, 1 failures")
174
+ @formatter.instance_variable_set :@states, [@state]
175
+ @formatter.finish
176
+ @out.should ==
177
+ %[<hr>
178
+ <ol id="details">
179
+ <li id="details-1"><p>describe it ERROR</p>
180
+ <p>MSpecExampleError: broken</p>
181
+ <pre>
182
+ path/to/some/file.rb:35:in method</pre>
183
+ </li>
184
+ </ol>
185
+ <p>Finished in 2.0 seconds</p>
186
+ <p class="fail">1 example, 1 failures</p>
187
+ </body>
188
+ </html>
189
+ ]
190
+ end
191
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/formatters/specdoc'
3
+ require 'mspec/runner/state'
4
+
5
+ describe SpecdocFormatter do
6
+ before :each do
7
+ @formatter = SpecdocFormatter.new
8
+ end
9
+
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)
13
+ @formatter.register
14
+ end
15
+ end
16
+
17
+ describe SpecdocFormatter, "#enter" do
18
+ before :each do
19
+ $stdout = @out = IOStub.new
20
+ @formatter = SpecdocFormatter.new
21
+ end
22
+
23
+ after :each do
24
+ $stdout = STDOUT
25
+ end
26
+
27
+ it "prints the #describe string" do
28
+ @formatter.enter("describe")
29
+ @out.should == "\ndescribe\n"
30
+ end
31
+ end
32
+
33
+ describe SpecdocFormatter, "#after" do
34
+ before :each do
35
+ $stdout = @out = IOStub.new
36
+ @formatter = SpecdocFormatter.new
37
+ @state = SpecState.new("describe", "it")
38
+ end
39
+
40
+ after :each do
41
+ $stdout = STDOUT
42
+ end
43
+
44
+ it "prints the #it once when there are no exceptions raised" do
45
+ @formatter.after @state
46
+ @out.should == "- it\n"
47
+ end
48
+
49
+ it "prints the #it string once for each exception raised" do
50
+ @formatter.register
51
+ @state.exceptions << ["msg", ExpectationNotMetError.new("disappointing")]
52
+ @state.exceptions << ["msg", Exception.new("painful")]
53
+ @formatter.tally.after @state
54
+ @formatter.after @state
55
+ @out.should == "- it (FAILED - 1)\n- it (ERROR - 2)\n"
56
+ end
57
+ end
@@ -0,0 +1,78 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/formatters/spinner'
3
+ require 'mspec/runner/mspec'
4
+ require 'mspec/runner/state'
5
+
6
+ describe SpinnerFormatter, "#initialize" do
7
+ it "permits zero arguments" do
8
+ SpinnerFormatter.new
9
+ end
10
+
11
+ it "accepts one argument" do
12
+ SpinnerFormatter.new nil
13
+ end
14
+ end
15
+
16
+ describe SpinnerFormatter, "#register" do
17
+ before :each do
18
+ @formatter = SpinnerFormatter.new
19
+ end
20
+
21
+ it "registers self with MSpec for appropriate actions" do
22
+ MSpec.stub!(:register)
23
+ MSpec.should_receive(:register).with(:start, @formatter)
24
+ MSpec.should_receive(:register).with(:load, @formatter)
25
+ MSpec.should_receive(:register).with(:after, @formatter)
26
+ MSpec.should_receive(:register).with(:finish, @formatter)
27
+ @formatter.register
28
+ end
29
+
30
+ it "creates TimerAction and TallyAction" do
31
+ timer = mock("timer")
32
+ tally = mock("tally")
33
+ timer.should_receive(:register)
34
+ tally.should_receive(:register)
35
+ tally.should_receive(:counter)
36
+ TimerAction.should_receive(:new).and_return(timer)
37
+ TallyAction.should_receive(:new).and_return(tally)
38
+ @formatter.register
39
+ end
40
+ end
41
+
42
+ describe SpinnerFormatter, "#print" do
43
+ after :each do
44
+ $stdout = STDOUT
45
+ end
46
+
47
+ it "ignores the argument to #initialize and writes to $stdout" do
48
+ $stdout = IOStub.new
49
+ formatter = SpinnerFormatter.new "some/file"
50
+ formatter.print "begonias"
51
+ $stdout.should == "begonias"
52
+ end
53
+ end
54
+
55
+ describe SpinnerFormatter, "#after" do
56
+ before :each do
57
+ $stdout = IOStub.new
58
+ MSpec.stub!(:retrieve).and_return(["a", "b"])
59
+ @formatter = SpinnerFormatter.new
60
+ @formatter.register
61
+ @state = SpecState.new("describe", "it")
62
+ end
63
+
64
+ after :each do
65
+ $stdout = STDOUT
66
+ end
67
+
68
+ it "updates the spinner" do
69
+ @formatter.start
70
+ @formatter.load
71
+ @formatter.after @state
72
+ @formatter.after @state
73
+ $stdout.should == "\r[/ | ======== 20% | 00:00:00] " \
74
+ "\e[0;32m 0F \e[0;32m 0E\e[0m" \
75
+ "\r[- | ======== 20% | 00:00:00] " \
76
+ "\e[0;32m 0F \e[0;32m 0E\e[0m"
77
+ end
78
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/formatters/summary'
3
+ require 'mspec/runner/state'
4
+
5
+ describe SummaryFormatter, "#after" do
6
+ before :each do
7
+ $stdout = @out = IOStub.new
8
+ @formatter = SummaryFormatter.new
9
+ @state = SpecState.new("describe", "it")
10
+ end
11
+
12
+ after :each do
13
+ $stdout = STDOUT
14
+ end
15
+
16
+ it "does not print anything" do
17
+ MSpec.stub!(:register)
18
+ tally = mock("tally", :null_object => true)
19
+ tally.stub!(:failures).and_return(1)
20
+ tally.stub!(:errors).and_return(1)
21
+ TallyAction.stub!(:new).and_return(tally)
22
+
23
+ @formatter.register
24
+ @state.exceptions << ExpectationNotMetError.new("disappointing")
25
+ @state.exceptions << Exception.new("painful")
26
+ @formatter.after(@state)
27
+ @out.should == ""
28
+ end
29
+ end
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/formatters/unit'
3
+ require 'mspec/runner/state'
4
+
5
+ describe UnitdiffFormatter, "#finish" do
6
+ before :each do
7
+ @tally = mock("tally", :null_object => true)
8
+ TallyAction.stub!(:new).and_return(@tally)
9
+ @timer = mock("timer", :null_object => true)
10
+ TimerAction.stub!(:new).and_return(@timer)
11
+
12
+ $stdout = @out = IOStub.new
13
+ @state = SpecState.new("describe", "it")
14
+ MSpec.stub!(:register)
15
+ @formatter = UnitdiffFormatter.new
16
+ @formatter.register
17
+ end
18
+
19
+ after :each do
20
+ $stdout = STDOUT
21
+ end
22
+
23
+ it "prints a failure message for an exception" do
24
+ @state.exceptions << ["msg", Exception.new("broken")]
25
+ @formatter.after @state
26
+ @formatter.finish
27
+ @out.should =~ /^1\)\ndescribe it ERROR$/
28
+ end
29
+
30
+ it "prints a backtrace for an exception" do
31
+ @formatter.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
32
+ @state.exceptions << ["msg", Exception.new("broken")]
33
+ @formatter.after @state
34
+ @formatter.finish
35
+ @out.should =~ %r[path/to/some/file.rb:35:in method$]
36
+ end
37
+
38
+ it "prints a summary of elapsed time" do
39
+ @timer.should_receive(:format).and_return("Finished in 2.0 seconds")
40
+ @formatter.finish
41
+ @out.should =~ /^Finished in 2.0 seconds$/
42
+ end
43
+
44
+ it "prints a tally of counts" do
45
+ @tally.should_receive(:format).and_return("1 example, 0 failures")
46
+ @formatter.finish
47
+ @out.should =~ /^1 example, 0 failures$/
48
+ end
49
+
50
+ it "prints errors, backtraces, elapsed time, and tallies" do
51
+ @state.exceptions << ["msg", Exception.new("broken")]
52
+ @formatter.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
53
+ @timer.should_receive(:format).and_return("Finished in 2.0 seconds")
54
+ @tally.should_receive(:format).and_return("1 example, 0 failures")
55
+ @formatter.after @state
56
+ @formatter.finish
57
+ @out.should ==
58
+ %[E
59
+
60
+ Finished in 2.0 seconds
61
+
62
+ 1)
63
+ describe it ERROR
64
+ Exception occurred during: msg
65
+ broken:
66
+ path/to/some/file.rb:35:in method
67
+
68
+ 1 example, 0 failures
69
+ ]
70
+ end
71
+ end
@@ -0,0 +1,123 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/formatters/yaml'
3
+ require 'mspec/runner/state'
4
+
5
+ describe YamlFormatter, "#initialize" do
6
+ it "permits zero arguments" do
7
+ YamlFormatter.new
8
+ end
9
+
10
+ it "accepts one argument" do
11
+ YamlFormatter.new nil
12
+ end
13
+ end
14
+
15
+ describe YamlFormatter, "#print" do
16
+ before :each do
17
+ $stdout = IOStub.new
18
+ @out = IOStub.new
19
+ File.stub!(:open).and_return(@out)
20
+ @formatter = YamlFormatter.new "some/file"
21
+ end
22
+
23
+ after :each do
24
+ $stdout = STDOUT
25
+ end
26
+
27
+ it "writes to $stdout if #switch has not been called" do
28
+ @formatter.print "begonias"
29
+ $stdout.should == "begonias"
30
+ @out.should == ""
31
+ end
32
+
33
+ it "writes to the file passed to #initialize once #switch has been called" do
34
+ @formatter.switch
35
+ @formatter.print "begonias"
36
+ $stdout.should == ""
37
+ @out.should == "begonias"
38
+ end
39
+
40
+ it "writes to $stdout once #switch is called if no file was passed to #initialize" do
41
+ formatter = YamlFormatter.new
42
+ formatter.switch
43
+ formatter.print "begonias"
44
+ $stdout.should == "begonias"
45
+ @out.should == ""
46
+ end
47
+ end
48
+
49
+ describe YamlFormatter, "#finish" do
50
+ before :each do
51
+ @tally = mock("tally", :null_object => true)
52
+ @counter = mock("counter", :null_object => true)
53
+ @tally.stub!(:counter).and_return(@counter)
54
+ TallyAction.stub!(:new).and_return(@tally)
55
+
56
+ @timer = mock("timer", :null_object => true)
57
+ TimerAction.stub!(:new).and_return(@timer)
58
+
59
+ $stdout = IOStub.new
60
+ @state = SpecState.new("describe", "it")
61
+ @state.exceptions << ["msg", MSpecExampleError.new("broken")]
62
+
63
+ @formatter = YamlFormatter.new
64
+ @formatter.stub!(:backtrace).and_return("")
65
+ MSpec.stub!(:register)
66
+ @formatter.register
67
+ @formatter.after @state
68
+ end
69
+
70
+ after :each do
71
+ $stdout = STDOUT
72
+ end
73
+
74
+ it "calls #switch" do
75
+ @formatter.should_receive(:switch)
76
+ @formatter.finish
77
+ end
78
+
79
+ it "outputs a failure message and backtrace" do
80
+ @formatter.should_receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
81
+ @formatter.finish
82
+ $stdout.should =~ /describe it ERROR/
83
+ $stdout.should =~ /MSpecExampleError occurred during: msg/
84
+ $stdout.should =~ /MSpecExampleError: broken/
85
+ $stdout.should =~ %r[path/to/some/file.rb:35:in method]
86
+ end
87
+
88
+ it "outputs an elapsed time" do
89
+ @timer.should_receive(:elapsed).and_return(4.2)
90
+ @formatter.finish
91
+ $stdout.should =~ /time: 4.2/
92
+ end
93
+
94
+ it "outputs a file count" do
95
+ @counter.should_receive(:files).and_return(3)
96
+ @formatter.finish
97
+ $stdout.should =~ /files: 3/
98
+ end
99
+
100
+ it "outputs an example count" do
101
+ @counter.should_receive(:examples).and_return(3)
102
+ @formatter.finish
103
+ $stdout.should =~ /examples: 3/
104
+ end
105
+
106
+ it "outputs an expectation count" do
107
+ @counter.should_receive(:expectations).and_return(9)
108
+ @formatter.finish
109
+ $stdout.should =~ /expectations: 9/
110
+ end
111
+
112
+ it "outputs a failure count" do
113
+ @counter.should_receive(:failures).and_return(2)
114
+ @formatter.finish
115
+ $stdout.should =~ /failures: 2/
116
+ end
117
+
118
+ it "outputs an error count" do
119
+ @counter.should_receive(:errors).and_return(1)
120
+ @formatter.finish
121
+ $stdout.should =~ /errors: 1/
122
+ end
123
+ end