summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-01-10 00:12:06 -0600
committerSamuel Giddins <segiddins@segiddins.me>2016-01-25 10:49:51 -0600
commit32595930a639549cbf6aa523ee831a3d51209150 (patch)
treeadc4d6585782e8c51ac1e861f05006d355261bf3
parentc19c34a5404322816610562b1e7f5541329558e2 (diff)
downloadbundler-32595930a639549cbf6aa523ee831a3d51209150.tar.gz
Add bang versions of the spec helpers
-rw-r--r--spec/install/gems/compact_index_spec.rb66
-rw-r--r--spec/support/helpers.rb18
-rw-r--r--spec/support/matchers.rb7
3 files changed, 54 insertions, 37 deletions
diff --git a/spec/install/gems/compact_index_spec.rb b/spec/install/gems/compact_index_spec.rb
index 717ef8a086..1069027a9d 100644
--- a/spec/install/gems/compact_index_spec.rb
+++ b/spec/install/gems/compact_index_spec.rb
@@ -10,7 +10,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
expect(out).to include("Fetching gem metadata from #{source_uri}")
should_be_installed "rack 1.0.0"
end
@@ -31,7 +31,7 @@ describe "compact index api" do
gem "rails"
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
expect(out).to include("Fetching gem metadata from #{source_uri}")
should_be_installed(
"rails 2.3.2",
@@ -48,7 +48,7 @@ describe "compact index api" do
gem "net-sftp"
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
should_be_installed "net-sftp 1.1.1"
end
@@ -57,7 +57,7 @@ describe "compact index api" do
source "#{source_uri}"
gem "rack"
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
bundle "install --deployment", :artifice => "compact_index"
expect(out).to include("Fetching gem metadata from #{source_uri}")
@@ -77,7 +77,7 @@ describe "compact index api" do
end
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
should_be_installed("rails 2.3.2")
end
@@ -93,7 +93,7 @@ describe "compact index api" do
gem 'foo', :git => "file:///#{lib_path("foo-1.0")}"
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
bundle "install --deployment", :artifice => "compact_index"
@@ -122,7 +122,7 @@ describe "compact index api" do
gem "rcov"
G
- bundle :install, :fakeweb => "windows"
+ bundle! :install, :fakeweb => "windows"
expect(out).to include("Fetching source index from #{source_uri}")
should_be_installed "rcov 1.0.0"
end
@@ -133,7 +133,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :verbose => true, :artifice => "compact_index_forbidden"
+ bundle! :install, :verbose => true, :artifice => "compact_index_forbidden"
expect(out).to include("Fetching gem metadata from #{source_uri}")
should_be_installed "rack 1.0.0"
end
@@ -144,7 +144,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :artifice => "compact_index_host_redirect"
+ bundle! :install, :artifice => "compact_index_host_redirect"
should_be_installed "rack 1.0.0"
end
@@ -167,7 +167,7 @@ describe "compact index api" do
H
end
- bundle :install, :artifice => "compact_index_host_redirect", :requires => [lib_path("disable_net_http_persistent.rb")]
+ bundle! :install, :artifice => "compact_index_host_redirect", :requires => [lib_path("disable_net_http_persistent.rb")]
expect(out).to_not match(/Too many redirects/)
should_be_installed "rack 1.0.0"
end
@@ -220,7 +220,7 @@ describe "compact index api" do
gem "back_deps"
G
- bundle :install, :artifice => "compact_index_extra"
+ bundle! :install, :artifice => "compact_index_extra"
should_be_installed "back_deps 1.0"
end
@@ -229,7 +229,7 @@ describe "compact index api" do
source "#{source_uri}"
gem "rack", "1.0.0"
G
- bundle :install, :artifice => "compact_index_extra_api"
+ bundle! :install, :artifice => "compact_index_extra_api"
should_be_installed "rack 1.0.0"
build_repo4 do
@@ -243,7 +243,7 @@ describe "compact index api" do
source "#{source_uri}/extra"
gem "rack", "1.2"
G
- bundle :install, :artifice => "compact_index_extra_api"
+ bundle! :install, :artifice => "compact_index_extra_api"
should_be_installed "rack 1.2"
end
@@ -265,7 +265,7 @@ describe "compact index api" do
gem 'somegem', '1.0.0'
G
- bundle :install, :artifice => "compact_index_extra_api"
+ bundle! :install, :artifice => "compact_index_extra_api"
should_be_installed "somegem 1.0.0"
should_be_installed "activesupport 1.2.3"
@@ -285,7 +285,7 @@ describe "compact index api" do
gem "back_deps"
G
- bundle :install, :artifice => "compact_index_extra"
+ bundle! :install, :artifice => "compact_index_extra"
expect(out).to include("Fetching gem metadata from http://localgemserver.test/")
expect(out).to include("Fetching source index from http://localgemserver.test/extra")
@@ -311,7 +311,7 @@ describe "compact index api" do
gem "back_deps"
G
- bundle :install, :artifice => "compact_index_extra_missing"
+ bundle! :install, :artifice => "compact_index_extra_missing"
should_be_installed "back_deps 1.0"
end
@@ -322,7 +322,7 @@ describe "compact index api" do
gem 'foo'
G
- bundle :install, :artifice => "compact_index_api_missing"
+ bundle! :install, :artifice => "compact_index_api_missing"
should_be_installed "foo 1.0"
end
@@ -340,7 +340,7 @@ describe "compact index api" do
gem "back_deps"
G
- bundle :install, :artifice => "compact_index_extra"
+ bundle! :install, :artifice => "compact_index_extra"
bundle "install --deployment", :artifice => "compact_index_extra"
should_be_installed "back_deps 1.0"
@@ -353,7 +353,7 @@ describe "compact index api" do
gem "bundler_dep"
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
expect(out).to include("Fetching gem metadata from #{source_uri}")
end
@@ -365,7 +365,7 @@ describe "compact index api" do
source "#{source_uri}"
gem "rails"
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
should_be_installed "rails 2.3.2"
end
@@ -409,7 +409,7 @@ describe "compact index api" do
gem 'rack-obama'
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
expect(out).to include("Post-install message from rack:")
end
@@ -419,7 +419,7 @@ describe "compact index api" do
gem 'rack_middleware'
G
- bundle :install, :artifice => "compact_index"
+ bundle! :install, :artifice => "compact_index"
expect(out).to include("Post-install message from rack:")
expect(out).to include("Rack's post install message")
end
@@ -441,7 +441,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :artifice => "compact_index_basic_authentication"
+ bundle! :install, :artifice => "compact_index_basic_authentication"
expect(out).not_to include("#{user}:#{password}")
should_be_installed "rack 1.0.0"
end
@@ -452,7 +452,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :artifice => "endopint_marshal_fail_basic_authentication"
+ bundle! :install, :artifice => "endopint_marshal_fail_basic_authentication"
expect(out).not_to include("#{user}:#{password}")
should_be_installed "rack 1.0.0"
end
@@ -474,7 +474,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :artifice => "compact_index_basic_authentication"
+ bundle! :install, :artifice => "compact_index_basic_authentication"
expect(out).to include("Warning: the gem 'rack' was found in multiple sources.")
expect(out).not_to include("#{user}:#{password}")
should_be_installed "rack 1.0.0"
@@ -486,7 +486,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :artifice => "compact_index_creds_diff_host"
+ bundle! :install, :artifice => "compact_index_creds_diff_host"
should_be_installed "rack 1.0.0"
end
@@ -501,7 +501,7 @@ describe "compact index api" do
it "reads authentication details by host name from bundle config" do
bundle "config #{source_hostname} #{user}:#{password}"
- bundle :install, :artifice => "compact_index_strict_basic_authentication"
+ bundle! :install, :artifice => "compact_index_strict_basic_authentication"
expect(out).to include("Fetching gem metadata from #{source_uri}")
should_be_installed "rack 1.0.0"
@@ -511,7 +511,7 @@ describe "compact index api" do
# The trailing slash is necessary here; Fetcher canonicalizes the URI.
bundle "config #{source_uri}/ #{user}:#{password}"
- bundle :install, :artifice => "compact_index_strict_basic_authentication"
+ bundle! :install, :artifice => "compact_index_strict_basic_authentication"
expect(out).to include("Fetching gem metadata from #{source_uri}")
should_be_installed "rack 1.0.0"
@@ -519,7 +519,7 @@ describe "compact index api" do
it "should use the API" do
bundle "config #{source_hostname} #{user}:#{password}"
- bundle :install, :artifice => "compact_index_strict_basic_authentication"
+ bundle! :install, :artifice => "compact_index_strict_basic_authentication"
expect(out).to include("Fetching gem metadata from #{source_uri}")
should_be_installed "rack 1.0.0"
end
@@ -532,7 +532,7 @@ describe "compact index api" do
bundle "config #{source_hostname} otheruser:wrong"
- bundle :install, :artifice => "compact_index_strict_basic_authentication"
+ bundle! :install, :artifice => "compact_index_strict_basic_authentication"
should_be_installed "rack 1.0.0"
end
@@ -558,7 +558,7 @@ describe "compact index api" do
gem "rack"
G
- bundle :install, :artifice => "compact_index_basic_authentication"
+ bundle! :install, :artifice => "compact_index_basic_authentication"
should_be_installed "rack 1.0.0"
end
end
@@ -625,9 +625,7 @@ describe "compact index api" do
gem 'rack'
G
- bundle "install", :artifice => "compact_index_forbidden"
-
- expect(exitstatus).to eq(0) if exitstatus
+ bundle! :install, :artifice => "compact_index_forbidden"
end
end
end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 09ef6e2945..182f7b9bad 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -17,6 +17,20 @@ module Spec
Bundler.send(:remove_instance_variable, :@settings) if Bundler.send(:instance_variable_defined?, :@settings)
end
+ def self.bang(method)
+ define_method("#{method}!") do |*args, &blk|
+ send(method, *args, &blk).tap do
+ if exitstatus && exitstatus != 0
+ error = out + "\n" + err
+ error.strip!
+ raise RuntimeError,
+ "Invoking #{method}!(#{args.map(&:inspect).join(", ")}) failed:\n#{error}",
+ caller.drop_while {|bt| bt.start_with?(__FILE__) }
+ end
+ end
+ end
+ end
+
attr_reader :out, :err, :exitstatus
def in_app_root(&blk)
@@ -39,6 +53,7 @@ module Spec
setup = "require 'rubygems' ; require 'bundler' ; Bundler.setup(#{groups})\n"
@out = ruby(setup + cmd, :expect_err => expect_err, :env => env)
end
+ bang :run
def load_error_run(ruby, name, *args)
cmd = <<-RUBY
@@ -85,6 +100,7 @@ module Spec
cmd = "#{env} #{sudo} #{Gem.ruby} -I#{lib}:#{spec} #{requires_str} #{bundle_bin} #{cmd}#{args}"
sys_exec(cmd, expect_err) {|i| yield i if block_given? }
end
+ bang :bundle
def bundle_ruby(options = {})
expect_err = options.delete(:expect_err)
@@ -110,6 +126,7 @@ module Spec
lib_option = options[:no_lib] ? "" : " -I#{lib}"
sys_exec(%(#{env}#{Gem.ruby}#{lib_option} -e "#{ruby}"), expect_err)
end
+ bang :ruby
def load_error_ruby(ruby, name, opts = {})
cmd = <<-R
@@ -149,6 +166,7 @@ module Spec
puts @err unless expect_err || @err.empty? || !$show_err
@out
end
+ bang :sys_exec
def config(config = nil, path = bundled_app(".bundle/config"))
return YAML.load_file(path) unless config
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
index 6c585ddae4..58babf2ceb 100644
--- a/spec/support/matchers.rb
+++ b/spec/support/matchers.rb
@@ -31,8 +31,9 @@ module Spec
names.each do |name|
name, version, platform = name.split(/\s+/)
version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name)
- run "require '#{name}.rb'; puts #{version_const}", *groups
- actual_version, actual_platform = out.split(/\s+/)
+ run! "require '#{name}.rb'; puts #{version_const}", *groups
+ expect(out).not_to be_empty, "#{name} is not installed"
+ actual_version, actual_platform = out.split(/\s+/, 2)
expect(Gem::Version.new(actual_version)).to eq(Gem::Version.new(version))
expect(actual_platform).to eq(platform)
end
@@ -44,7 +45,7 @@ module Spec
opts = names.last.is_a?(Hash) ? names.pop : {}
groups = Array(opts[:groups]) || []
names.each do |name|
- name, version = name.split(/\s+/)
+ name, version = name.split(/\s+/, 2)
run <<-R, *(groups + [opts])
begin
require '#{name}'