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,77 @@
1
+ require 'mspec/runner/formatters/dotted'
2
+
3
+ # MSpecScript provides a skeleton for all the MSpec runner scripts.
4
+
5
+ class MSpecScript
6
+ def self.config
7
+ @config ||= { :path => ['.', 'spec'] }
8
+ end
9
+
10
+ def self.set(key, value)
11
+ config[key] = value
12
+ end
13
+
14
+ def initialize
15
+ config[:tags_dir] = 'spec/tags'
16
+ config[:formatter] = DottedFormatter
17
+ config[:includes] = []
18
+ config[:excludes] = []
19
+ config[:patterns] = []
20
+ config[:xpatterns] = []
21
+ config[:tags] = []
22
+ config[:xtags] = []
23
+ config[:profiles] = []
24
+ config[:xprofiles] = []
25
+ config[:atags] = []
26
+ config[:astrings] = []
27
+ config[:abort] = true
28
+ end
29
+
30
+ def config
31
+ MSpecScript.config
32
+ end
33
+
34
+ def load(name)
35
+ return Kernel.load(name) if File.exist?(File.expand_path(name))
36
+
37
+ config[:path].each do |dir|
38
+ file = File.join dir, name
39
+ return Kernel.load(file) if File.exist? file
40
+ end
41
+ end
42
+
43
+ def register
44
+ config[:formatter].new(config[:output]).register
45
+
46
+ MatchFilter.new(:include, *config[:includes]).register unless config[:includes].empty?
47
+ MatchFilter.new(:exclude, *config[:excludes]).register unless config[:excludes].empty?
48
+ RegexpFilter.new(:include, *config[:patterns]).register unless config[:patterns].empty?
49
+ RegexpFilter.new(:exclude, *config[:xpatterns]).register unless config[:xpatterns].empty?
50
+ TagFilter.new(:include, *config[:tags]).register unless config[:tags].empty?
51
+ TagFilter.new(:exclude, *config[:xtags]).register unless config[:xtags].empty?
52
+ ProfileFilter.new(:include, *config[:profiles]).register unless config[:profiles].empty?
53
+ ProfileFilter.new(:exclude, *config[:xprofiles]).register unless config[:xprofiles].empty?
54
+
55
+ DebugAction.new(config[:atags], config[:astrings]).register if config[:debugger]
56
+ GdbAction.new(config[:atags], config[:astrings]).register if config[:gdb]
57
+ end
58
+
59
+ def signals
60
+ if config[:abort]
61
+ Signal.trap "INT" do
62
+ puts "\nProcess aborted!"
63
+ exit! 1
64
+ end
65
+ end
66
+ end
67
+
68
+ def self.main
69
+ script = new
70
+ script.load 'default.mspec'
71
+ script.load '~/.mspecrc'
72
+ script.options
73
+ script.signals
74
+ script.register
75
+ script.run
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module MSpec
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,321 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/commands/mkspec'
3
+
4
+
5
+ describe "The -c, --constant CONSTANT option" do
6
+ before :each do
7
+ @options = OptionParser.new
8
+ OptionParser.stub!(:new).and_return(@options)
9
+ @script = MkSpec.new
10
+ @config = @script.config
11
+ end
12
+
13
+ it "is enabled by #options" do
14
+ @options.stub!(:on)
15
+ @options.should_receive(:on).with("-c", "--constant CONSTANT",
16
+ String, an_instance_of(String))
17
+ @script.options
18
+ end
19
+
20
+ it "adds CONSTANT to the list of constants" do
21
+ ["-c", "--constant"].each do |opt|
22
+ @config[:constants] = []
23
+ @script.options [opt, "Object"]
24
+ @config[:constants].should include("Object")
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "The -b, --base DIR option" do
30
+ before :each do
31
+ @options = OptionParser.new
32
+ OptionParser.stub!(:new).and_return(@options)
33
+ @script = MkSpec.new
34
+ @config = @script.config
35
+ end
36
+
37
+ it "is enabled by #options" do
38
+ @options.stub!(:on)
39
+ @options.should_receive(:on).with("-b", "--base DIR",
40
+ String, an_instance_of(String))
41
+ @script.options
42
+ end
43
+
44
+ it "sets the base directory relative to which the spec directories are created" do
45
+ ["-b", "--base"].each do |opt|
46
+ @config[:base] = nil
47
+ @script.options [opt, "superspec"]
48
+ @config[:base].should == File.expand_path("superspec")
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "The -r, --require LIBRARY option" do
54
+ before :each do
55
+ @options = OptionParser.new
56
+ OptionParser.stub!(:new).and_return(@options)
57
+ @script = MkSpec.new
58
+ @config = @script.config
59
+ end
60
+
61
+ it "is enabled by #options" do
62
+ @options.stub!(:on)
63
+ @options.should_receive(:on).with("-r", "--require LIBRARY",
64
+ String, an_instance_of(String))
65
+ @script.options
66
+ end
67
+
68
+ it "adds CONSTANT to the list of constants" do
69
+ ["-r", "--require"].each do |opt|
70
+ @config[:requires] = []
71
+ @script.options [opt, "libspec"]
72
+ @config[:requires].should include("libspec")
73
+ end
74
+ end
75
+ end
76
+
77
+ describe MkSpec, "#options" do
78
+ before :each do
79
+ @options = OptionParser.new
80
+ OptionParser.stub!(:new).and_return(@options)
81
+ @script = MkSpec.new
82
+ end
83
+
84
+ it "parses the command line options" do
85
+ @options.should_receive(:parse).with(["--this", "and", "--that"])
86
+ @script.options ["--this", "and", "--that"]
87
+ end
88
+
89
+ it "parses ARGV unless passed other options" do
90
+ @options.should_receive(:parse).with(ARGV)
91
+ @script.options
92
+ end
93
+
94
+ it "prints help and exits if passed an unrecognized option" do
95
+ @script.should_receive(:puts).exactly(3).times
96
+ @script.should_receive(:exit)
97
+ @script.options "--iunknown"
98
+ end
99
+ end
100
+
101
+ describe MkSpec, "#create_directory" do
102
+ before :each do
103
+ @script = MkSpec.new
104
+ @script.config[:base] = "spec"
105
+ end
106
+
107
+ it "prints a warning if a file with the directory name exists" do
108
+ File.should_receive(:exist?).and_return(true)
109
+ File.should_receive(:directory?).and_return(false)
110
+ FileUtils.should_not_receive(:mkdir_p)
111
+ @script.should_receive(:puts).with("spec/class already exists and is not a directory.")
112
+ @script.create_directory("Class").should == nil
113
+ end
114
+
115
+ it "does nothing if the directory already exists" do
116
+ File.should_receive(:exist?).and_return(true)
117
+ File.should_receive(:directory?).and_return(true)
118
+ FileUtils.should_not_receive(:mkdir_p)
119
+ @script.create_directory("Class").should == "spec/class"
120
+ end
121
+
122
+ it "creates the directory if it does not exist" do
123
+ File.should_receive(:exist?).and_return(false)
124
+ FileUtils.should_receive(:mkdir_p).with("spec/class")
125
+ @script.create_directory("Class").should == "spec/class"
126
+ end
127
+
128
+ it "creates the directory for a namespaced module if it does not exist" do
129
+ File.should_receive(:exist?).and_return(false)
130
+ FileUtils.should_receive(:mkdir_p).with("spec/struct/tms")
131
+ @script.create_directory("Struct::Tms").should == "spec/struct/tms"
132
+ end
133
+ end
134
+
135
+ describe MkSpec, "#write_requires" do
136
+ before :each do
137
+ @script = MkSpec.new
138
+ @script.config[:base] = "spec"
139
+
140
+ @file = mock("file")
141
+ File.stub!(:open).and_yield(@file)
142
+ end
143
+
144
+ it "writes the spec_helper require line" do
145
+ @file.should_receive(:puts).with("require File.dirname(__FILE__) + '/../../../spec_helper'")
146
+ @script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
147
+ end
148
+
149
+ it "writes require lines for each library specified on the command line" do
150
+ @file.stub!(:puts)
151
+ @file.should_receive(:puts).with("require File.dirname(__FILE__) + '/../../../spec_helper'")
152
+ @file.should_receive(:puts).with("require 'complex'")
153
+ @script.config[:requires] << 'complex'
154
+ @script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
155
+ end
156
+ end
157
+
158
+ describe MkSpec, "#write_spec" do
159
+ before :each do
160
+ @file = mock("file")
161
+ @file.stub!(:puts)
162
+ File.stub!(:open).and_yield(@file)
163
+
164
+ @script = MkSpec.new
165
+ @script.stub!(:puts)
166
+
167
+ @response = mock("system command response")
168
+ @response.stub!(:=~).and_return(false)
169
+ @script.stub!(:`).and_return(@response)
170
+ end
171
+
172
+ it "checks if specs exist for the method if the spec file exists" do
173
+ @script.should_receive(:`).with(
174
+ /mspec\/bin\/mspec-run --dry-run -fs -e 'Object#inspect' spec\/core\/tcejbo\/inspect_spec.rb/)
175
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
176
+ end
177
+
178
+ it "escapes the Regexp when checking for method name in the spec file output" do
179
+ Regexp.should_receive(:escape).with("Array#[]=")
180
+ @script.write_spec("spec/core/yarra/element_set_spec.rb", "Array#[]=", true)
181
+ end
182
+
183
+ it "returns nil if the spec file exists and contains a spec for the method" do
184
+ @response.stub!(:=~).and_return(true)
185
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true).should == nil
186
+ end
187
+
188
+ it "does not print the spec file name if it exists and contains a spec for the method" do
189
+ @response.stub!(:=~).and_return(true)
190
+ @script.should_not_receive(:puts)
191
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
192
+ end
193
+
194
+ it "prints the spec file name if a template spec is written" do
195
+ @script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
196
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
197
+ end
198
+
199
+ it "writes a template spec to the file if the spec file does not exist" do
200
+ @file.should_receive(:puts)
201
+ @script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
202
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", false)
203
+ end
204
+
205
+ it "writes a template spec to the file if it exists but contains no spec for the method" do
206
+ @response.should_receive(:=~).and_return(false)
207
+ @file.should_receive(:puts)
208
+ @script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
209
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
210
+ end
211
+ end
212
+
213
+ describe MkSpec, "#create_file" do
214
+ before :each do
215
+ @script = MkSpec.new
216
+ @script.stub!(:write_requires)
217
+ @script.stub!(:write_spec)
218
+
219
+ File.stub!(:exist?).and_return(false)
220
+ end
221
+
222
+ it "generates a file name based on the directory, class/module, and method" do
223
+ File.should_receive(:join).with("spec/tcejbo", "inspect_spec.rb"
224
+ ).and_return("spec/tcejbo/inspect_spec.rb")
225
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
226
+ end
227
+
228
+ it "does not call #write_requires if the spec file already exists" do
229
+ File.should_receive(:exist?).and_return(true)
230
+ @script.should_not_receive(:write_requires)
231
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
232
+ end
233
+
234
+ it "calls #write_requires if the spec file does not exist" do
235
+ File.should_receive(:exist?).and_return(false)
236
+ @script.should_receive(:write_requires).with(
237
+ "spec/tcejbo", "spec/tcejbo/inspect_spec.rb")
238
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
239
+ end
240
+
241
+ it "calls #write_spec with the file, method name" do
242
+ @script.should_receive(:write_spec).with(
243
+ "spec/tcejbo/inspect_spec.rb", "Object#inspect", false)
244
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
245
+ end
246
+ end
247
+
248
+ describe MkSpec, "#run" do
249
+ before :each do
250
+ @options = OptionParser.new
251
+ OptionParser.stub!(:new).and_return(@options)
252
+
253
+ @map = NameMap.new
254
+ NameMap.stub!(:new).and_return(@map)
255
+
256
+ @script = MkSpec.new
257
+ @script.stub!(:create_directory).and_return("spec/mkspec")
258
+ @script.stub!(:create_file)
259
+ @script.config[:constants] = [MkSpec]
260
+ end
261
+
262
+ it "loads files in the requires list" do
263
+ @script.stub!(:require)
264
+ @script.should_receive(:require).with("alib")
265
+ @script.should_receive(:require).with("blib")
266
+ @script.config[:requires] = ["alib", "blib"]
267
+ @script.run
268
+ end
269
+
270
+ it "creates a map of constants to methods" do
271
+ @map.should_receive(:map).with({}, @script.config[:constants]).and_return({})
272
+ @script.run
273
+ end
274
+
275
+ it "creates a map of Object.constants if not constants are specified" do
276
+ @script.config[:constants] = []
277
+ Object.stub!(:constants).and_return(["Object"])
278
+ @map.should_receive(:filter).with(["Object"]).and_return(["Object"])
279
+ @map.should_receive(:map).with({}, ["Object"]).and_return({})
280
+ @script.run
281
+ end
282
+
283
+ it "calls #create_directory for each class/module in the map" do
284
+ @script.should_receive(:create_directory).with("MkSpec").twice
285
+ @script.run
286
+ end
287
+
288
+ it "calls #create_file for each method on each class/module in the map" do
289
+ @map.should_receive(:map).with({}, @script.config[:constants]).and_return({"MkSpec#" => "run"})
290
+ @script.should_receive(:create_file).with("spec/mkspec", "MkSpec", "run", "MkSpec#run")
291
+ @script.run
292
+ end
293
+ end
294
+
295
+ describe MkSpec, ".main" do
296
+ before :each do
297
+ @script = mock("MkSpec", :null_object => true)
298
+ MkSpec.stub!(:new).and_return(@script)
299
+ end
300
+
301
+ it "sets MSPEC_RUNNER = '1' in the environment" do
302
+ ENV["MSPEC_RUNNER"] = "0"
303
+ MkSpec.main
304
+ ENV["MSPEC_RUNNER"].should == "1"
305
+ end
306
+
307
+ it "creates an instance of MSpecScript" do
308
+ MkSpec.should_receive(:new).and_return(@script)
309
+ MkSpec.main
310
+ end
311
+
312
+ it "calls the #options method on the script" do
313
+ @script.should_receive(:options)
314
+ MkSpec.main
315
+ end
316
+
317
+ it "calls the #run method on the script" do
318
+ @script.should_receive(:run)
319
+ MkSpec.main
320
+ end
321
+ end
@@ -0,0 +1,139 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/runner/mspec'
3
+ require 'mspec/runner/filters/tag'
4
+ require 'mspec/commands/mspec-ci'
5
+
6
+ describe MSpecCI, "#options" do
7
+ before :each do
8
+ @options, @config = new_option
9
+ MSpecOptions.stub!(:new).and_return(@options)
10
+
11
+ @script = MSpecCI.new
12
+ @script.stub!(:config).and_return(@config)
13
+ end
14
+
15
+ it "enables the config option" do
16
+ @options.should_receive(:add_config)
17
+ @script.options
18
+ end
19
+
20
+ it "provides a custom action (block) to the config option" do
21
+ @script.should_receive(:load).with("cfg.mspec")
22
+ @script.options ["-B", "cfg.mspec"]
23
+ end
24
+
25
+ it "enables the name option" do
26
+ @options.should_receive(:add_name)
27
+ @script.options
28
+ end
29
+
30
+ it "enables the tags dir option" do
31
+ @options.should_receive(:add_tags_dir)
32
+ @script.options
33
+ end
34
+
35
+ it "enables the dry run option" do
36
+ @options.should_receive(:add_pretend)
37
+ @script.options
38
+ end
39
+
40
+ it "enables the interrupt single specs option" do
41
+ @options.should_receive(:add_interrupt)
42
+ @script.options
43
+ end
44
+
45
+ it "enables the formatter options" do
46
+ @options.should_receive(:add_formatters)
47
+ @script.options
48
+ end
49
+
50
+ it "enables the verbose option" do
51
+ @options.should_receive(:add_verbose)
52
+ @script.options
53
+ end
54
+
55
+ it "enables the action options" do
56
+ @options.should_receive(:add_actions)
57
+ @script.options
58
+ end
59
+
60
+ it "enables the action filter options" do
61
+ @options.should_receive(:add_action_filters)
62
+ @script.options
63
+ end
64
+
65
+ it "enables the version option" do
66
+ @options.should_receive(:add_version)
67
+ @script.options
68
+ end
69
+
70
+ it "enables the help option" do
71
+ @options.should_receive(:add_help)
72
+ @script.options
73
+ end
74
+ end
75
+
76
+ describe MSpecCI, "#run" do
77
+ before :each do
78
+ MSpec.stub!(:process)
79
+
80
+ @filter = mock("TagFilter")
81
+ TagFilter.stub!(:new).and_return(@filter)
82
+ @filter.stub!(:register)
83
+
84
+ stat = mock("stat")
85
+ stat.stub!(:file?).and_return(true)
86
+ stat.stub!(:directory?).and_return(false)
87
+ File.stub!(:expand_path)
88
+ File.stub!(:stat).and_return(stat)
89
+
90
+ @config = { :ci_files => ["one", "two"] }
91
+ @script = MSpecCI.new
92
+ @script.stub!(:exit)
93
+ @script.stub!(:config).and_return(@config)
94
+ @script.options
95
+ end
96
+
97
+ it "registers the tags directory path" do
98
+ @config[:tags_dir] = "tags_dir"
99
+ MSpec.should_receive(:register_tags_path).with("tags_dir")
100
+ @script.run
101
+ end
102
+
103
+ it "registers the files to process" do
104
+ MSpec.should_receive(:register_files).with(["one", "two"])
105
+ @script.run
106
+ end
107
+
108
+ it "registers a tag filter for 'fails'" do
109
+ filter = mock("fails filter")
110
+ TagFilter.should_receive(:new).with(:exclude, 'fails').and_return(filter)
111
+ filter.should_receive(:register)
112
+ @script.run
113
+ end
114
+
115
+ it "registers a tag filter for 'unstable'" do
116
+ filter = mock("unstable filter")
117
+ TagFilter.should_receive(:new).with(:exclude, 'unstable').and_return(filter)
118
+ filter.should_receive(:register)
119
+ @script.run
120
+ end
121
+
122
+ it "registers a tag filter for 'incomplete'" do
123
+ filter = mock("incomplete filter")
124
+ TagFilter.should_receive(:new).with(:exclude, 'incomplete').and_return(filter)
125
+ filter.should_receive(:register)
126
+ @script.run
127
+ end
128
+
129
+ it "processes the files" do
130
+ MSpec.should_receive(:process)
131
+ @script.run
132
+ end
133
+
134
+ it "exits with the exit code registered with MSpec" do
135
+ MSpec.stub!(:exit_code).and_return(7)
136
+ @script.should_receive(:exit).with(7)
137
+ @script.run
138
+ end
139
+ end