mspec 1.5.17 → 1.5.18

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 (174) hide show
  1. data/.gitignore +27 -0
  2. data/Gemfile +4 -0
  3. data/README +39 -159
  4. data/Rakefile +4 -44
  5. data/bin/mkspec.bat +1 -0
  6. data/bin/mspec-ci.bat +1 -0
  7. data/bin/mspec-run.bat +1 -0
  8. data/bin/mspec-tag.bat +1 -0
  9. data/bin/mspec.bat +1 -0
  10. data/lib/mspec/commands/mkspec.rb +2 -2
  11. data/lib/mspec/commands/mspec-run.rb +4 -0
  12. data/lib/mspec/commands/mspec.rb +18 -3
  13. data/lib/mspec/guards.rb +1 -0
  14. data/lib/mspec/guards/block_device.rb +22 -0
  15. data/lib/mspec/guards/guard.rb +14 -2
  16. data/lib/mspec/helpers.rb +5 -5
  17. data/lib/mspec/helpers/const_lookup.rb +6 -1
  18. data/lib/mspec/helpers/datetime.rb +28 -0
  19. data/lib/mspec/helpers/ducktype.rb +4 -4
  20. data/lib/mspec/helpers/environment.rb +19 -2
  21. data/lib/mspec/helpers/fs.rb +5 -1
  22. data/lib/mspec/helpers/io.rb +39 -1
  23. data/lib/mspec/helpers/numeric.rb +89 -0
  24. data/lib/mspec/helpers/pack.rb +3 -0
  25. data/lib/mspec/helpers/ruby_exe.rb +53 -15
  26. data/lib/mspec/helpers/singleton_class.rb +7 -0
  27. data/lib/mspec/helpers/stasy.rb +33 -0
  28. data/lib/mspec/helpers/tmp.rb +16 -3
  29. data/lib/mspec/matchers.rb +8 -0
  30. data/lib/mspec/matchers/be_computed_by.rb +37 -0
  31. data/lib/mspec/matchers/be_computed_by_function.rb +35 -0
  32. data/lib/mspec/matchers/be_nan.rb +20 -0
  33. data/lib/mspec/matchers/be_valid_dns_name.rb +25 -0
  34. data/lib/mspec/matchers/have_data.rb +6 -5
  35. data/lib/mspec/matchers/have_private_method.rb +24 -0
  36. data/lib/mspec/matchers/have_singleton_method.rb +24 -0
  37. data/lib/mspec/matchers/infinity.rb +28 -0
  38. data/lib/mspec/matchers/match_yaml.rb +5 -5
  39. data/lib/mspec/matchers/raise_error.rb +5 -3
  40. data/lib/mspec/matchers/signed_zero.rb +28 -0
  41. data/lib/mspec/mocks/mock.rb +15 -9
  42. data/lib/mspec/mocks/object.rb +4 -0
  43. data/lib/mspec/mocks/proxy.rb +26 -1
  44. data/lib/mspec/runner/actions.rb +0 -1
  45. data/lib/mspec/runner/context.rb +18 -16
  46. data/lib/mspec/runner/formatters.rb +2 -0
  47. data/lib/mspec/runner/formatters/dotted.rb +13 -1
  48. data/lib/mspec/runner/formatters/junit.rb +96 -0
  49. data/lib/mspec/runner/formatters/profile.rb +70 -0
  50. data/lib/mspec/runner/mspec.rb +11 -0
  51. data/lib/mspec/runner/shared.rb +1 -1
  52. data/lib/mspec/utils/options.rb +33 -9
  53. data/lib/mspec/utils/ruby_name.rb +1 -1
  54. data/lib/mspec/utils/script.rb +2 -1
  55. data/lib/mspec/version.rb +1 -1
  56. data/mspec.gemspec +40 -0
  57. data/spec/commands/mkspec_spec.rb +4 -3
  58. data/spec/commands/mspec_ci_spec.rb +1 -6
  59. data/spec/commands/mspec_run_spec.rb +1 -6
  60. data/spec/commands/mspec_spec.rb +14 -6
  61. data/spec/commands/mspec_tag_spec.rb +28 -27
  62. data/spec/expectations/expectations_spec.rb +1 -1
  63. data/spec/expectations/should_spec.rb +4 -4
  64. data/spec/guards/background_spec.rb +2 -2
  65. data/spec/guards/block_device_spec.rb +46 -0
  66. data/spec/guards/bug_spec.rb +2 -3
  67. data/spec/guards/compliance_spec.rb +2 -2
  68. data/spec/guards/conflict_spec.rb +2 -2
  69. data/spec/guards/endian_spec.rb +2 -2
  70. data/spec/guards/extensions_spec.rb +2 -2
  71. data/spec/guards/feature_spec.rb +2 -2
  72. data/spec/guards/guard_spec.rb +80 -22
  73. data/spec/guards/noncompliance_spec.rb +2 -2
  74. data/spec/guards/platform_spec.rb +2 -2
  75. data/spec/guards/quarantine_spec.rb +2 -2
  76. data/spec/guards/runner_spec.rb +2 -2
  77. data/spec/guards/specified_spec.rb +2 -2
  78. data/spec/guards/superuser_spec.rb +2 -2
  79. data/spec/guards/support_spec.rb +2 -2
  80. data/spec/guards/tty_spec.rb +2 -2
  81. data/spec/guards/user_spec.rb +2 -2
  82. data/spec/guards/version_spec.rb +2 -2
  83. data/spec/helpers/argv_spec.rb +3 -2
  84. data/spec/helpers/const_lookup_spec.rb +3 -2
  85. data/spec/helpers/datetime_spec.rb +44 -0
  86. data/spec/helpers/ducktype_spec.rb +3 -2
  87. data/spec/helpers/encode_spec.rb +3 -2
  88. data/spec/helpers/enumerator_class_spec.rb +5 -5
  89. data/spec/helpers/environment_spec.rb +15 -3
  90. data/spec/helpers/fixture_spec.rb +3 -2
  91. data/spec/helpers/flunk_spec.rb +4 -3
  92. data/spec/helpers/fs_spec.rb +35 -18
  93. data/spec/helpers/hash_spec.rb +3 -2
  94. data/spec/helpers/io_spec.rb +75 -6
  95. data/spec/helpers/language_version_spec.rb +3 -2
  96. data/spec/helpers/mock_to_path_spec.rb +3 -2
  97. data/spec/helpers/numeric_spec.rb +25 -0
  98. data/spec/helpers/ruby_exe_spec.rb +115 -29
  99. data/spec/helpers/scratch_spec.rb +3 -1
  100. data/spec/helpers/stasy_spec.rb +59 -0
  101. data/spec/helpers/tmp_spec.rb +21 -4
  102. data/spec/matchers/base_spec.rb +2 -2
  103. data/spec/matchers/be_an_instance_of_spec.rb +2 -2
  104. data/spec/matchers/be_ancestor_of_spec.rb +2 -2
  105. data/spec/matchers/be_close_spec.rb +2 -2
  106. data/spec/matchers/be_computed_by_function_spec.rb +36 -0
  107. data/spec/matchers/be_computed_by_spec.rb +42 -0
  108. data/spec/matchers/be_empty_spec.rb +2 -2
  109. data/spec/matchers/be_false_spec.rb +3 -3
  110. data/spec/matchers/be_kind_of_spec.rb +2 -2
  111. data/spec/matchers/be_nan_spec.rb +28 -0
  112. data/spec/matchers/be_nil_spec.rb +3 -3
  113. data/spec/matchers/be_true_spec.rb +3 -3
  114. data/spec/matchers/be_valid_dns_name_spec.rb +50 -0
  115. data/spec/matchers/complain_spec.rb +2 -2
  116. data/spec/matchers/eql_spec.rb +2 -2
  117. data/spec/matchers/equal_element_spec.rb +2 -2
  118. data/spec/matchers/equal_spec.rb +2 -2
  119. data/spec/matchers/equal_utf16_spec.rb +2 -2
  120. data/spec/matchers/have_class_variable_spec.rb +3 -3
  121. data/spec/matchers/have_constant_spec.rb +2 -2
  122. data/spec/matchers/have_data_spec.rb +8 -5
  123. data/spec/matchers/have_instance_method_spec.rb +2 -2
  124. data/spec/matchers/have_instance_variable_spec.rb +3 -3
  125. data/spec/matchers/have_method_spec.rb +2 -2
  126. data/spec/matchers/have_private_instance_method_spec.rb +3 -3
  127. data/spec/matchers/have_private_method_spec.rb +44 -0
  128. data/spec/matchers/have_protected_instance_method_spec.rb +2 -2
  129. data/spec/matchers/have_public_instance_method_spec.rb +2 -2
  130. data/spec/matchers/have_singleton_method_spec.rb +45 -0
  131. data/spec/matchers/include_spec.rb +2 -2
  132. data/spec/matchers/infinity_spec.rb +34 -0
  133. data/spec/matchers/match_yaml_spec.rb +3 -3
  134. data/spec/matchers/output_spec.rb +2 -2
  135. data/spec/matchers/output_to_fd_spec.rb +2 -2
  136. data/spec/matchers/raise_error_spec.rb +24 -3
  137. data/spec/matchers/respond_to_spec.rb +2 -2
  138. data/spec/matchers/signed_zero_spec.rb +32 -0
  139. data/spec/matchers/stringsymboladapter_spec.rb +2 -2
  140. data/spec/mocks/mock_spec.rb +12 -12
  141. data/spec/mocks/proxy_spec.rb +1 -1
  142. data/spec/runner/actions/gdb_spec.rb +1 -1
  143. data/spec/runner/actions/tag_spec.rb +1 -1
  144. data/spec/runner/actions/taglist_spec.rb +1 -1
  145. data/spec/runner/context_spec.rb +27 -27
  146. data/spec/runner/example_spec.rb +1 -1
  147. data/spec/runner/exception_spec.rb +1 -1
  148. data/spec/runner/filters/tag_spec.rb +2 -2
  149. data/spec/runner/formatters/describe_spec.rb +1 -1
  150. data/spec/runner/formatters/dotted_spec.rb +2 -2
  151. data/spec/runner/formatters/html_spec.rb +2 -2
  152. data/spec/runner/formatters/junit_spec.rb +147 -0
  153. data/spec/runner/formatters/unit_spec.rb +2 -2
  154. data/spec/runner/formatters/yaml_spec.rb +3 -3
  155. data/spec/runner/mspec_spec.rb +22 -21
  156. data/spec/runner/shared_spec.rb +9 -1
  157. data/spec/runner/tag_spec.rb +1 -1
  158. data/spec/spec_helper.rb +1 -7
  159. data/spec/utils/name_map_spec.rb +1 -2
  160. data/spec/utils/options_spec.rb +58 -27
  161. data/spec/utils/script_spec.rb +5 -13
  162. data/spec/utils/version_spec.rb +1 -1
  163. metadata +254 -64
  164. data/lib/mspec/helpers/bignum.rb +0 -5
  165. data/lib/mspec/helpers/fmode.rb +0 -15
  166. data/lib/mspec/helpers/infinity.rb +0 -5
  167. data/lib/mspec/helpers/metaclass.rb +0 -7
  168. data/lib/mspec/helpers/nan.rb +0 -5
  169. data/lib/mspec/runner/actions/debug.rb +0 -17
  170. data/spec/helpers/bignum_spec.rb +0 -11
  171. data/spec/helpers/fmode_spec.rb +0 -14
  172. data/spec/helpers/infinity_spec.rb +0 -8
  173. data/spec/helpers/nan_spec.rb +0 -8
  174. data/spec/runner/actions/debug_spec.rb +0 -62
