mspec 1.5.17 → 1.5.18

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/mspec/guards.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'mspec/utils/ruby_name'
2
2
  require 'mspec/guards/background'
3
+ require 'mspec/guards/block_device'
3
4
  require 'mspec/guards/bug'
4
5
  require 'mspec/guards/compliance'
5
6
  require 'mspec/guards/conflict'
@@ -0,0 +1,22 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ class BlockDeviceGuard < SpecGuard
4
+ def match?
5
+ platform_is_not :freebsd, :windows do
6
+ block = `find /dev /devices -type b 2> /dev/null`
7
+ return !(block.nil? || block.empty?)
8
+ end
9
+
10
+ false
11
+ end
12
+ end
13
+
14
+ class Object
15
+ def with_block_device
16
+ g = BlockDeviceGuard.new
17
+ g.name = :with_block_device
18
+ yield if g.yield?
19
+ ensure
20
+ g.unregister
21
+ end
22
+ end
@@ -32,6 +32,16 @@ class SpecGuard
32
32
  @guards = []
33
33
  end
34
34
 
35
+ @@ruby_version_override = nil
36
+
37
+ def self.ruby_version_override=(version)
38
+ @@ruby_version_override = version
39
+ end
40
+
41
+ def self.ruby_version_override
42
+ @@ruby_version_override
43
+ end
44
+
35
45
  # Returns a partial Ruby version string based on +which+. For example,
36
46
  # if RUBY_VERSION = 8.2.3 and RUBY_PATCHLEVEL = 71:
37
47
  #
@@ -54,7 +64,7 @@ class SpecGuard
54
64
 
55
65
  patch = RUBY_PATCHLEVEL.to_i
56
66
  patch = 0 if patch < 0
57
- version = "#{RUBY_VERSION}.#{patch}"
67
+ version = "#{ruby_version_override || RUBY_VERSION}.#{patch}"
58
68
  version.split('.')[0,n].join('.')
59
69
  end
60
70
 
@@ -123,6 +133,8 @@ class SpecGuard
123
133
  RUBY_NAME =~ /^macruby/
124
134
  when :maglev
125
135
  RUBY_NAME =~ /^maglev/
136
+ when :topaz
137
+ RUBY_NAME =~ /^topaz/
126
138
  else
127
139
  false
128
140
  end
@@ -153,7 +165,7 @@ class SpecGuard
153
165
 
154
166
  def os?(*oses)
155
167
  oses.any? do |os|
156
- host_os = Config::CONFIG['host_os'] || RUBY_PLATFORM
168
+ host_os = RbConfig::CONFIG['host_os'] || RUBY_PLATFORM
157
169
  host_os.downcase!
158
170
  host_os.match(os.to_s) || windows?(os, host_os)
159
171
  end
data/lib/mspec/helpers.rb CHANGED
@@ -1,21 +1,21 @@
1
1
  require 'mspec/helpers/argv'
2
- require 'mspec/helpers/bignum'
3
2
  require 'mspec/helpers/const_lookup'
3
+ require 'mspec/helpers/datetime'
4
4
  require 'mspec/helpers/ducktype'
5
5
  require 'mspec/helpers/encode'
6
6
  require 'mspec/helpers/enumerator_class'
7
7
  require 'mspec/helpers/environment'
8
8
  require 'mspec/helpers/fixture'
9
9
  require 'mspec/helpers/flunk'
10
- require 'mspec/helpers/fmode'
11
10
  require 'mspec/helpers/fs'
12
11
  require 'mspec/helpers/hash'
13
- require 'mspec/helpers/infinity'
14
12
  require 'mspec/helpers/io'
15
13
  require 'mspec/helpers/language_version'
16
- require 'mspec/helpers/metaclass'
17
14
  require 'mspec/helpers/mock_to_path'
18
- require 'mspec/helpers/nan'
15
+ require 'mspec/helpers/numeric'
16
+ require 'mspec/helpers/pack'
19
17
  require 'mspec/helpers/ruby_exe'
20
18
  require 'mspec/helpers/scratch'
19
+ require 'mspec/helpers/stasy'
20
+ require 'mspec/helpers/singleton_class'
21
21
  require 'mspec/helpers/tmp'
@@ -1,9 +1,14 @@
1
+ require 'mspec/utils/version'
2
+
1
3
  module Kernel
2
4
  def const_lookup(c)
5
+ extra_arg = SpecVersion.new(RUBY_VERSION) >= "1.9"
6
+
3
7
  names = c.split '::'
4
8
  names.shift if names.first.empty?
