diff options
Diffstat (limited to 'spec/mspec/spec/helpers/ruby_exe_spec.rb')
-rw-r--r-- | spec/mspec/spec/helpers/ruby_exe_spec.rb | 109 |
1 files changed, 56 insertions, 53 deletions
diff --git a/spec/mspec/spec/helpers/ruby_exe_spec.rb b/spec/mspec/spec/helpers/ruby_exe_spec.rb index 8036043578..32b3818853 100644 --- a/spec/mspec/spec/helpers/ruby_exe_spec.rb +++ b/spec/mspec/spec/helpers/ruby_exe_spec.rb @@ -10,7 +10,7 @@ class RubyExeSpecs public :ruby_exe end -describe "#ruby_exe_options" do +RSpec.describe "#ruby_exe_options" do before :each do @ruby_exe_env = ENV['RUBY_EXE'] @script = RubyExeSpecs.new @@ -22,89 +22,89 @@ describe "#ruby_exe_options" do it "returns ENV['RUBY_EXE'] when passed :env" do ENV['RUBY_EXE'] = "kowabunga" - @script.ruby_exe_options(:env).should == "kowabunga" + expect(@script.ruby_exe_options(:env)).to eq("kowabunga") end it "returns 'bin/jruby' when passed :engine and RUBY_ENGINE is 'jruby'" do stub_const "RUBY_ENGINE", 'jruby' - @script.ruby_exe_options(:engine).should == 'bin/jruby' + expect(@script.ruby_exe_options(:engine)).to eq('bin/jruby') end it "returns 'bin/rbx' when passed :engine, RUBY_ENGINE is 'rbx'" do stub_const "RUBY_ENGINE", 'rbx' - @script.ruby_exe_options(:engine).should == 'bin/rbx' + expect(@script.ruby_exe_options(:engine)).to eq('bin/rbx') end it "returns 'ir' when passed :engine and RUBY_ENGINE is 'ironruby'" do stub_const "RUBY_ENGINE", 'ironruby' - @script.ruby_exe_options(:engine).should == 'ir' + expect(@script.ruby_exe_options(:engine)).to eq('ir') end it "returns 'maglev-ruby' when passed :engine and RUBY_ENGINE is 'maglev'" do stub_const "RUBY_ENGINE", 'maglev' - @script.ruby_exe_options(:engine).should == 'maglev-ruby' + expect(@script.ruby_exe_options(:engine)).to eq('maglev-ruby') end it "returns 'topaz' when passed :engine and RUBY_ENGINE is 'topaz'" do stub_const "RUBY_ENGINE", 'topaz' - @script.ruby_exe_options(:engine).should == 'topaz' + expect(@script.ruby_exe_options(:engine)).to eq('topaz') end it "returns RUBY_ENGINE + $(EXEEXT) when passed :name" do bin = RUBY_ENGINE + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') name = File.join ".", bin - @script.ruby_exe_options(:name).should == name + expect(@script.ruby_exe_options(:name)).to eq(name) end it "returns $(bindir)/$(RUBY_INSTALL_NAME) + $(EXEEXT) when passed :install_name" do bin = RbConfig::CONFIG['RUBY_INSTALL_NAME'] + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') name = File.join RbConfig::CONFIG['bindir'], bin - @script.ruby_exe_options(:install_name).should == name + expect(@script.ruby_exe_options(:install_name)).to eq(name) end end -describe "#resolve_ruby_exe" do +RSpec.describe "#resolve_ruby_exe" do before :each do @name = "ruby_spec_exe" @script = RubyExeSpecs.new end it "returns the value returned by #ruby_exe_options if it exists and is executable" do - @script.should_receive(:ruby_exe_options).and_return(@name) - File.should_receive(:file?).with(@name).and_return(true) - File.should_receive(:executable?).with(@name).and_return(true) - File.should_receive(:expand_path).with(@name).and_return(@name) - @script.resolve_ruby_exe.should == @name + expect(@script).to receive(:ruby_exe_options).and_return(@name) + expect(File).to receive(:file?).with(@name).and_return(true) + expect(File).to receive(:executable?).with(@name).and_return(true) + expect(File).to receive(:expand_path).with(@name).and_return(@name) + expect(@script.resolve_ruby_exe).to eq(@name) end it "expands the path portion of the result of #ruby_exe_options" do - @script.should_receive(:ruby_exe_options).and_return("#{@name}") - File.should_receive(:file?).with(@name).and_return(true) - File.should_receive(:executable?).with(@name).and_return(true) - File.should_receive(:expand_path).with(@name).and_return("/usr/bin/#{@name}") - @script.resolve_ruby_exe.should == "/usr/bin/#{@name}" + expect(@script).to receive(:ruby_exe_options).and_return("#{@name}") + expect(File).to receive(:file?).with(@name).and_return(true) + expect(File).to receive(:executable?).with(@name).and_return(true) + expect(File).to receive(:expand_path).with(@name).and_return("/usr/bin/#{@name}") + expect(@script.resolve_ruby_exe).to eq("/usr/bin/#{@name}") end it "adds the flags after the executable" do @name = 'bin/rbx' - @script.should_receive(:ruby_exe_options).and_return(@name) - File.should_receive(:file?).with(@name).and_return(true) - File.should_receive(:executable?).with(@name).and_return(true) - File.should_receive(:expand_path).with(@name).and_return(@name) + expect(@script).to receive(:ruby_exe_options).and_return(@name) + expect(File).to receive(:file?).with(@name).and_return(true) + expect(File).to receive(:executable?).with(@name).and_return(true) + expect(File).to receive(:expand_path).with(@name).and_return(@name) - ENV.should_receive(:[]).with("RUBY_FLAGS").and_return('-X19') - @script.resolve_ruby_exe.should == 'bin/rbx -X19' + expect(ENV).to receive(:[]).with("RUBY_FLAGS").and_return('-X19') + expect(@script.resolve_ruby_exe).to eq('bin/rbx -X19') end it "raises an exception if no exe is found" do - File.should_receive(:file?).at_least(:once).and_return(false) - lambda { + expect(File).to receive(:file?).at_least(:once).and_return(false) + expect { @script.resolve_ruby_exe - }.should raise_error(Exception) + }.to raise_error(Exception) end end -describe Object, "#ruby_cmd" do +RSpec.describe Object, "#ruby_cmd" do before :each do stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q' @@ -115,83 +115,86 @@ describe Object, "#ruby_cmd" do end it "returns a command that runs the given file if it is a file that exists" do - File.should_receive(:exist?).with(@file).and_return(true) - @script.ruby_cmd(@file).should == "ruby_spec_exe -w -Q some/ruby/file.rb" + expect(File).to receive(:exist?).with(@file).and_return(true) + expect(@script.ruby_cmd(@file)).to eq("ruby_spec_exe -w -Q some/ruby/file.rb") end it "includes the given options and arguments with a file" do - File.should_receive(:exist?).with(@file).and_return(true) - @script.ruby_cmd(@file, :options => "-w -Cdir", :args => "< file.txt").should == + expect(File).to receive(:exist?).with(@file).and_return(true) + expect(@script.ruby_cmd(@file, :options => "-w -Cdir", :args => "< file.txt")).to eq( "ruby_spec_exe -w -Q -w -Cdir some/ruby/file.rb < file.txt" + ) end it "includes the given options and arguments with -e" do - File.should_receive(:exist?).with(@code).and_return(false) - @script.ruby_cmd(@code, :options => "-W0 -Cdir", :args => "< file.txt").should == + expect(File).to receive(:exist?).with(@code).and_return(false) + expect(@script.ruby_cmd(@code, :options => "-W0 -Cdir", :args => "< file.txt")).to eq( %(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 == + expect(@script.ruby_cmd(nil, :options => "-c", :args => "> file.txt")).to eq( "ruby_spec_exe -w -Q -c > file.txt" + ) end end -describe Object, "#ruby_exe" do +RSpec.describe Object, "#ruby_exe" do before :each do stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q' @script = RubyExeSpecs.new - @script.stub(:`) + allow(@script).to receive(:`) end it "returns an Array containing the interpreter executable and flags when given no arguments" do - @script.ruby_exe.should == ['ruby_spec_exe', '-w', '-Q'] + expect(@script.ruby_exe).to eq(['ruby_spec_exe', '-w', '-Q']) end it "executes (using `) the result of calling #ruby_cmd with the given arguments" do code = "code" options = {} - @script.should_receive(:ruby_cmd).and_return("ruby_cmd") - @script.should_receive(:`).with("ruby_cmd") + expect(@script).to receive(:ruby_cmd).and_return("ruby_cmd") + expect(@script).to receive(:`).with("ruby_cmd") @script.ruby_exe(code, options) end describe "with :dir option" do it "is deprecated" do - lambda { + expect { @script.ruby_exe nil, :dir => "tmp" - }.should raise_error(/no longer supported, use Dir\.chdir/) + }.to raise_error(/no longer supported, use Dir\.chdir/) end end describe "with :env option" do it "preserves the values of existing ENV keys" do ENV["ABC"] = "123" - ENV.stub(:[]) - ENV.should_receive(:[]).with("ABC") + allow(ENV).to receive(:[]) + expect(ENV).to receive(:[]).with("ABC") @script.ruby_exe nil, :env => { :ABC => "xyz" } end it "adds the :env entries to ENV" do - ENV.should_receive(:[]=).with("ABC", "xyz") + expect(ENV).to receive(:[]=).with("ABC", "xyz") @script.ruby_exe nil, :env => { :ABC => "xyz" } end it "deletes the :env entries in ENV when an exception is raised" do - ENV.should_receive(:delete).with("XYZ") + expect(ENV).to receive(:delete).with("XYZ") @script.ruby_exe nil, :env => { :XYZ => "xyz" } end it "resets the values of existing ENV keys when an exception is raised" do ENV["ABC"] = "123" - ENV.should_receive(:[]=).with("ABC", "xyz") - ENV.should_receive(:[]=).with("ABC", "123") + expect(ENV).to receive(:[]=).with("ABC", "xyz") + expect(ENV).to receive(:[]=).with("ABC", "123") - @script.should_receive(:`).and_raise(Exception) - lambda do + expect(@script).to receive(:`).and_raise(Exception) + expect do @script.ruby_exe nil, :env => { :ABC => "xyz" } - end.should raise_error(Exception) + end.to raise_error(Exception) end end end |