summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerence Lee <hone02@gmail.com>2011-10-01 21:37:31 -0500
committerTerence Lee <hone02@gmail.com>2011-10-01 21:37:31 -0500
commitf53243d843aa4b08d24db4ad1e43688e0a534a39 (patch)
treef5232f47b49bf28b8b214a63fd2418da414aa63d
parent1ba329499ea02f5a951d4a49b2f4f2939e9c9b54 (diff)
downloadbundler-f53243d843aa4b08d24db4ad1e43688e0a534a39.tar.gz
#1458. refactor load error tests
-rw-r--r--spec/install/gems/groups_spec.rb30
-rw-r--r--spec/install/gems/standalone_spec.rb24
-rw-r--r--spec/runtime/require_spec.rb20
-rw-r--r--spec/support/helpers.rb24
4 files changed, 45 insertions, 53 deletions
diff --git a/spec/install/gems/groups_spec.rb b/spec/install/gems/groups_spec.rb
index 0b3b444ce7..47123599fe 100644
--- a/spec/install/gems/groups_spec.rb
+++ b/spec/install/gems/groups_spec.rb
@@ -21,13 +21,9 @@ describe "bundle install with gem sources" do
it "installs gems in a group block into that group" do
should_be_installed "activesupport 2.3.5"
- run <<-R, :default, :expect_err => true
- begin
- require 'activesupport'
- puts ACTIVESUPPORT
- rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- activesupport")
- end
+ load_error_run <<-R, 'activesupport', :default
+ require 'activesupport'
+ puts ACTIVESUPPORT
R
err.should == "ZOMG LOAD ERROR"
@@ -36,13 +32,9 @@ describe "bundle install with gem sources" do
it "installs gems with inline :groups into those groups" do
should_be_installed "thin 1.0"
- run <<-R, :default, :expect_err => true
- begin
- require 'thin'
- puts THIN
- rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- thin")
- end
+ load_error_run <<-R, 'thin', :default
+ require 'thin'
+ puts THIN
R
err.should == "ZOMG LOAD ERROR"
@@ -60,14 +52,10 @@ describe "bundle install with gem sources" do
end
it "removes old groups when new groups are set up" do
- run <<-RUBY, :emo, :expect_err => true
+ load_error_run <<-RUBY, 'thin', :emo
Bundler.setup(:default)
- begin
- require 'thin'
- puts THIN
- rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- thin")
- end
+ require 'thin'
+ puts THIN
RUBY
err.should == "ZOMG LOAD ERROR"
diff --git a/spec/install/gems/standalone_spec.rb b/spec/install/gems/standalone_spec.rb
index 88c170a615..9752f47ce5 100644
--- a/spec/install/gems/standalone_spec.rb
+++ b/spec/install/gems/standalone_spec.rb
@@ -113,17 +113,13 @@ describe "bundle install --standalone" do
it "allows creating a standalone file with limited groups" do
bundle "install --standalone default"
- ruby <<-RUBY, :no_lib => true, :expect_err => true
+ load_error_ruby <<-RUBY, 'spec', :no_lib => true
$:.unshift File.expand_path("bundle")
require "bundler/setup"
require "actionpack"
puts ACTIONPACK
- begin
- require "spec"
- rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- spec")
- end
+ require "spec"
RUBY
out.should be == "2.3.2"
@@ -133,17 +129,13 @@ describe "bundle install --standalone" do
it "allows --without to limit the groups used in a standalone" do
bundle "install --standalone --without test"
- ruby <<-RUBY, :no_lib => true, :expect_err => true
+ load_error_ruby <<-RUBY, 'spec', :no_lib => true
$:.unshift File.expand_path("bundle")
require "bundler/setup"
require "actionpack"
puts ACTIONPACK
- begin
- require "spec"
- rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- spec")
- end
+ require "spec"
RUBY
out.should be == "2.3.2"
@@ -168,17 +160,13 @@ describe "bundle install --standalone" do
bundle "install --without test"
bundle "install --standalone"
- ruby <<-RUBY, :no_lib => true, :expect_err => true
+ load_error_ruby <<-RUBY, 'spec', :no_lib => true
$:.unshift File.expand_path("bundle")
require "bundler/setup"
require "actionpack"
puts ACTIONPACK
- begin
- require "spec"
- rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- spec")
- end
+ require "spec"
RUBY
out.should be == "2.3.2"
diff --git a/spec/runtime/require_spec.rb b/spec/runtime/require_spec.rb
index b336ed9a7a..bad1ec9730 100644
--- a/spec/runtime/require_spec.rb
+++ b/spec/runtime/require_spec.rb
@@ -82,15 +82,11 @@ describe "Bundler.require" do
gem "two", :require => 'fail'
G
- run <<-R
- begin
- Bundler.require
- rescue LoadError => e
- puts "ZOMG ERROR" if e.message.include?("-- fail")
- end
+ load_error_run <<-R, 'fail'
+ Bundler.require
R
- out.should == "ZOMG ERROR"
+ err.should == "ZOMG LOAD ERROR"
end
describe "using bundle exec" do
@@ -192,14 +188,10 @@ describe "Bundler.require" do
gem "busted_require"
G
- run <<-R
- begin
- Bundler.require
- rescue LoadError => e
- puts 'ZOMG ERROR' if e.message.include?("-- no_such_file_omg")
- end
+ load_error_run <<-R, 'no_such_file_omg'
+ Bundler.require
R
- out.should == 'ZOMG ERROR'
+ err.should == 'ZOMG LOAD ERROR'
end
end
end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 4d7b9e20a8..c275e6ba8e 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -35,6 +35,19 @@ module Spec
@out = ruby(setup + cmd, :expect_err => expect_err, :env => env)
end
+ def load_error_run(ruby, gem, *args)
+ cmd = <<-R
+ begin
+ #{ruby}
+ rescue LoadError => e
+ $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- #{gem}")
+ end
+ R
+ opts = args.last.is_a?(Hash) ? args.pop : {}
+ opts.merge!(:expect_err => true)
+ run(cmd, *args, opts)
+ end
+
def lib
File.expand_path('../../../lib', __FILE__)
end
@@ -73,6 +86,17 @@ module Spec
sys_exec(%{#{env}#{Gem.ruby}#{lib_option} -e "#{ruby}"}, expect_err)
end
+ def load_error_ruby(ruby, gem, opts = {})
+ cmd = <<-R
+ begin
+ #{ruby}
+ rescue LoadError => e
+ $stderr.puts "ZOMG LOAD ERROR"# if e.message.include?("-- #{gem}")
+ end
+ R
+ ruby(cmd, opts.merge(:expect_err => true))
+ end
+
def gembin(cmd)
lib = File.expand_path("../../../lib", __FILE__)
old, ENV['RUBYOPT'] = ENV['RUBYOPT'], "#{ENV['RUBYOPT']} -I#{lib}"