Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update mspec to 8ea1d4f12d7fa5e4b5f339559b9166d17b254987

  • Loading branch information...
commit 806b4828d7eea388830dc1b14ae57ed6c619752e 1 parent 9989999
@Watson1978 Watson1978 authored
View
28 mspec/lib/mspec/helpers/ruby_exe.rb
@@ -115,19 +115,9 @@ def resolve_ruby_exe
end
def ruby_exe(code, opts = {})
- body = code
env = opts[:env] || {}
working_dir = opts[:dir] || "."
Dir.chdir(working_dir) do
- if code and not File.exists?(code)
- if opts[:escape]
- code = "'#{code}'"
- else
- code = code.inspect
- end
- body = "-e #{code}"
- end
-
saved_env = {}
env.each do |key, value|
key = key.to_s
@@ -136,8 +126,7 @@ def ruby_exe(code, opts = {})
end
begin
- cmd = [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]]
- `#{cmd.compact.join(' ')}`
+ `#{ruby_cmd(code, opts)}`
ensure
saved_env.each { |key, value| ENV[key] = value }
env.keys.each do |key|
@@ -148,6 +137,21 @@ def ruby_exe(code, opts = {})
end
end
+ def ruby_cmd(code, opts = {})
+ body = code
+
+ if code and not File.exists?(code)
+ if opts[:escape]
+ code = "'#{code}'"
+ else
+ code = code.inspect
+ end
+ body = "-e #{code}"
+ end
+
+ [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]].compact.join(' ')
+ end
+
unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE
require 'rbconfig'
View
56 mspec/spec/helpers/ruby_exe_spec.rb
@@ -133,7 +133,7 @@ class RubyExeSpecs
end
end
-describe Object, "#ruby_exe" do
+describe Object, "#ruby_cmd" do
before :all do
@verbose = $VERBOSE
$VERBOSE = nil
@@ -156,36 +156,49 @@ class RubyExeSpecs
$VERBOSE = @verbose
end
- it "executes the argument if it is a file that exists" do
+ it "returns a command that runs the given file if it is a file that exists" do
File.should_receive(:exists?).with(@file).and_return(true)
- @script.should_receive(:`).with("ruby_spec_exe -w -Q some/ruby/file.rb")
- @script.ruby_exe @file
+ @script.ruby_cmd(@file).should == "ruby_spec_exe -w -Q some/ruby/file.rb"
end
- it "executes the file with options and arguments" do
+ it "includes the given options and arguments with a file" do
File.should_receive(:exists?).with(@file).and_return(true)
- @script.should_receive(:`).with(
- "ruby_spec_exe -w -Q -w -Cdir some/ruby/file.rb < file.txt")
- @script.ruby_exe @file, :options => "-w -Cdir", :args => "< file.txt"
+ @script.ruby_cmd(@file, :options => "-w -Cdir", :args => "< file.txt").should ==
+ "ruby_spec_exe -w -Q -w -Cdir some/ruby/file.rb < file.txt"
end
- it "executes the argument with -e" do
+ it "returns a command that runs code using -e" do
File.should_receive(:exists?).with(@code).and_return(false)
- @script.should_receive(:`).with(
- %(ruby_spec_exe -w -Q -e "some \\"real\\" 'ruby' code"))
- @script.ruby_exe @code
+ @script.ruby_cmd(@code).should == %(ruby_spec_exe -w -Q -e "some \\"real\\" 'ruby' code")
end
- it "executes the code with options and arguments" do
+ it "includes the given options and arguments with -e" do
File.should_receive(:exists?).with(@code).and_return(false)
- @script.should_receive(:`).with(
- %(ruby_spec_exe -w -Q -W0 -Cdir -e "some \\"real\\" 'ruby' code" < file.txt))
- @script.ruby_exe @code, :options => "-W0 -Cdir", :args => "< file.txt"
+ @script.ruby_cmd(@code, :options => "-W0 -Cdir", :args => "< file.txt").should ==
+ %(ruby_spec_exe -w -Q -W0 -Cdir -e "some \\"real\\" 'ruby' code" < file.txt)
+ end
+
+ it "returns a command with options and arguments but without code or file" do
+ @script.ruby_cmd(nil, :options => "-c", :args => "> file.txt").should ==
+ "ruby_spec_exe -w -Q -c > file.txt"
+ end
+end
+
+describe Object, "#ruby_exe" do
+ before :all do
+ @script = RubyExeSpecs.new
+ end
+
+ before :each do
+ @script.stub!(:`)
end
- it "executes with options and arguments but without code or file" do
- @script.should_receive(:`).with("ruby_spec_exe -w -Q -c > file.txt")
- @script.ruby_exe nil, :options => "-c", :args => "> file.txt"
+ it "executes (using `) the result of calling #ruby_cmd with the given arguments" do
+ code = "code"
+ options = {}
+ @script.should_receive(:ruby_cmd).with(code, options).and_return("ruby_cmd")
+ @script.should_receive(:`).with("ruby_cmd")
+ @script.ruby_exe(code, options)
end
describe "with :dir option" do
@@ -196,10 +209,6 @@ class RubyExeSpecs
end
describe "with :env option" do
- before :each do
- @script.stub!(:`)
- end
-
it "preserves the values of existing ENV keys" do
ENV["ABC"] = "123"
ENV.should_receive(:[]).with("RUBY_FLAGS")
@@ -227,6 +236,5 @@ class RubyExeSpecs
@script.ruby_exe nil, :env => { :ABC => "xyz" }
end.should raise_error(Exception)
end
-
end
end
View
2  mspec/upstream
@@ -1 +1 @@
-1852dc783135155ce36298d50d8b18cf95a02668
+8ea1d4f12d7fa5e4b5f339559b9166d17b254987
Please sign in to comment.
Something went wrong with that request. Please try again.