@@ -86,7 +86,7 @@ class MSpecScript
86
86
  # first two numbers in RUBY_VERSION. For example, on MRI 1.8.6,
87
87
  # the file name would be 'ruby.1.8.mspec'.
88
88
  def load_default
89
- return if load 'default.mspec'
89
+ load 'default.mspec'
90
90
 
91
91
  if Object.const_defined?(:RUBY_ENGINE)
92
92
  engine = RUBY_ENGINE
@@ -141,6 +141,7 @@ class MSpecScript
141
141
  def signals
142
142
  if config[:abort]
143
143
  Signal.trap "INT" do
144
+ MSpec.actions :abort
144
145
  puts "\nProcess aborted!"
145
146
  exit! 1
146
147
  end
data/lib/mspec/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'mspec/utils/version'
2
2
 
3
3
  module MSpec
4
- VERSION = SpecVersion.new "1.5.17"
4
+ VERSION = SpecVersion.new "1.5.18"
5
5
  end
data/mspec.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.unshift File.expand_path('../lib', __FILE__)
3
+ require 'mspec/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "mspec"
7
+ gem.version = MSpec::VERSION.to_s
8
+ gem.authors = ["Brian Shirai"]
9
+ gem.email = ["bshirai@engineyard.com"]
10
+ gem.homepage = "http://rubyspec.org"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) unless File.extname(f) == ".bat" }.compact
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.require_paths = ["lib"]
16
+ gem.description = <<-EOD
17
+ MSpec is a specialized framework for RubySpec.
18
+ EOD
19
+ gem.summary = <<-EOS
20
+ MSpec is a specialized framework that is syntax-compatible
21
+ with RSpec for basic things like describe, it blocks and
22
+ before, after actions.
23
+
24
+ MSpec contains additional features that assist in writing
25
+ the RubySpecs used by multiple Ruby implementations. Also,
26
+ MSpec attempts to use the simplest Ruby language features
27
+ so that beginning Ruby implementations can run it.
28
+ EOS
29
+ gem.has_rdoc = true
30
+ gem.extra_rdoc_files = %w[ README LICENSE ]
31
+ gem.rubygems_version = %q{1.3.5}
32
+ gem.rubyforge_project = 'http://rubyforge.org/projects/mspec'
33
+
34
+ gem.rdoc_options << '--title' << 'MSpec Gem' <<
35
+ '--main' << 'README' <<
36
+ '--line-numbers'
37
+
38
+ gem.add_development_dependency "rake", "~> 10.0"
39
+ gem.add_development_dependency "rspec", "~> 2.8"
40
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'mspec/commands/mkspec'
3
3
 
