mspec 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,146 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/runner/mspec'
3
+ require 'mspec/commands/mspec-run'
4
+
5
+ describe MSpecRun, "#options" do
6
+ before :each do
7
+ @stdout, $stdout = $stdout, IOStub.new
8
+
9
+ @argv = ["a", "b"]
10
+ @options, @config = new_option
11
+ MSpecOptions.stub!(:new).and_return(@options)
12
+
13
+ @script = MSpecRun.new
14
+ @script.stub!(:config).and_return(@config)
15
+ end
16
+
17
+ after :each do
18
+ $stdout = @stdout
19
+ end
20
+
21
+ it "enables the filter options" do
22
+ @options.should_receive(:add_filters)
23
+ @script.options @argv
24
+ end
25
+
26
+ it "enables the config option" do
27
+ @options.should_receive(:add_config)
28
+ @script.options @argv
29
+ end
30
+
31
+ it "provides a custom action (block) to the config option" do
32
+ @script.should_receive(:load).with("cfg.mspec")
33
+ @script.options ["-B", "cfg.mspec", "a"]
34
+ end
35
+
36
+ it "enables the name option" do
37
+ @options.should_receive(:add_name)
38
+ @script.options @argv
39
+ end
40
+
41
+ it "enables the tags dir option" do
42
+ @options.should_receive(:add_tags_dir)
43
+ @script.options @argv
44
+ end
45
+
46
+ it "enables the randomize option to runs specs in random order" do
47
+ @options.should_receive(:add_randomize)
48
+ @script.options @argv
49
+ end
50
+
51
+ it "enables the dry run option" do
52
+ @options.should_receive(:add_pretend)
53
+ @script.options @argv
54
+ end
55
+
56
+ it "enables the interrupt single specs option" do
57
+ @options.should_receive(:add_interrupt)
58
+ @script.options @argv
59
+ end
60
+
61
+ it "enables the formatter options" do
62
+ @options.should_receive(:add_formatters)
63
+ @script.options @argv
64
+ end
65
+
66
+ it "enables the verbose option" do
67
+ @options.should_receive(:add_verbose)
68
+ @script.options @argv
69
+ end
70
+
71
+ it "enables the verify options" do
72
+ @options.should_receive(:add_verify)
73
+ @script.options @argv
74
+ end
75
+
76
+ it "enables the action options" do
77
+ @options.should_receive(:add_actions)
78
+ @script.options @argv
79
+ end
80
+
81
+ it "enables the action filter options" do
82
+ @options.should_receive(:add_action_filters)
83
+ @script.options @argv
84
+ end
85
+
86
+ it "enables the version option" do
87
+ @options.should_receive(:add_version)
88
+ @script.options @argv
89
+ end
90
+
91
+ it "enables the help option" do
92
+ @options.should_receive(:add_help)
93
+ @script.options @argv
94
+ end
95
+
96
+ it "exits if there are no files to process" do
97
+ @options.should_receive(:parse).and_return([])
98
+ @script.should_receive(:exit)
99
+ @script.options
100
+ $stdout.should =~ /No files specified/
101
+ end
102
+ end
103
+
104
+ describe MSpecRun, "#run" do
105
+ before :each do
106
+ MSpec.stub!(:process)
107
+
108
+ stat = mock("stat")
109
+ stat.stub!(:file?).and_return(true)
110
+ stat.stub!(:directory?).and_return(false)
111
+ File.stub!(:expand_path)
112
+ File.stub!(:stat).and_return(stat)
113
+
114
+ options = mock("MSpecOptions", :null_object => true)
115
+ options.stub!(:parse).and_return(["one", "two"])
116
+ MSpecOptions.stub!(:new).and_return(options)
117
+
118
+ @config = { }
119
+ @script = MSpecRun.new
120
+ @script.stub!(:exit)
121
+ @script.stub!(:config).and_return(@config)
122
+ @script.options
123
+ end
124
+
125
+ it "registers the tags directory path" do
126
+ @config[:tags_dir] = "tags_dir"
127
+ MSpec.should_receive(:register_tags_path).with("tags_dir")
128
+ @script.run
129
+ end
130
+
131
+ it "registers the files to process" do
132
+ MSpec.should_receive(:register_files).with(["one", "two"])
133
+ @script.run
134
+ end
135
+
136
+ it "processes the files" do
137
+ MSpec.should_receive(:process)
138
+ @script.run
139
+ end
140
+
141
+ it "exits with the exit code registered with MSpec" do
142
+ MSpec.stub!(:exit_code).and_return(7)
143
+ @script.should_receive(:exit).with(7)
144
+ @script.run
145
+ end
146
+ end
@@ -0,0 +1,359 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'yaml'
3
+ require 'mspec/commands/mspec'
4
+
5
+ describe MSpecMain, "#options" do
6
+ before :each do
7
+ @options, @config = new_option
8
+ @options.stub!(:parser).and_return(mock("parser"))
9
+ @options.parser.stub!(:filter!).and_return(["blocked!"])
10
+ MSpecOptions.stub!(:new).and_return(@options)
11
+
12
+ @script = MSpecMain.new
13
+ @script.stub!(:config).and_return(@config)
14
+ end
15
+
16
+ it "enables the config option" do
17
+ @options.should_receive(:add_config)
18
+ @script.options
19
+ end
20
+
21
+ it "provides a custom action (block) to the config option" do
22
+ @script.options ["-B", "config"]
23
+ @config[:options].should include("-B", "config")
24
+ end
25
+
26
+ it "enables the target options" do
27
+ @options.should_receive(:add_targets)
28
+ @script.options
29
+ end
30
+
31
+ it "enables the version option" do
32
+ @options.should_receive(:add_version)
33
+ @script.options
34
+ end
35
+ end
36
+
37
+ describe MSpecMain, "#parallel" do
38
+ before :all do
39
+ @verbose, $VERBOSE = $VERBOSE, nil
40
+ end
41
+
42
+ after :all do
43
+ $VERBOSE = @verbose
44
+ end
45
+
46
+ before :each do
47
+ @script = MSpecMain.new
48
+ @ruby_platform = Object.const_get :RUBY_PLATFORM
49
+ end
50
+
51
+ after :each do
52
+ Object.const_set :RUBY_PLATFORM, @ruby_platform
53
+ end
54
+
55
+ it "returns false if JRUBY_VERSION is defined" do
56
+ Object.should_receive(:const_defined?).with(:JRUBY_VERSION).and_return(true)
57
+ @script.parallel.should == false
58
+ end
59
+
60
+ it "returns false if RUBY_PLATFORM matches mswin" do
61
+ Object.const_set :RUBY_PLATFORM, "i386-mswin32"
62
+ @script.parallel.should == false
63
+ end
64
+
65
+ it "returns false if RUBY_PLATFORM matches mingw" do
66
+ Object.const_set :RUBY_PLATFORM, "i386-mingw32"
67
+ @script.parallel.should == false
68
+ end
69
+
70
+ it "returns true unless JRUBY_VERSION is set or RUBY_PLATFORM matches mswin or mingw" do
71
+ Object.should_receive(:const_defined?).with(:JRUBY_VERSION).and_return(false)
72
+ Object.const_set :RUBY_PLATFORM, "i686-linux"
73
+ @script.parallel.should == true
74
+ end
75
+ end
76
+
77
+ describe MSpecMain, "#fork" do
78
+ before :each do
79
+ @script = MSpecMain.new
80
+ ScratchPad.clear
81
+ end
82
+
83
+ it "calls Kernel.fork if #parallel returns true" do
84
+ @script.should_receive(:parallel).and_return(true)
85
+ Kernel.should_receive(:fork)
86
+ @script.fork
87
+ end
88
+
89
+ it "calls the block if #parallel returns false" do
90
+ @script.should_receive(:parallel).and_return(false)
91
+ Kernel.should_not_receive(:fork)
92
+ @script.fork { ScratchPad.record :called }
93
+ ScratchPad.recorded.should == :called
94
+ end
95
+ end
96
+
97
+ describe MSpecMain, "#report" do
98
+ before :each do
99
+ @stdout, $stdout = $stdout, IOStub.new
100
+
101
+ @timer = mock("timer", :null_object => true)
102
+ @timer.stub!(:format).and_return("Finished in 42 seconds")
103
+ @file = mock("file", :null_object => true)
104
+
105
+ File.stub!(:delete)
106
+ YAML.stub!(:load)
107
+
108
+ @hash = { "files"=>1, "examples"=>1, "expectations"=>2, "failures"=>0, "errors"=>0 }
109
+ File.stub!(:open).and_yield(@file).and_return(@hash)
110
+
111
+ @script = MSpecMain.new
112
+ end
113
+
114
+ after :each do
115
+ $stdout = @stdout
116
+ end
117
+
118
+ it "calls YAML.load for each element in the passed array" do
119
+ YAML.should_receive(:load).with(@file).twice
120
+ @script.report(["a", "b"], @timer)
121
+ end
122
+
123
+ it "calls File.delete for each element in the passed array" do
124
+ File.should_receive(:delete).with("a")
125
+ File.should_receive(:delete).with("b")
126
+ @script.report(["a", "b"], @timer)
127
+ end
128
+
129
+ it "outputs a summary without errors" do
130
+ @script.report(["a", "b"], @timer)
131
+ $stdout.should ==
132
+ %[
133
+
134
+ Finished in 42 seconds
135
+
136
+ 2 files, 2 examples, 4 expectations, 0 failures, 0 errors
137
+ ]
138
+ end
139
+
140
+ it "outputs a summary with errors" do
141
+ @hash["exceptions"] = [
142
+ "Some#method works real good FAILED\nExpected real good\n to equal fail\n\nfoo.rb:1\nfoo.rb:2",
143
+ "Some#method never fails ERROR\nExpected 5\n to equal 3\n\nfoo.rb:1\nfoo.rb:2"
144
+ ]
145
+ @script.report(["a"], @timer)
146
+ $stdout.should ==
147
+ %[
148
+
149
+ 1)
150
+ Some#method works real good FAILED
151
+ Expected real good
152
+ to equal fail
153
+
154
+ foo.rb:1
155
+ foo.rb:2
156
+
157
+ 2)
158
+ Some#method never fails ERROR
159
+ Expected 5
160
+ to equal 3
161
+
162
+ foo.rb:1
163
+ foo.rb:2
164
+
165
+ Finished in 42 seconds
166
+
167
+ 1 file, 1 example, 2 expectations, 0 failures, 0 errors
168
+ ]
169
+ end
170
+ end
171
+
172
+ describe MSpecMain, "#multi_exec" do
173
+ before :each do
174
+ @options, @config = new_option
175
+ MSpecOptions.stub!(:new).and_return(@options)
176
+
177
+ @config[:target] = "target"
178
+ @config[:ci_files] = ["a", "b"]
179
+
180
+ @script = MSpecMain.new
181
+ @script.stub!(:config).and_return(@config)
182
+ @script.stub!(:fork)
183
+ @script.stub!(:report)
184
+ Process.stub!(:waitall)
185
+ end
186
+
187
+ it "calls #fork for each entry in config[:ci_files]" do
188
+ @script.should_receive(:fork).twice
189
+ @script.multi_exec []
190
+ end
191
+
192
+ it "calls Process.waitall" do
193
+ Process.should_receive(:waitall)
194
+ @script.multi_exec []
195
+ end
196
+
197
+ it "calls #report" do
198
+ @script.should_receive(:report)
199
+ @script.multi_exec []
200
+ end
201
+ end
202
+
203
+ describe MSpecMain, "#run" do
204
+ before :each do
205
+ @options, @config = new_option
206
+ MSpecOptions.stub!(:new).and_return(@options)
207
+ @script = MSpecMain.new
208
+ end
209
+
210
+ it "sets MSPEC_RUNNER = '1' in the environment" do
211
+ @script.stub!(:exec)
212
+ ENV["MSPEC_RUNNER"] = "0"
213
+ @script.run
214
+ ENV["MSPEC_RUNNER"].should == "1"
215
+ end
216
+
217
+ it "uses exec to invoke the runner script" do
218
+ @script.should_receive(:exec).with("ruby", %r"mspec/bin/mspec-run$")
219
+ @script.options
220
+ @script.run
221
+ end
222
+
223
+ it "calls #multi_exec if the command is 'ci' and the multi option is passed" do
224
+ @script.should_receive(:multi_exec).and_return do |arg|
225
+ arg.length.should == 2
226
+ arg.first.should =~ %r"mspec/bin/mspec-ci$"
227
+ arg.last.should == "-fy"
228
+ end
229
+ @script.options ["ci", "-j"]
230
+ @script.run
231
+ end
232
+ end
233
+
234
+ describe "The -D, --gdb option" do
235
+ before :each do
236
+ @options, @config = new_option
237
+ MSpecOptions.stub!(:new).and_return(@options)
238
+ @script = MSpecMain.new
239
+ @script.stub!(:config).and_return(@config)
240
+ end
241
+
242
+ it "is enabled by #options" do
243
+ @options.stub!(:on)
244
+ @options.should_receive(:on).with("-D", "--gdb", an_instance_of(String))
245
+ @script.options
246
+ end
247
+
248
+ it "sets flags to --gdb" do
249
+ ["-D", "--gdb"].each do |opt|
250
+ @config[:flags] = []
251
+ @script.options [opt]
252
+ @config[:flags].should include("--gdb")
253
+ end
254
+ end
255
+ end
256
+
257
+ describe "The -A, --valgrind option" do
258
+ before :each do
259
+ @options, @config = new_option
260
+ MSpecOptions.stub!(:new).and_return(@options)
261
+ @script = MSpecMain.new
262
+ @script.stub!(:config).and_return(@config)
263
+ end
264
+
265
+ it "is enabled by #options" do
266
+ @options.stub!(:on)
267
+ @options.should_receive(:on).with("-A", "--valgrind", an_instance_of(String))
268
+ @script.options
269
+ end
270
+
271
+ it "sets flags to --valgrind" do
272
+ ["-A", "--valgrind"].each do |opt|
273
+ @config[:flags] = []
274
+ @script.options [opt]
275
+ @config[:flags].should include("--valgrind")
276
+ end
277
+ end
278
+ end
279
+
280
+ describe "The --warnings option" do
281
+ before :each do
282
+ @options, @config = new_option
283
+ MSpecOptions.stub!(:new).and_return(@options)
284
+ @script = MSpecMain.new
285
+ @script.stub!(:config).and_return(@config)
286
+ end
287
+
288
+ it "is enabled by #options" do
289
+ @options.stub!(:on)
290
+ @options.should_receive(:on).with("--warnings", an_instance_of(String))
291
+ @script.options
292
+ end
293
+
294
+ it "sets flags to -w" do
295
+ @config[:flags] = []
296
+ @script.options ["--warnings"]
297
+ @config[:flags].should include("-w")
298
+ end
299
+
300
+ it "set OUTPUT_WARNINGS = '1' in the environment" do
301
+ ENV['OUTPUT_WARNINGS'] = '0'
302
+ @script.options ["--warnings"]
303
+ ENV['OUTPUT_WARNINGS'].should == '1'
304
+ end
305
+ end
306
+
307
+ describe "The -j, --multi option" do
308
+ before :each do
309
+ @options, @config = new_option
310
+ MSpecOptions.stub!(:new).and_return(@options)
311
+ @script = MSpecMain.new
312
+ @script.stub!(:config).and_return(@config)
313
+ end
314
+
315
+ it "is enabled by #options" do
316
+ @options.stub!(:on)
317
+ @options.should_receive(:on).with("-j", "--multi", an_instance_of(String))
318
+ @script.options
319
+ end
320
+
321
+ it "sets the multiple process option" do
322
+ ["-j", "--multi"].each do |opt|
323
+ @config[:multi] = nil
324
+ @script.options [opt]
325
+ @config[:multi].should == true
326
+ end
327
+ end
328
+
329
+ it "sets the formatter to YamlFormatter" do
330
+ ["-j", "--multi"].each do |opt|
331
+ @config[:options] = []
332
+ @script.options [opt]
333
+ @config[:options].should include("-fy")
334
+ end
335
+ end
336
+ end
337
+
338
+ describe "The -h, --help option" do
339
+ before :each do
340
+ @options, @config = new_option
341
+ MSpecOptions.stub!(:new).and_return(@options)
342
+ @script = MSpecMain.new
343
+ @script.stub!(:config).and_return(@config)
344
+ end
345
+
346
+ it "is enabled by #options" do
347
+ @options.stub!(:on)
348
+ @options.should_receive(:on).with("-h", "--help", an_instance_of(String))
349
+ @script.options
350
+ end
351
+
352
+ it "prints help and exits" do
353
+ @script.should_receive(:puts).twice
354
+ @script.should_receive(:exit).twice
355
+ ["-h", "--help"].each do |opt|
356
+ @script.options [opt]
357
+ end
358
+ end
359
+ end