diff options
author | Bundlerbot <bot@bundler.io> | 2019-09-17 07:09:14 +0000 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-11-07 16:41:28 +0100 |
commit | c86b21c24424eaa26c3fc073834594c1f3d31cc3 (patch) | |
tree | d1c5193eb1128b5941b270c06fdfc2e0d4931059 /spec/support | |
parent | b0dcf5f7b2a23372128ec0caf1ae888cb8630749 (diff) | |
download | bundler-c86b21c24424eaa26c3fc073834594c1f3d31cc3.tar.gz |
Merge #7359
7359: Spec simplifications r=indirect a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that while working on #7296 and investigating why CI was failing there, I ended up adding several simplifications that are not necessarily related to that PR. In order to make that PR more digestable, I extracted those simplifications and improvements to this separate PR.
### Why did you choose this fix out of the possible options?
I chose this fix because it makes our dev and test environment better and simpler with some little tweaks.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
(cherry picked from commit 892b18be786ab891b2602f2126d9b033f1f591b1)
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/command_execution.rb | 5 | ||||
-rw-r--r-- | spec/support/filters.rb | 45 | ||||
-rw-r--r-- | spec/support/helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/matchers.rb | 5 | ||||
-rw-r--r-- | spec/support/requirement_checker.rb | 19 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 37 | ||||
-rw-r--r-- | spec/support/the_bundle.rb | 4 |
7 files changed, 72 insertions, 47 deletions
diff --git a/spec/support/command_execution.rb b/spec/support/command_execution.rb index cec531d6c3..b3c289979f 100644 --- a/spec/support/command_execution.rb +++ b/spec/support/command_execution.rb @@ -1,12 +1,7 @@ # frozen_string_literal: true -require "support/helpers" -require "support/path" - module Spec CommandExecution = Struct.new(:command, :working_directory, :exitstatus, :stdout, :stderr) do - include RSpec::Matchers::Composable - def to_s c = Shellwords.shellsplit(command.strip).map {|s| s.include?("\n") ? " \\\n <<EOS\n#{s.gsub(/^/, " ").chomp}\nEOS" : Shellwords.shellescape(s) } c = c.reduce("") do |acc, elem| diff --git a/spec/support/filters.rb b/spec/support/filters.rb new file mode 100644 index 0000000000..4ce6648cdc --- /dev/null +++ b/spec/support/filters.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require_relative "sudo" + +class RequirementChecker < Proc + def self.against(present) + provided = Gem::Version.new(present) + + new do |required| + !Gem::Requirement.new(required).satisfied_by?(provided) + end.tap do |checker| + checker.provided = provided + end + end + + attr_accessor :provided + + def inspect + "\"!= #{provided}\"" + end +end + +RSpec.configure do |config| + if ENV["BUNDLER_SUDO_TESTS"] && Spec::Sudo.present? + config.filter_run :sudo => true + else + config.filter_run_excluding :sudo => true + end + + if ENV["BUNDLER_REALWORLD_TESTS"] + config.filter_run :realworld => true + else + config.filter_run_excluding :realworld => true + end + + git_version = Bundler::Source::Git::GitProxy.new(nil, nil, nil).version + + config.filter_run_excluding :rubygems => RequirementChecker.against(Gem::VERSION) + config.filter_run_excluding :git => RequirementChecker.against(git_version) + config.filter_run_excluding :bundler => RequirementChecker.against(Bundler::VERSION.split(".")[0]) + config.filter_run_excluding :ruby_repo => !ENV["GEM_COMMAND"].nil? + config.filter_run_excluding :no_color_tty => Gem.win_platform? || !ENV["GITHUB_ACTION"].nil? + + config.filter_run_when_matching :focus unless ENV["CI"] +end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 0c05789946..b5617d399f 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -513,10 +513,6 @@ module Spec Dir.chdir(path) { `git rev-parse HEAD`.strip } end - def capture_output - capture(:stdout) - end - def with_read_only(pattern) chmod = lambda do |dirmode, filemode| lambda do |f| diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index b0493801e8..69d3be4a3d 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require "forwardable" -require "support/the_bundle" +require_relative "the_bundle" + module Spec module Matchers extend RSpec::Matchers @@ -170,7 +171,7 @@ module Spec end R rescue StandardError => e - next "checking for #{name} failed:\n#{e}" + next "checking for #{name} failed:\n#{e}\n#{e.backtrace.join("\n")}" end next if out == "WIN" next "expected #{name} to not be installed, but it was" if version.nil? diff --git a/spec/support/requirement_checker.rb b/spec/support/requirement_checker.rb deleted file mode 100644 index e6bd0eb50d..0000000000 --- a/spec/support/requirement_checker.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RequirementChecker < Proc - def self.against(present) - provided = Gem::Version.new(present) - - new do |required| - !Gem::Requirement.new(required).satisfied_by?(provided) - end.tap do |checker| - checker.provided = provided - end - end - - attr_accessor :provided - - def inspect - "\"!= #{provided}\"" - end -end diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index faa474a917..1a9549d2b5 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "rubygems/user_interaction" require_relative "path" require "fileutils" @@ -29,7 +28,9 @@ module Spec "ruby-graphviz" => ">= 0.a", }.freeze - def self.dev_setup + extend self + + def dev_setup deps = DEV_DEPS # JRuby can't build ronn, so we skip that @@ -38,22 +39,16 @@ module Spec install_gems(deps) end - def self.gem_load(gem_name, bin_container) - gem_activate(gem_name) - load Gem.bin_path(gem_name, bin_container) - end - - def self.gem_activate(gem_name) - gem_requirement = DEV_DEPS[gem_name] - gem gem_name, gem_requirement + def gem_load(gem_name, bin_container) + gem_load_and_activate(gem_name, bin_container) end - def self.gem_require(gem_name) + def gem_require(gem_name) gem_activate(gem_name) require gem_name end - def self.setup + def setup Gem.clear_paths ENV["BUNDLE_PATH"] = nil @@ -74,17 +69,31 @@ module Spec ENV["HOME"] = Path.home.to_s ENV["TMPDIR"] = Path.tmpdir.to_s + require "rubygems/user_interaction" Gem::DefaultUserInteraction.ui = Gem::SilentUI.new end - def self.install_gems(gems) + private + + def gem_load_and_activate(gem_name, bin_container) + gem_activate(gem_name) + load Gem.bin_path(gem_name, bin_container) + rescue Gem::LoadError => e + abort "We couln't activate #{gem_name} (#{e.requirement}). Run `gem install #{gem_name}:'#{e.requirement}'`" + end + + def gem_activate(gem_name) + gem_requirement = DEV_DEPS[gem_name] + gem gem_name, gem_requirement + end + + def install_gems(gems) reqs, no_reqs = gems.partition {|_, req| !req.nil? && !req.split(" ").empty? } no_reqs.map!(&:first) reqs.map! {|name, req| "'#{name}:#{req}'" } deps = reqs.concat(no_reqs).join(" ") gem = Path.gem_bin cmd = "#{gem} install #{deps} --no-document --conservative" - puts cmd system(cmd) || raise("Installing gems #{deps} for the tests to use failed!") end end diff --git a/spec/support/the_bundle.rb b/spec/support/the_bundle.rb index c994eaae78..f252a4515b 100644 --- a/spec/support/the_bundle.rb +++ b/spec/support/the_bundle.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -require "support/helpers" -require "support/path" +require_relative "path" module Spec class TheBundle - include Spec::Helpers include Spec::Path attr_accessor :bundle_dir |