9
+
5
10
  names.inject(Object) do |m, n|
6
- defined = RUBY_VERSION =~ /^1.9/ ? m.const_defined?(n, false) : m.const_defined?(n)
11
+ defined = extra_arg ? m.const_defined?(n, false) : m.const_defined?(n)
7
12
  defined ? m.const_get(n) : m.const_missing(n)
8
13
  end
9
14
  end
@@ -0,0 +1,28 @@
1
+ class Object
2
+ # The new_datetime helper makes writing DateTime specs more simple by
3
+ # providing default constructor values and accepting a Hash of only the
4
+ # constructor values needed for the particular spec. For example:
5
+ #
6
+ # new_datetime :hour => 1, :minute => 20
7
+ #
8
+ # Possible keys are:
9
+ # :year, :month, :day, :hour, :minute, :second, :offset and :sg.
10
+
11
+ def new_datetime(opts={})
12
+ require 'date'
13
+
14
+ value = {
15
+ :year => -4712,
16
+ :month => 1,
17
+ :day => 1,
18
+ :hour => 0,
19
+ :minute => 0,
20
+ :second => 0,
21
+ :offset => 0,
22
+ :sg => Date::ITALY
23
+ }.merge opts
24
+
25
+ DateTime.new value[:year], value[:month], value[:day], value[:hour],
26
+ value[:minute], value[:second], value[:offset], value[:sg]
27
+ end
28
+ end
@@ -1,6 +1,6 @@
1
1
  class Object
2
2
  def responds_to(sym)
3
- metaclass.class_eval <<-END
3
+ singleton_class.class_eval <<-END
4
4
  def respond_to?(sym, include_private=false)
5
5
  sym.to_sym == #{sym.to_sym.inspect} ? true : super
6
6
  end
@@ -8,7 +8,7 @@ class Object
8
8
  end
9
9
 
10
10
  def does_not_respond_to(sym)
11
- metaclass.class_eval <<-END
11
+ singleton_class.class_eval <<-END
12
12
  def respond_to?(sym, include_private=false)
13
13
  sym.to_sym == #{sym.to_sym.inspect} ? false : super
14
14
  end
@@ -16,7 +16,7 @@ class Object
16
16
  end
17
17
 
18
18
  def undefine(sym)
19
- metaclass.class_eval <<-END
19
+ singleton_class.class_eval <<-END
20
20
  undef_method #{sym.to_sym.inspect}
21
21
  END
22
22
  end
@@ -24,7 +24,7 @@ class Object
24
24
  def fake!(sym, value=nil)
25
25
  responds_to sym
26
26
 
27
- metaclass.class_eval <<-END
27
+ singleton_class.class_eval <<-END
28
28
  def method_missing(sym, *args)
29
29
  return #{value.inspect} if sym.to_sym == #{sym.to_sym.inspect}
30
30
  end
@@ -13,7 +13,7 @@ class Object
13
13
 
14
14
  def windows_env_echo(var)
15
15
  `cmd.exe /C ECHO %#{var}%`.strip
16
- end
16
+ end
17
17
 
18
18
  def username
19
19
  user = ""
@@ -28,5 +28,22 @@ class Object
28
28
  def home_directory
29
29
  return ENV['HOME'] unless PlatformGuard.windows?
30
30
  windows_env_echo('HOMEDRIVE') + windows_env_echo('HOMEPATH')
31
- end
31
+ end
32
+
33
+ def dev_null
34
+ if PlatformGuard.windows?
35
+ "NUL"
36
+ else
37
+ "/dev/null"
38
+ end
39
+ end
40
+
41
+ def hostname
42
+ commands = ['hostname', 'uname -n']
43
+ commands.each do |command|
44
+ name = `#{command}`
45
+ return name.strip if $?.success?
46
+ end
47
+ raise Exception, "hostname: unable to find a working command"
48
+ end
32
49
  end
@@ -37,7 +37,11 @@ class Object
37
37
  raise ArgumentError, "#{path} is not prefixed by #{prefix}"
38
38
  end
39
39
 
40
- if File.directory? path
40
+ # File.symlink? needs to be checked first as
41
+ # File.exists? returns false for dangling symlinks
42
+ if File.symlink? path
43
+ File.unlink path
44
+ elsif File.directory? path
41
45
  Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ }
42
46
  Dir.rmdir path
43
47
  elsif File.exists? path
@@ -1,3 +1,5 @@
1
+ require 'mspec/guards/feature'
2
+
1
3
  class IOStub < String
