Skip to content

Commit

Permalink
Pass -T flags to executable in ruby_exe helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ford committed Aug 4, 2008
1 parent de768fc commit d8c753c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/mspec/commands/mspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def multi_exec(argv)

def run
ENV['MSPEC_RUNNER'] = '1'
ENV['RUBY_EXE'] = config[:target]
ENV['RUBY_EXE'] = config[:target]
ENV['RUBY_FLAGS'] = config[:flags].join " "

argv = []
argv.concat config[:flags]
Expand Down
4 changes: 2 additions & 2 deletions lib/mspec/helpers/ruby_exe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def resolve_ruby_exe

def ruby_exe(code)
if File.exists?(code) and File.executable?(code)
`#{RUBY_EXE} #{code}`
`#{RUBY_EXE} #{ENV['RUBY_FLAGS']} #{code}`
else
`#{RUBY_EXE} -e #{code.inspect}`
`#{RUBY_EXE} #{ENV['RUBY_FLAGS']} -e #{code.inspect}`
end
end
end
1 change: 0 additions & 1 deletion lib/mspec/utils/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def targets
case t
when 'r', 'ruby'
config[:target] = 'ruby'
config[:flags] << '-v'
when 'r19', 'ruby19'
config[:target] = 'ruby19'
when 'x', 'rubinius'
Expand Down
11 changes: 9 additions & 2 deletions spec/commands/mspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,29 @@
@options, @config = new_option
MSpecOptions.stub!(:new).and_return(@options)
@script = MSpecMain.new
@script.stub!(:config).and_return(@config)
@script.stub!(:exec)
end

it "sets MSPEC_RUNNER = '1' in the environment" do
@script.stub!(:exec)
ENV["MSPEC_RUNNER"] = "0"
@script.run
ENV["MSPEC_RUNNER"].should == "1"
end

it "sets RUBY_EXE = config[:target] in the environment" do
@script.stub!(:exec)
ENV["RUBY_EXE"] = nil
@script.run
ENV["RUBY_EXE"].should == @config[:target]
end

it "sets RUBY_FLAGS = config[:flags] in the environment" do
ENV["RUBY_FLAGS"] = nil
@config[:flags] = ["-w", "-Q"]
@script.run
ENV["RUBY_FLAGS"].should == "-w -Q"
end

it "uses exec to invoke the runner script" do
@script.should_receive(:exec).with("ruby", "-v", %r"mspec/bin/mspec-run$")
@script.options
Expand Down
8 changes: 6 additions & 2 deletions spec/helpers/ruby_exe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class RubyExeSpecs
@verbose = $VERBOSE
$VERBOSE = nil

@ruby_flags = ENV["RUBY_FLAGS"]
ENV["RUBY_FLAGS"] = "-w -Q"

@ruby_exe = Object.const_get :RUBY_EXE
Object.const_set :RUBY_EXE, 'ruby_spec_exe'

Expand All @@ -85,21 +88,22 @@ class RubyExeSpecs

after :all do
Object.const_set :RUBY_EXE, @ruby_exe
ENV["RUBY_FLAGS"] = @ruby_flags
$VERBOSE = @verbose
end

it "executes the argument if it is a file that exists and is executable" do
code = "some/ruby/file.rb"
File.should_receive(:exists?).with(code).and_return(true)
File.should_receive(:executable?).with(code).and_return(true)
@script.should_receive(:`).with("ruby_spec_exe some/ruby/file.rb")
@script.should_receive(:`).with("ruby_spec_exe -w -Q some/ruby/file.rb")
@script.ruby_exe code
end

it "executes the argument with -e" do
code = %(some "real" 'ruby' code)
File.should_receive(:exists?).with(code).and_return(false)
@script.should_receive(:`).with(%(ruby_spec_exe -e "some \\"real\\" 'ruby' code"))
@script.should_receive(:`).with(%(ruby_spec_exe -w -Q -e "some \\"real\\" 'ruby' code"))
@script.ruby_exe code
end
end
1 change: 0 additions & 1 deletion spec/utils/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@
["-t", "--target"].each do |opt|
@options.parse [opt, "ruby"]
@config[:target].should == "ruby"
@config[:flags].should include("-v")
end
end

Expand Down

0 comments on commit d8c753c

Please sign in to comment.