diff options
author | The Bundler Bot <bot@bundler.io> | 2016-12-22 10:35:00 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2016-12-22 10:35:00 +0000 |
commit | 607f372d610f6a946a9005a67d4ffd01c48ed2e2 (patch) | |
tree | 197fc9a037e295e1a90d844422fe125433795827 | |
parent | 148816f865c323bbb170d61c211f09c99ca3cbce (diff) | |
parent | 4a6615a027fd17c6fbf7155345a7a77e040f7abc (diff) | |
download | bundler-607f372d610f6a946a9005a67d4ffd01c48ed2e2.tar.gz |
Auto merge of #5209 - bundler:seg-spec-improvements, r=indirect
Random spec improvements
Called "sam has a flight and forgot to run `rake spec:deps`"
-rw-r--r-- | lib/bundler/source.rb | 4 | ||||
-rw-r--r-- | spec/commands/install_spec.rb | 4 | ||||
-rw-r--r-- | spec/support/artifice/fail.rb | 39 | ||||
-rw-r--r-- | spec/support/helpers.rb | 20 |
4 files changed, 41 insertions, 26 deletions
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 9d65d4613b..917e9106e0 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -34,5 +34,9 @@ module Bundler def include?(other) other == self end + + def inspect + "#<#{self.class}:0x#{object_id} #{self}>" + end end end diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index 457fec26cb..0d05766eeb 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -314,14 +314,14 @@ describe "bundle install with gem sources" do end it "gracefully handles error when rubygems server is unavailable" do - install_gemfile <<-G + install_gemfile <<-G, :artifice => nil source "file://#{gem_repo1}" source "http://localhost:9384" gem 'foo' G - bundle :install + bundle :install, :artifice => nil expect(out).to include("Could not fetch specs from http://localhost:9384/") expect(out).not_to include("file://") end diff --git a/spec/support/artifice/fail.rb b/spec/support/artifice/fail.rb index 2ef009c7c8..1059c6df4e 100644 --- a/spec/support/artifice/fail.rb +++ b/spec/support/artifice/fail.rb @@ -1,20 +1,39 @@ # frozen_string_literal: true -require File.expand_path("../../path.rb", __FILE__) +require "net/http" +begin + require "net/https" +rescue LoadError + nil # net/https or openssl +end + +# We can't use artifice here because it uses rack -# Set up pretend http gem server with Artifice -$LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,rack,tilt}-*/lib")].map(&:to_s)) -require "artifice" +module Artifice; end # for < 2.0, Net::HTTP::Persistent::SSLReuse -class Fail - def call(env) - raise(exception(env)) +class Fail < Net::HTTP + # Net::HTTP uses a @newimpl instance variable to decide whether + # to use a legacy implementation. Since we are subclassing + # Net::HTTP, we must set it + @newimpl = true + + def request(req, body = nil, &block) + raise(exception(req)) end - def exception(env) + # Ensure we don't start a connect here + def connect + end + + def exception(req) name = ENV.fetch("BUNDLER_SPEC_EXCEPTION") { "Errno::ENETUNREACH" } const = name.split("::").reduce(Object) {|mod, sym| mod.const_get(sym) } - const.new("host down: Bundler spec artifice fail! #{env["PATH_INFO"]}") + const.new("host down: Bundler spec artifice fail! #{req["PATH_INFO"]}") end end -Artifice.activate_with(Fail.new) + +# Replace Net::HTTP with our failing subclass +::Net.class_eval do + remove_const(:HTTP) + const_set(:HTTP, ::Fail) +end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 3ec5d368b9..3912ad068f 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -84,7 +84,7 @@ module Spec with_sudo = options.delete(:sudo) sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo - options["no-color"] = true unless options.key?("no-color") || cmd.to_s.start_with?("exec", "exe", "ex", "e", "conf") + options["no-color"] = true unless options.key?("no-color") || cmd.to_s =~ /\A(e|ex|exe|exec|conf|confi|config)(\s|\z)/ bundle_bin = options.delete("bundle_bin") || File.expand_path("../../../exe/bundle", __FILE__) @@ -93,7 +93,9 @@ module Spec end requires = options.delete(:requires) || [] - requires << File.expand_path("../artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice) + if artifice = options.delete(:artifice) { "fail" unless RSpec.current_example.metadata[:realworld] } + requires << File.expand_path("../artifice/#{artifice}.rb", __FILE__) + end requires << "support/hax" requires_str = requires.map {|r| "-r#{r}" }.join(" ") @@ -119,18 +121,8 @@ module Spec end def bundle_ruby(options = {}) - options["no-color"] = true unless options.key?("no-color") - - bundle_bin = File.expand_path("../../../exe/bundle_ruby", __FILE__) - - requires = options.delete(:requires) || [] - requires << File.expand_path("../artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice) - requires_str = requires.map {|r| "-r#{r}" }.join(" ") - - env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}' " }.join - cmd = "#{env}#{Gem.ruby} -I#{lib} #{requires_str} #{bundle_bin}" - - sys_exec(cmd) {|i, o, thr| yield i, o, thr if block_given? } + options["bundle_bin"] = File.expand_path("../../../exe/bundle_ruby", __FILE__) + bundle("", options) end def ruby(ruby, options = {}) |