2
4
  def write(*str)
3
5
  self << str.join
@@ -25,12 +27,48 @@ class Object
25
27
  # with any Ruby object). The file descriptor can safely be passed
26
28
  # to IO.new without creating a Ruby object alias to the fd.
27
29
  def new_fd(name, mode="w:utf-8")
30
+ mode = options_or_mode(mode)
31
+
32
+ if mode.kind_of? Hash
33
+ if mode.key? :mode
34
+ mode = mode[:mode]
35
+ else
36
+ raise ArgumentError, "new_fd options Hash must include :mode"
37
+ end
38
+ end
39
+
28
40
  IO.sysopen name, fmode(mode)
29
41
  end
30
42
 
31
43
  # Creates an IO instance for a temporary file name. The file
32
44
  # must be deleted.
33
45
  def new_io(name, mode="w:utf-8")
34
- IO.new new_fd(name, fmode(mode))
46
+ IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
47
+ end
48
+
49
+ # This helper simplifies passing file access modes regardless of
50
+ # whether the :encoding feature is enabled. Only the access specifier
51
+ # itself will be returned if :encoding is not enabled. Otherwise,
52
+ # the full mode string will be returned (i.e. the helper is a no-op).
53
+ def fmode(mode)
54
+ if FeatureGuard.enabled? :encoding
55
+ mode
56
+ else
57
+ mode.split(':').first
58
+ end
59
+ end
60
+
61
+ # This helper simplifies passing file access modes or options regardless of
62
+ # whether the :encoding feature is enabled. Only the access specifier itself
63
+ # will be returned if :encoding is not enabled. Otherwise, the full mode
64
+ # string or option will be returned (i.e. the helper is a no-op).
65
+ def options_or_mode(oom)
66
+ return fmode(oom) if oom.kind_of? String
67
+
68
+ if FeatureGuard.enabled? :encoding
69
+ oom
70
+ else
71
+ fmode(oom[:mode] || "r:utf-8")
72
+ end
35
73
  end
36
74
  end
@@ -0,0 +1,89 @@
1
+ class Object
2
+ def nan_value
3
+ 0/0.0
4
+ end
5
+
6
+ def infinity_value
7
+ 1/0.0
8
+ end
9
+
10
+ def bignum_value(plus=0)
11
+ 0x8000_0000_0000_0000 + plus
12
+ end
13
+
14
+ # This is a bit hairy, but we need to be able to write specs that cover the
15
+ # boundary between Fixnum and Bignum for operations like Fixnum#<<. Since
16
+ # this boundary is implementation-dependent, we use these helpers to write
17
+ # specs based on the relationship between values rather than specific
18
+ # values.
19
+ guard = SpecGuard.new
20
+
21
+ if guard.standard? or guard.implementation? :topaz
22
+ if guard.wordsize? 32
23
+ def fixnum_max()
24
+ (2**30) - 1
25
+ end
26
+
27
+ def fixnum_min()
28
+ -(2**30)
29
+ end
30
+ elsif guard.wordsize? 64
31
+ def fixnum_max()
32
+ (2**62) - 1
33
+ end
34
+
35
+ def fixnum_min()
36
+ -(2**62)
37
+ end
38
+ end
39
+ elsif guard.implementation? :rubinius
40
+ def fixnum_max()
41
+ Fixnum::MAX
42
+ end
43
+
44
+ def fixnum_min()
45
+ Fixnum::MIN
46
+ end
47
+ elsif guard.implementation? :jruby
48
+ # Values from jruby/test/testFixnumBignumAutoconversion.rb
49
+ def fixnum_max()
50
+ 9223372036854775807
51
+ end
52
+
53
+ def fixnum_min()
54
+ -9223372036854775808
55
+ end
56
+ elsif guard.implementation? :ironruby
57
+ def fixnum_max()
58
+ raise "fixnum_max() helper not implemented"
59
+ end
60
+
61
+ def fixnum_min()
62
+ raise "fixnum_min() helper not implemented"
63
+ end
64
+ elsif guard.implementation? :maglev
65
+ def fixnum_max()
66
+ raise "fixnum_max() helper not implemented"
67
+ end
68
+
69
+ def fixnum_min()
70
+ raise "fixnum_min() helper not implemented"
71
+ end
72
+ elsif guard.implementation? :macruby
73
+ def fixnum_max()
74
+ raise "fixnum_max() helper not implemented"
75
+ end
76
+
77
+ def fixnum_min()
78
+ raise "fixnum_min() helper not implemented"
79
+ end
80
+ else
81
+ def fixnum_max()
82
+ raise "unknown implementation for fixnum_max() helper"
83
+ end
84
+
85
+ def fixnum_min()
86
+ raise "unknown implementation for fixnum_min() helper"
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ def pack_int(*ary)
2
+ ary.pack("i*")
3
+ end
@@ -22,15 +22,19 @@ require 'mspec/guards/platform'
22
22
  #