4
4
 
@@ -194,8 +194,9 @@ describe MkSpec, "#write_spec" do
194
194
  end
195
195
 
196
196
  it "checks if specs exist for the method if the spec file exists" do
197
+ name = Regexp.escape(@script.ruby)
197
198
  @script.should_receive(:`).with(
198
- %r"#{@script.ruby} #{MSPEC_HOME}/bin/mspec-run --dry-run -fs -e 'Object#inspect' spec/core/tcejbo/inspect_spec.rb")
199
+ %r"#{name} #{MSPEC_HOME}/bin/mspec-run --dry-run -fs -e 'Object#inspect' spec/core/tcejbo/inspect_spec.rb")
199
200
  @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
200
201
  end
201
202
 
@@ -335,7 +336,7 @@ end
335
336
 
336
337
  describe MkSpec, ".main" do
337
338
  before :each do
338
- @script = mock("MkSpec", :null_object => true)
339
+ @script = mock("MkSpec").as_null_object
339
340
  MkSpec.stub!(:new).and_return(@script)
340
341
  end
341
342
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'mspec/runner/mspec'
3
3
  require 'mspec/runner/filters/tag'
4
4
  require 'mspec/commands/mspec-ci'
@@ -88,11 +88,6 @@ describe MSpecCI, "#options" do
88
88
  @script.options
89
89
  end
90
90
 
91
- it "enables the debug option" do
92
- @options.should_receive(:debug)
93
- @script.options @argv
94
- end
95
-
96
91
  it "calls #custom_options" do
97
92
  @script.should_receive(:custom_options).with(@options)
98
93
  @script.options
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'mspec/runner/mspec'
3
3
  require 'mspec/commands/mspec-run'
4
4
 
@@ -118,11 +118,6 @@ describe MSpecRun, "#options" do
118
118
  @script.options @argv
119
119
  end
120
120
 
121
- it "enables the debug option" do
122
- @options.should_receive(:debug)
123
- @script.options @argv
124
- end
125
-
126
121
  it "exits if there are no files to process" do
127
122
  @options.should_receive(:parse).and_return([])
128
123
  @script.should_receive(:exit)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'yaml'
3
3
  require 'mspec/commands/mspec'
4
4
 
@@ -108,9 +108,9 @@ describe MSpecMain, "#report" do
108
108
  before :each do
109
109
  @stdout, $stdout = $stdout, IOStub.new
110
110
 
111
- @timer = mock("timer", :null_object => true)
111
+ @timer = mock("timer").as_null_object
112
112
  @timer.stub!(:format).and_return("Finished in 42 seconds")
113
- @file = mock("file", :null_object => true)
113
+ @file = mock("file").as_null_object
114
114
 
115
115
  File.stub!(:delete)
116
116
  YAML.stub!(:load)
@@ -244,6 +244,14 @@ describe MSpecMain, "#run" do
244
244
  @script.run
245
245
  end
246
246
 
247
+ it "adds config[:launch] to the exec options" do
248
+ @script.should_receive(:exec).with("ruby",
249
+ "-Xlaunch.option", "-v", %r"#{MSPEC_HOME}/bin/mspec-run$")
250
+ @config[:launch] << "-Xlaunch.option"
251
+ @script.options []
252
+ @script.run
253
+ end
254
+
247
255
  it "calls #multi_exec if the command is 'ci' and the multi option is passed" do
248
256
  @script.should_receive(:multi_exec).and_return do |arg|
249
257
  arg.length.should == 3
@@ -293,11 +301,11 @@ describe "The -A, --valgrind option" do
293
301
  @script.options
294
302
  end
295
303
 
296
- it "sets flags to --valgrind" do
304
+ it "sets :use_valgrind config option to true" do
297
305
  ["-A", "--valgrind"].each do |opt|
298
- @config[:flags] = []
306
+ @config[:use_valgrind] = false
299
307
  @script.options [opt]
300
- @config[:flags].should include("--valgrind")
308
+ @config[:use_valgrind].should be_true
301
309
  end
302
310
  end
303
311
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'mspec/runner/mspec'
3
3
  require 'mspec/commands/mspec-tag'
4
4
  require 'mspec/runner/actions/tag'
@@ -98,11 +98,6 @@ describe MSpecTag, "#options" do
98
98
  @script.options @argv
99
99
  end
100
100
 
101
- it "enables the debug option" do
102
- @options.should_receive(:debug)
103
- @script.options @argv
104
- end
105
-
106
101
  it "calls #custom_options" do
107
102
  @script.should_receive(:custom_options).with(@options)
108
103
  @script.options @argv
@@ -264,7 +259,7 @@ describe MSpecTag, "#run" do
264
259
  before :each do
265
260
  MSpec.stub!(:process)
266
261
 
267
- options = mock("MSpecOptions", :null_object => true)
262
+ options = mock("MSpecOptions").as_null_object
268
263
  options.stub!(:parse).and_return(["one", "two"])
269
264
  MSpecOptions.stub!(:new).and_return(options)
270
265
 
@@ -318,36 +313,42 @@ describe MSpecTag, "#register" do
318
313
  @tl.stub!(:register)
319
314
  end
320
315
 
321
- it "creates a TagAction if config[:tagger] is :add" do
322
- TagAction.should_receive(:new).with(:add, :fail, "fake", nil, [], []).and_return(@t)
323
- @script.register
316
+ it "raises an ArgumentError if no recognized action is given" do
317
+ @config[:tagger] = :totally_whack
318
+ lambda { @script.register }.should raise_error(ArgumentError)
324
319
  end
325
320
 
326
- it "creates a TagAction if config[:tagger] is :del" do
327
- @config[:tagger] = :del
328
- @config[:outcome] = :pass
329
- TagAction.should_receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
330
- @script.register
331
- end
321
+ describe "when config[:tagger] is the default (:add)" do
322
+ before :each do
323
+ @config[:formatter] = false
324
+ end
332
325
 
333
- it "calls #register on the TagAction instance" do
334
- TagAction.should_receive(:new).and_return(@t)
335
- @t.should_receive(:register)
336
- @script.register
337
- end
326
+ it "creates a TagAction" do
327
+ TagAction.should_receive(:new).and_return(@t)
328
+ @script.register
329
+ end
338
330
 
339
- it "raises an ArgumentError if no recognized action is given" do
340
- @config[:tagger] = :totally_whack
341
- lambda { @script.register }.should raise_error(ArgumentError)
331
+ it "creates a TagAction if config[:tagger] is :del" do
332
+ @config[:tagger] = :del
333
+ @config[:outcome] = :pass
334
+ TagAction.should_receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
335
+ @script.register
336
+ end
337
+
338
+ it "calls #register on the TagAction instance" do
339
+ TagAction.should_receive(:new).and_return(@t)
340
+ @t.should_receive(:register)
341
+ @script.register
342
+ end
342
343
  end
343
344
 
344
345
  describe "when config[:tagger] is :list" do
345
346
  before :each do
347
+ TagListAction.should_receive(:new).with(@config[:ltags]).and_return(@tl)
346
348
  @config[:tagger] = :list
347
349
  end
348
350
 
349
351
  it "creates a TagListAction" do
350
- TagListAction.should_receive(:new).with(@config[:ltags]).and_return(@tl)
351
352
  @tl.should_receive(:register)
352
353
  @script.register
353
354
  end
@@ -365,11 +366,11 @@ describe MSpecTag, "#register" do
365
366
 
366
367
  describe "when config[:tagger] is :list_all" do
367
368
  before :each do
369
+ TagListAction.should_receive(:new).with(nil).and_return(@tl)
368
370
  @config[:tagger] = :list_all
369
371
  end
370
372
 
371
373
  it "creates a TagListAction" do
372
- TagListAction.should_receive(:new).with(nil).and_return(@tl)
373
374
  @tl.should_receive(:register)
374
375
  @script.register
375
376
  end
@@ -387,12 +388,12 @@ describe MSpecTag, "#register" do
387
388
 
388
389
  describe "when config[:tagger] is :purge" do
389
390
  before :each do
391
+ TagPurgeAction.should_receive(:new).and_return(@tl)
390
392
  MSpec.stub!(:register_mode)
391
393
  @config[:tagger] = :purge
392
394
  end
393
395
 
394
396
  it "creates a TagPurgeAction" do
395
- TagPurgeAction.should_receive(:new).and_return(@tl)
396
397
  @tl.should_receive(:register)
397
398
  @script.register
398
399
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'mspec/expectations/expectations'
3
3
 
4
4
  describe SpecExpectationNotMetError do
@@ -1,10 +1,10 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'rbconfig'
3
3
 
4
- describe MSpec do
4
+ describe "MSpec" do
5
5
  before :all do
6
- path = Config::CONFIG['bindir']
7
- exe = Config::CONFIG['ruby_install_name']
6
+ path = RbConfig::CONFIG['bindir']
7
+ exe = RbConfig::CONFIG['ruby_install_name']
8
8
  file = File.dirname(__FILE__) + '/should.rb'
9
9
  @out = `#{path}/#{exe} #{file}`
10
10
  end
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/guards/background'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
3
3
 
4
4
  describe Object, "#process_is_foreground" do
5
5
  before :each do
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
3
+
4
+ describe Object, "#with_block_device" do
5
+ before :each do
6
+ ScratchPad.clear
7
+
8
+ @guard = BlockDeviceGuard.new
9
+ BlockDeviceGuard.stub!(:new).and_return(@guard)
10
+ end
11
+
12
+ platform_is_not :freebsd, :windows do
13
+ it "yields if block device is available" do
14
+ @guard.should_receive(:`).and_return("block devices")
15
+ with_block_device { ScratchPad.record :yield }
16
+ ScratchPad.recorded.should == :yield
17
+ end
18
+
19
+ it "does not yield if block device is not available" do
20
+ @guard.should_receive(:`).and_return(nil)
21
+ with_block_device { ScratchPad.record :yield }
22
+ ScratchPad.recorded.should_not == :yield
23
+ end
24
+ end
25
+
26
+ platform_is :freebsd, :windows do
27
+ it "does not yield, since platform does not support block devices" do
28
+ @guard.should_not_receive(:`)
29
+ with_block_device { ScratchPad.record :yield }
30
+ ScratchPad.recorded.should_not == :yield
31
+ end
32
+ end
33
+
34
+ it "sets the name of the guard to :with_block_device" do
35
+ with_block_device { }
36
+ @guard.name.should == :with_block_device
37
+ end
38
+
39
+ it "calls #unregister even when an exception is raised in the guard block" do
40
+ @guard.should_receive(:match?).and_return(true)
41
+ @guard.should_receive(:unregister)
42
+ lambda do
43
+ with_block_device { raise Exception }
44
+ end.should raise_error(Exception)
45
+ end
46
+ end
@@ -1,6 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/utils/ruby_name'
3
- require 'mspec/guards/bug'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
4
3
 
5
4
  describe BugGuard, "#match? when #implementation? is 'ruby'" do
6
5
  before :all do
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/guards/compliance'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
3
3
 
4
4
  describe Object, "#compliant_on" do
5
5
  before :all do
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/guards/conflict'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
3
3
 
4
4
  describe Object, "#conflicts_with" do
5
5
  before :each do
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/guards/endian'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
3
3
 
4
4
  describe Object, "#big_endian" do
5
5
  before :each do
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/guards/extensions'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
3
3
 
4
4
  describe Object, "#extended_on" do
5
5
  before :all do
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/guards/feature'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
3
3
 
4
4
  describe FeatureGuard, ".enabled?" do
5
5
  it "returns true if the feature is enabled" do
@@ -1,10 +1,24 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/utils/ruby_name'
3
- require 'mspec/guards/guard'
1
+ require 'spec_helper'
2
+ require 'mspec/guards'
4
3
  require 'rbconfig'
5
4
 
5
+ describe SpecGuard, "#ruby_version_override=" do
6
+ after :each do
7
+ SpecGuard.ruby_version_override = nil
8
+ end
9
+
10
+ it "returns nil by default" do
11
+ SpecGuard.ruby_version_override.should be_nil
12
+ end
13
+
14
+ it "returns the value set by #ruby_version_override=" do
15
+ SpecGuard.ruby_version_override = "8.3.2"
16
+ SpecGuard.ruby_version_override.should == "8.3.2"
17
+ end
18
+ end
19
+
6
20
  describe SpecGuard, ".ruby_version" do
7
- before :all do
21
+ before :each do
8
22
  @ruby_version = Object.const_get :RUBY_VERSION
9
23
  @ruby_patchlevel = Object.const_get :RUBY_PATCHLEVEL
10
24
 
@@ -12,7 +26,7 @@ describe SpecGuard, ".ruby_version" do
12
26
  Object.const_set :RUBY_PATCHLEVEL, 71
13
27
  end
14
28
 
15
- after :all do
29
+ after :each do
16
30
  Object.const_set :RUBY_VERSION, @ruby_version
17
31
  Object.const_set :RUBY_PATCHLEVEL, @ruby_patchlevel
18
32
  end
@@ -45,6 +59,45 @@ describe SpecGuard, ".ruby_version" do
45
59
  it "returns major for :major" do
46
60
  SpecGuard.ruby_version(:major).should == "8"
47
61
  end
62
+
63
+ describe "with ruby_version_override set" do
64
+ before :each do
65
+ SpecGuard.ruby_version_override = "8.3.2"
66
+ end
67
+
68
+ after :each do
69
+ SpecGuard.ruby_version_override = nil
70
+ end
71
+
72
+ it "returns the version and patchlevel for :full" do
73
+ SpecGuard.ruby_version(:full).should == "8.3.2.71"
74
+ end
75
+
76
+ it "returns 0 for negative RUBY_PATCHLEVEL values" do
77
+ Object.const_set :RUBY_PATCHLEVEL, -1
78
+ SpecGuard.ruby_version(:full).should == "8.3.2.0"
79
+ end
80
+
81
+ it "returns major.minor.tiny for :tiny" do
82
+ SpecGuard.ruby_version(:tiny).should == "8.3.2"
83
+ end
84
+
85
+ it "returns major.minor.tiny for :teeny" do
86
+ SpecGuard.ruby_version(:tiny).should == "8.3.2"
87
+ end
88
+
89
+ it "returns major.minor for :minor" do
90
+ SpecGuard.ruby_version(:minor).should == "8.3"
91
+ end
92
+
93
+ it "defaults to :minor" do
94
+ SpecGuard.ruby_version.should == "8.3"
95
+ end
96
+
97
+ it "returns major for :major" do
98
+ SpecGuard.ruby_version(:major).should == "8"
99
+ end
100
+ end
48
101
  end
49
102
 
50
103
  describe SpecGuard, "#yield?" do
@@ -158,6 +211,11 @@ describe SpecGuard, "#implementation?" do
158
211
  @guard.implementation?(:maglev).should == true
159
212
  end
160
213
 
214
+ it "returns true if passed :topaz and RUBY_NAME == 'topaz'" do
215
+ Object.const_set :RUBY_NAME, 'topaz'
216
+ @guard.implementation?(:topaz).should == true
217
+ end
218
+
161
219
  it "returns true if passed :ruby and RUBY_NAME matches /^ruby/" do
162
220
  Object.const_set :RUBY_NAME, 'ruby'
163
221
  @guard.implementation?(:ruby).should == true
@@ -237,12 +295,12 @@ describe SpecGuard, "#platform?" do
237
295
  @guard.platform?(:windows).should == true
238
296
  end
239
297
 
240
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mswin'" do
298
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
241
299
  Object.const_set :RUBY_PLATFORM, 'i386-mswin32'
242
300
  @guard.platform?(:linux).should == false
243
301
  end
244
302
 
245
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mingw'" do
303
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
246
304
  Object.const_set :RUBY_PLATFORM, 'i386-mingw32'
247
305
  @guard.platform?(:linux).should == false
248
306
  end
@@ -273,12 +331,12 @@ describe SpecGuard, "#platform? on JRuby" do
273
331
  end
274
332
 
275
333
  it "returns true when arg is :windows and RUBY_PLATFORM contains 'java' and os?(:windows) is true" do
276
- Config::CONFIG.stub!(:[]).and_return('mswin32')
334
+ RbConfig::CONFIG.stub!(:[]).and_return('mswin32')
277
335
  @guard.platform?(:windows).should == true
278
336
  end
279
337
 
280
338
  it "returns true when RUBY_PLATFORM contains 'java' and os?(argument) is true" do
281
- Config::CONFIG.stub!(:[]).and_return('amiga')
339
+ RbConfig::CONFIG.stub!(:[]).and_return('amiga')
282
340
  @guard.platform?(:amiga).should == true
283
341
  end
284
342
  end
@@ -300,42 +358,42 @@ end
300
358
  describe SpecGuard, "#os?" do
301
359
  before :each do
302
360
  @guard = SpecGuard.new
303
- Config::CONFIG.stub!(:[]).and_return('unreal')
361
+ RbConfig::CONFIG.stub!(:[]).and_return('unreal')
304
362
  end
305
363
 
306
- it "returns true if argument matches Config::CONFIG['host_os']" do
364
+ it "returns true if argument matches RbConfig::CONFIG['host_os']" do
307
365
  @guard.os?(:unreal).should == true
308
366
  end
309
367
 
310
- it "returns true if any argument matches Config::CONFIG['host_os']" do
368
+ it "returns true if any argument matches RbConfig::CONFIG['host_os']" do
311
369
  @guard.os?(:bsd, :unreal, :amiga).should == true
312
370
  end
313
371
 
314
- it "returns false if no argument matches Config::CONFIG['host_os']" do
372
+ it "returns false if no argument matches RbConfig::CONFIG['host_os']" do
315
373
  @guard.os?(:bsd, :netbsd, :amiga, :msdos).should == false
316
374
  end
317
375
 
318
- it "returns false if argument does not match Config::CONFIG['host_os']" do
376
+ it "returns false if argument does not match RbConfig::CONFIG['host_os']" do
319
377
  @guard.os?(:amiga).should == false
320
378
  end
321
379
 
322
- it "returns true when arg is :windows and Config::CONFIG['host_os'] contains 'mswin'" do
323
- Config::CONFIG.stub!(:[]).and_return('i386-mswin32')
380
+ it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
381
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mswin32')
324
382
  @guard.os?(:windows).should == true
325
383
  end
326
384
 
327
- it "returns true when arg is :windows and Config::CONFIG['host_os'] contains 'mingw'" do
328
- Config::CONFIG.stub!(:[]).and_return('i386-mingw32')
385
+ it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
386
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32')
329
387
  @guard.os?(:windows).should == true
330
388
  end
331
389
 
332
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mswin'" do
333
- Config::CONFIG.stub!(:[]).and_return('i386-mingw32')
390
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
391
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32')
334
392
  @guard.os?(:linux).should == false
335
393
  end
336
394
 
337
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mingw'" do
338
- Config::CONFIG.stub!(:[]).and_return('i386-mingw32')
395
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
396
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32')
339
397
  @guard.os?(:linux).should == false
340
398
  end
341
399
  end