|
2 | 2 | require 'mspec/helpers/tmp'
|
3 | 3 |
|
4 | 4 | # The ruby_exe helper provides a wrapper for invoking the
|
5 |
| -# same Ruby interpreter with the same falgs as the one running |
| 5 | +# same Ruby interpreter with the same flags as the one running |
6 | 6 | # the specs and getting the output from running the code.
|
| 7 | +# |
7 | 8 | # If +code+ is a file that exists, it will be run.
|
8 |
| -# Otherwise, +code+ should be Ruby code that will be run with |
9 |
| -# the -e command line option. For example: |
| 9 | +# Otherwise, +code+ will be written to a temporary file and be run. |
| 10 | +# For example: |
10 | 11 | #
|
11 | 12 | # ruby_exe('path/to/some/file.rb')
|
12 | 13 | #
|
13 | 14 | # will be executed as
|
14 | 15 | #
|
15 | 16 | # `#{RUBY_EXE} 'path/to/some/file.rb'`
|
16 | 17 | #
|
17 |
| -# while |
18 |
| -# |
19 |
| -# ruby_exe('puts "hello, world."') |
20 |
| -# |
21 |
| -# will be executed as |
22 |
| -# |
23 |
| -# `#{RUBY_EXE} -e 'puts "hello, world."'` |
24 |
| -# |
25 | 18 | # The ruby_exe helper also accepts an options hash with three
|
26 | 19 | # keys: :options, :args and :env. For example:
|
27 | 20 | #
|
28 | 21 | # ruby_exe('file.rb', :options => "-w",
|
29 |
| -# :args => "> file.txt", |
| 22 | +# :args => "arg1 arg2", |
30 | 23 | # :env => { :FOO => "bar" })
|
31 | 24 | #
|
32 | 25 | # will be executed as
|
33 | 26 | #
|
34 |
| -# `#{RUBY_EXE} -w #{'file.rb'} > file.txt` |
| 27 | +# `#{RUBY_EXE} -w file.rb arg1 arg2` |
35 | 28 | #
|
36 | 29 | # with access to ENV["FOO"] with value "bar".
|
37 | 30 | #
|
|
49 | 42 | # The RUBY_EXE constant is setup by mspec automatically
|
50 | 43 | # and is used by ruby_exe and ruby_cmd. The mspec runner script
|
51 | 44 | # will set ENV['RUBY_EXE'] to the name of the executable used
|
52 |
| -# to invoke the mspec-run script. The value of RUBY_EXE will be |
53 |
| -# constructed as follows: |
54 |
| -# |
55 |
| -# 1. the value of ENV['RUBY_EXE'] |
56 |
| -# 2. an explicit value based on RUBY_ENGINE |
57 |
| -# 3. cwd/(RUBY_ENGINE + $(EXEEXT) || $(exeext) || '') |
58 |
| -# 4. $(bindir)/$(RUBY_INSTALL_NAME) |
| 45 | +# to invoke the mspec-run script. |
59 | 46 | #
|
60 | 47 | # The value will only be used if the file exists and is executable.
|
61 |
| -# The flags will then be appended to the resulting value. |
62 |
| -# |
63 |
| -# These 4 ways correspond to the following scenarios: |
64 |
| -# |
65 |
| -# 1. Using the MSpec runner scripts, the name of the |
66 |
| -# executable is explicitly passed by ENV['RUBY_EXE'] |
67 |
| -# so there is no ambiguity. |
68 |
| -# |
69 |
| -# Otherwise, if using RSpec (or something else) |
70 |
| -# |
71 |
| -# 2. Running the specs while developing an alternative |
72 |
| -# Ruby implementation. This explicitly names the |
73 |
| -# executable in the development directory based on |
74 |
| -# the value of RUBY_ENGINE. |
75 |
| -# 3. Running the specs within the source directory for |
76 |
| -# some implementation. (E.g. a local build directory.) |
77 |
| -# 4. Running the specs against some installed Ruby |
78 |
| -# implementation. |
| 48 | +# The flags will then be appended to the resulting value, such that |
| 49 | +# the RUBY_EXE constant contains both the executable and the flags. |
79 | 50 | #
|
80 | 51 | # Additionally, the flags passed to mspec
|
81 | 52 | # (with -T on the command line or in the config with set :flags)
|
@@ -129,6 +100,10 @@ def resolve_ruby_exe
|
129 | 100 | raise Exception, "Unable to find a suitable ruby executable."
|
130 | 101 | end
|
131 | 102 |
|
| 103 | +unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE |
| 104 | + RUBY_EXE = resolve_ruby_exe |
| 105 | +end |
| 106 | + |
132 | 107 | def ruby_exe(code = :not_given, opts = {})
|
133 | 108 | if opts[:dir]
|
134 | 109 | raise "ruby_exe(..., dir: dir) is no longer supported, use Dir.chdir"
|
@@ -180,7 +155,3 @@ def ruby_cmd(code, opts = {})
|
180 | 155 |
|
181 | 156 | [RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ')
|
182 | 157 | end
|
183 |
| - |
184 |
| -unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE |
185 |
| - RUBY_EXE = resolve_ruby_exe |
186 |
| -end |
0 commit comments