23
23
  # `#{RUBY_EXE} -e #{'puts "hello, world."'}`
24
24
  #
25
- # The ruby_exe helper also accepts an options hash with two
26
- # keys: :options and :args. For example:
25
+ # The ruby_exe helper also accepts an options hash with three
26
+ # keys: :options, :args and :env. For example:
27
27
  #
28
- # ruby_exe('file.rb', :options => "-w", :args => "> file.txt")
28
+ # ruby_exe('file.rb', :options => "-w",
29
+ # :args => "> file.txt",
30
+ # :env => { :FOO => "bar" })
29
31
  #
30
32
  # will be executed as
31
33
  #
32
34
  # `#{RUBY_EXE} -w #{'file.rb'} > file.txt`
33
35
  #
36
+ # with access to ENV["FOO"] with value "bar".
37
+ #
34
38
  # If +nil+ is passed for the first argument, the command line
35
39
  # will be built only from the options hash.
36
40
  #
@@ -73,47 +77,81 @@ class Object
73
77
  when :engine
74
78
  case RUBY_NAME
75
79
  when 'rbx'
76
- "bin/rbx"
80
+ if SpecGuard.ruby_version < "1.9"
81
+ "bin/rbx"
82
+ else
83
+ "bin/rbx -X19"
84
+ end
77
85
  when 'jruby'
78
86
  "bin/jruby"
79
87
  when 'maglev'
80
88
  "maglev-ruby"
89
+ when 'topaz'
90
+ "topaz"
81
91
  when 'ironruby'
82
92
  "ir"
83
93
  end
84
94
  when :name
85
- bin = RUBY_NAME + (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '')
95
+ bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
86
96
  File.join(".", bin)
87
97
  when :install_name
88
- bin = Config::CONFIG["RUBY_INSTALL_NAME"] || Config::CONFIG["ruby_install_name"]
89
- bin << (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '')
90
- File.join(Config::CONFIG['bindir'], bin)
98
+ bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"]
99
+ bin << (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
100
+ File.join(RbConfig::CONFIG['bindir'], bin)
91
101
  end
92
102
  end
93
103
 
94
104
  def resolve_ruby_exe
95
105
  [:env, :engine, :name, :install_name].each do |option|
96
106
  next unless cmd = ruby_exe_options(option)
97
- exe = cmd.split.first
107
+ exe, *rest = cmd.split(" ")
98
108
 
99
109
  # It has been reported that File.executable is not reliable
100
110
  # on Windows platforms (see commit 56bc555c). So, we check the
101
- # platform.
111
+ # platform.
102
112
  if File.exists?(exe) and (PlatformGuard.windows? or File.executable?(exe))
103
- return cmd
113
+ return [File.expand_path(exe), *rest].join(" ")
104
114
  end
105
115
  end
106
116
  nil
107
117
  end
108
118
 
109
119
  def ruby_exe(code, opts = {})
110
- body = code
120
+ env = opts[:env] || {}
111
121
  working_dir = opts[:dir] || "."
112
122
  Dir.chdir(working_dir) do
113
- body = "-e #{code.inspect}" if code and not File.exists?(code)
114
- cmd = [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]]
115
- `#{cmd.compact.join(' ')}`
123
+ saved_env = {}
124
+ env.each do |key, value|
125
+ key = key.to_s
126
+ saved_env[key] = ENV[key] if ENV.key? key
127
+ ENV[key] = value
128
+ end
129
+
130
+ begin
131
+ `#{ruby_cmd(code, opts)}`
132
+ ensure
133
+ saved_env.each { |key, value| ENV[key] = value }
134
+ env.keys.each do |key|
135
+ key = key.to_s
136
+ ENV.delete key unless saved_env.key? key
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ def ruby_cmd(code, opts = {})
143
+ body = code
144
+
145
+ if code and not File.exists?(code)
146
+ if opts[:escape]
147
+ code = "'#{code}'"
148
+ else
149
+ code = code.inspect
150
+ end
151
+ body = "-e #{code}"
116
152
  end
153
+
154
+ [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]].compact.join(' ')
117
155
  end
118
156
 
119
157
  unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE