From cc51cfabfd0592dd49d4a8ad4bc78e0520128e72 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 2 Feb 2021 20:23:14 +0900 Subject: Merge Bundler-2.2.7 --- spec/bundler/bundler/cli_spec.rb | 4 +- spec/bundler/bundler/gem_helper_spec.rb | 8 ++ spec/bundler/cache/git_spec.rb | 2 +- spec/bundler/commands/cache_spec.rb | 13 ++ spec/bundler/commands/update_spec.rb | 13 +- spec/bundler/install/bundler_spec.rb | 70 ++++++---- spec/bundler/install/gemfile/git_spec.rb | 18 +++ spec/bundler/install/gems/resolving_spec.rb | 9 +- spec/bundler/install/gems/standalone_spec.rb | 24 ++++ spec/bundler/realworld/double_check_spec.rb | 2 +- spec/bundler/realworld/edgecases_spec.rb | 199 +++++++++++++++++++++++++-- spec/bundler/realworld/parallel_spec.rb | 2 +- spec/bundler/runtime/platform_spec.rb | 18 ++- spec/bundler/spec_helper.rb | 3 +- spec/bundler/support/helpers.rb | 2 - spec/bundler/support/sometimes.rb | 57 -------- 16 files changed, 326 insertions(+), 118 deletions(-) delete mode 100644 spec/bundler/support/sometimes.rb (limited to 'spec') diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index ccf957d6df..e49066f7dc 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -138,12 +138,12 @@ RSpec.describe "bundle executable" do it "doesn't print defaults" do install_gemfile "", :verbose => true - expect(out).to start_with("Running `bundle install --retry 0 --verbose` with bundler #{Bundler::VERSION}") + expect(out).to start_with("Running `bundle install --verbose` with bundler #{Bundler::VERSION}") end it "doesn't print defaults" do install_gemfile "", :verbose => true - expect(out).to start_with("Running `bundle install --retry 0 --verbose` with bundler #{Bundler::VERSION}") + expect(out).to start_with("Running `bundle install --verbose` with bundler #{Bundler::VERSION}") end end diff --git a/spec/bundler/bundler/gem_helper_spec.rb b/spec/bundler/bundler/gem_helper_spec.rb index 30befdf40c..7eb334356d 100644 --- a/spec/bundler/bundler/gem_helper_spec.rb +++ b/spec/bundler/bundler/gem_helper_spec.rb @@ -266,6 +266,14 @@ RSpec.describe Bundler::GemHelper do Rake.application["release"].invoke end + + it "also works with releasing from a branch not yet pushed" do + sys_exec("git checkout -b module_function", :dir => app_path) + + expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) + + Rake.application["release"].invoke + end end context "on releasing with a custom tag prefix" do diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb index 97d73907db..25f12a9e87 100644 --- a/spec/bundler/cache/git_spec.rb +++ b/spec/bundler/cache/git_spec.rb @@ -200,7 +200,7 @@ RSpec.describe "bundle cache with git" do gem "foo", :git => '#{lib_path("foo-1.0")}' G bundle "config set cache_all true" - bundle :cache, "all-platforms" => true, :install => false, :path => "./vendor/cache" + bundle :cache, "all-platforms" => true, :install => false simulate_new_machine with_path_as "" do diff --git a/spec/bundler/commands/cache_spec.rb b/spec/bundler/commands/cache_spec.rb index 173389c068..df5f01bc45 100644 --- a/spec/bundler/commands/cache_spec.rb +++ b/spec/bundler/commands/cache_spec.rb @@ -1,6 +1,19 @@ # frozen_string_literal: true RSpec.describe "bundle cache" do + it "doesn't update the cache multiple times, even if it already exists" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + + bundle :cache + expect(out).to include("Updating files in vendor/cache").once + + bundle :cache + expect(out).to include("Updating files in vendor/cache").once + end + context "with --gemfile" do it "finds the gemfile" do gemfile bundled_app("NotGemfile"), <<-G diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index b8de6507f6..521c175711 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -651,6 +651,8 @@ RSpec.describe "bundle update when a gem depends on a newer version of bundler" build_gem "rails", "3.0.1" do |s| s.add_dependency "bundler", Bundler::VERSION.succ end + + build_gem "bundler", Bundler::VERSION.succ end gemfile <<-G @@ -659,18 +661,11 @@ RSpec.describe "bundle update when a gem depends on a newer version of bundler" G end - it "should explain that bundler conflicted", :bundler => "< 3" do + it "should explain that bundler conflicted and how to resolve the conflict" do bundle "update", :all => true, :raise_on_error => false expect(last_command.stdboth).not_to match(/in snapshot/i) expect(err).to match(/current Bundler version/i). - and match(/perhaps you need to update bundler/i) - end - - it "should warn that the newer version of Bundler would conflict", :bundler => "3" do - bundle "update", :all => true - expect(err).to include("rails (3.0.1) has dependency bundler"). - and include("so the dependency is being ignored") - expect(the_bundle).to include_gem "rails 3.0.1" + and match(/Install the necessary version with `gem install bundler:#{Bundler::VERSION.succ}`/i) end end diff --git a/spec/bundler/install/bundler_spec.rb b/spec/bundler/install/bundler_spec.rb index af1ff7225a..9445be66f1 100644 --- a/spec/bundler/install/bundler_spec.rb +++ b/spec/bundler/install/bundler_spec.rb @@ -29,9 +29,49 @@ RSpec.describe "bundle install" do expect(the_bundle).not_to include_gems "bundler #{Bundler::VERSION}" end - it "causes a conflict if explicitly requesting a different version" do - bundle "config set force_ruby_platform true" + it "causes a conflict if explicitly requesting a different version of bundler" do + install_gemfile <<-G, :raise_on_error => false + source "#{file_uri_for(gem_repo2)}" + gem "rails", "3.0" + gem "bundler", "0.9.1" + G + + nice_error = <<-E.strip.gsub(/^ {8}/, "") + Bundler could not find compatible versions for gem "bundler": + In Gemfile: + bundler (= 0.9.1) + + Current Bundler version: + bundler (#{Bundler::VERSION}) + + Your bundle requires a different version of Bundler than the one you're running. + Install the necessary version with `gem install bundler:0.9.1` and rerun bundler using `bundle _0.9.1_ install` + E + expect(err).to include(nice_error) + end + + it "causes a conflict if explicitly requesting a non matching requirement on bundler" do + install_gemfile <<-G, :raise_on_error => false + source "#{file_uri_for(gem_repo2)}" + gem "rails", "3.0" + gem "bundler", "~> 0.8" + G + + nice_error = <<-E.strip.gsub(/^ {8}/, "") + Bundler could not find compatible versions for gem "bundler": + In Gemfile: + bundler (~> 0.8) + + Current Bundler version: + bundler (#{Bundler::VERSION}) + + Your bundle requires a different version of Bundler than the one you're running. + Install the necessary version with `gem install bundler:0.9.1` and rerun bundler using `bundle _0.9.1_ install` + E + expect(err).to include(nice_error) + end + it "causes a conflict if explicitly requesting a version of bundler that doesn't exist" do install_gemfile <<-G, :raise_on_error => false source "#{file_uri_for(gem_repo2)}" gem "rails", "3.0" @@ -45,10 +85,8 @@ RSpec.describe "bundle install" do Current Bundler version: bundler (#{Bundler::VERSION}) - This Gemfile requires a different version of Bundler. - Perhaps you need to update Bundler by running `gem install bundler`? - Could not find gem 'bundler (= 0.9.2)' in any + Your bundle requires a different version of Bundler than the one you're running, and that version could not be found. E expect(err).to include(nice_error) end @@ -197,27 +235,5 @@ RSpec.describe "bundle install" do bundle "check" expect(out).to include("The Gemfile's dependencies are satisfied") end - - context "with allow_bundler_dependency_conflicts set" do - before { bundle "config set allow_bundler_dependency_conflicts true" } - - it "are forced to the current bundler version with warnings when no compatible version is found" do - build_repo4 do - build_gem "requires_nonexistant_bundler" do |s| - s.add_runtime_dependency "bundler", "99.99.99.99" - end - end - - install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem "requires_nonexistant_bundler" - G - - expect(err).to include "requires_nonexistant_bundler (1.0) has dependency bundler (= 99.99.99.99), " \ - "which is unsatisfied by the current bundler version #{Bundler::VERSION}, so the dependency is being ignored" - - expect(the_bundle).to include_gems "bundler #{Bundler::VERSION}", "requires_nonexistant_bundler 1.0" - end - end end end diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 7850fad8d0..c0181a8788 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -598,6 +598,24 @@ RSpec.describe "bundle install with git sources" do bundle :install, :raise_on_error => false expect(err).to match(/The Gemfile lock is pointing to revision \w+/) end + + it "does not explode on invalid revision on install" do + build_git "rack", "0.8" + + build_git "rack", "0.8", :path => lib_path("local-rack") do |s| + s.write "lib/rack.rb", "puts :LOCAL" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master" + G + + bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set disable_local_revision_check true) + bundle :install + expect(out).to match(/Bundle complete!/) + end end describe "specified inline" do diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index 8ea61afca2..2d0ac5a805 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -145,7 +145,7 @@ RSpec.describe "bundle install with install-time dependencies" do bundle :install, :env => { "DEBUG_RESOLVER_TREE" => "1", "DEBUG" => "1" } activated_groups = if local_platforms.any? - "net_b (1.0) (#{local_platforms.join(", ")})" + "net_b (1.0) (ruby), net_b (1.0) (#{local_platforms.join(", ")})" else "net_b (1.0) (ruby)" end @@ -242,7 +242,6 @@ RSpec.describe "bundle install with install-time dependencies" do let(:ruby_requirement) { %("#{RUBY_VERSION}") } let(:error_message_requirement) { "~> #{RUBY_VERSION}.0" } - let(:error_message_platform) { Bundler.local_platform } shared_examples_for "ruby version conflicts" do it "raises an error during resolution" do @@ -259,10 +258,10 @@ RSpec.describe "bundle install with install-time dependencies" do nice_error = strip_whitespace(<<-E).strip Bundler found conflicting requirements for the Ruby\0 version: In Gemfile: - Ruby\0 (#{error_message_requirement}) #{error_message_platform} + Ruby\0 (#{error_message_requirement}) - require_ruby #{error_message_platform} was resolved to 1.0, which depends on - Ruby\0 (> 9000) #{error_message_platform} + require_ruby was resolved to 1.0, which depends on + Ruby\0 (> 9000) Ruby\0 (> 9000), which is required by gem 'require_ruby', is not available in the local ruby installation E diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index 02452f1ef6..90134865e1 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -7,6 +7,12 @@ RSpec.shared_examples "bundle install --standalone" do expect(the_bundle).to include_gems(*args) end + it "still makes system gems unavailable to normal bundler" do + system_gems "rack-1.0.0" + + expect(the_bundle).to_not include_gems("rack") + end + it "generates a bundle/bundler/setup.rb" do expect(bundled_app("bundle/bundler/setup.rb")).to exist end @@ -26,6 +32,24 @@ RSpec.shared_examples "bundle install --standalone" do expect(out).to eq(expected_gems.values.join("\n")) end + it "makes system gems unavailable without bundler" do + system_gems "rack-1.0.0" + + testrb = String.new <<-RUBY + $:.unshift File.expand_path("bundle") + require "bundler/setup" + + begin + require "rack" + rescue LoadError + puts "LoadError" + end + RUBY + ruby testrb + + expect(out).to eq("LoadError") + end + it "works on a different system" do begin FileUtils.mv(bundled_app, "#{bundled_app}2") diff --git a/spec/bundler/realworld/double_check_spec.rb b/spec/bundler/realworld/double_check_spec.rb index 0a8f5e4d9e..07697f080e 100644 --- a/spec/bundler/realworld/double_check_spec.rb +++ b/spec/bundler/realworld/double_check_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "double checking sources", :realworld => true, :sometimes => true do +RSpec.describe "double checking sources", :realworld => true do it "finds already-installed gems" do create_file("rails.gemspec", <<-RUBY) Gem::Specification.new do |s| diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb index eb38613742..1925f76c06 100644 --- a/spec/bundler/realworld/edgecases_spec.rb +++ b/spec/bundler/realworld/edgecases_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do +RSpec.describe "real world edgecases", :realworld => true do def rubygems_version(name, requirement) ruby <<-RUBY require "#{spec_dir}/support/artifice/vcr" @@ -64,6 +64,8 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do it "is able to update a top-level dependency when there is a conflict on a shared transitive child" do # from https://github.com/rubygems/bundler/issues/5031 + system_gems "bundler-2.99.0" + gemfile <<-G source "https://rubygems.org" gem 'rails', '~> 4.2.7.1' @@ -189,7 +191,7 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do rails (~> 4.2.7.1) L - bundle "lock --update paperclip" + bundle "lock --update paperclip", :env => { "BUNDLER_VERSION" => "2.99.0" } expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0")) end @@ -448,12 +450,13 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do end G - bundle :lock, :env => { "DEBUG_RESOLVER" => "1" } - if Bundler.feature_flag.bundler_3_mode? - expect(out).to include("BUNDLER: Finished resolution (1336 steps)") + # Conflicts on bundler version, so fails earlier + bundle :lock, :env => { "DEBUG_RESOLVER" => "1" }, :raise_on_error => false + expect(out).to display_total_steps_of(435) else - expect(out).to include("BUNDLER: Finished resolution (1395 steps)") + bundle :lock, :env => { "DEBUG_RESOLVER" => "1" } + expect(out).to display_total_steps_of(1025) end end @@ -477,9 +480,189 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do bundle :lock, :env => { "DEBUG_RESOLVER" => "1" } if Bundler.feature_flag.bundler_3_mode? - expect(out).to include("BUNDLER: Finished resolution (366 steps)") + expect(out).to display_total_steps_of(890) + else + expect(out).to display_total_steps_of(891) + end + end + + it "doesn't hang on nix gemfile" do + skip "Only for ruby 3.0.0" if RUBY_VERSION != "3.0.0" + + gemfile <<~G + source "https://rubygems.org" do + gem "addressable" + gem "atk" + gem "awesome_print" + gem "bacon" + gem "byebug" + gem "cairo" + gem "cairo-gobject" + gem "camping" + gem "charlock_holmes" + gem "cld3" + gem "cocoapods" + gem "cocoapods-acknowledgements" + gem "cocoapods-art" + gem "cocoapods-bin" + gem "cocoapods-browser" + gem "cocoapods-bugsnag" + gem "cocoapods-check" + gem "cocoapods-clean" + gem "cocoapods-clean_build_phases_scripts" + gem "cocoapods-core" + gem "cocoapods-coverage" + gem "cocoapods-deintegrate" + gem "cocoapods-dependencies" + gem "cocoapods-deploy" + gem "cocoapods-downloader" + gem "cocoapods-expert-difficulty" + gem "cocoapods-fix-react-native" + gem "cocoapods-generate" + gem "cocoapods-git_url_rewriter" + gem "cocoapods-keys" + gem "cocoapods-no-dev-schemes" + gem "cocoapods-open" + gem "cocoapods-packager" + gem "cocoapods-playgrounds" + gem "cocoapods-plugins" + gem "cocoapods-prune-localizations" + gem "cocoapods-rome" + gem "cocoapods-search" + gem "cocoapods-sorted-search" + gem "cocoapods-static-swift-framework" + gem "cocoapods-stats" + gem "cocoapods-tdfire-binary" + gem "cocoapods-testing" + gem "cocoapods-trunk" + gem "cocoapods-try" + gem "cocoapods-try-release-fix" + gem "cocoapods-update-if-you-dare" + gem "cocoapods-whitelist" + gem "cocoapods-wholemodule" + gem "coderay" + gem "concurrent-ruby" + gem "curb" + gem "curses" + gem "daemons" + gem "dep-selector-libgecode" + gem "digest-sha3" + gem "domain_name" + gem "do_sqlite3" + gem "ethon" + gem "eventmachine" + gem "excon" + gem "faraday" + gem "ffi" + gem "ffi-rzmq-core" + gem "fog-dnsimple" + gem "gdk_pixbuf2" + gem "gio2" + gem "gitlab-markup" + gem "glib2" + gem "gpgme" + gem "gtk2" + gem "hashie" + gem "highline" + gem "hike" + gem "hitimes" + gem "hpricot" + gem "httpclient" + gem "http-cookie" + gem "iconv" + gem "idn-ruby" + gem "jbuilder" + gem "jekyll" + gem "jmespath" + gem "jwt" + gem "libv8" + gem "libxml-ruby" + gem "magic" + gem "markaby" + gem "method_source" + gem "mini_magick" + gem "msgpack" + gem "mysql2" + gem "ncursesw" + gem "netrc" + gem "net-scp" + gem "net-ssh" + gem "nokogiri" + gem "opus-ruby" + gem "ovirt-engine-sdk" + gem "pango" + gem "patron" + gem "pcaprub" + gem "pg" + gem "pry" + gem "pry-byebug" + gem "pry-doc" + gem "public_suffix" + gem "puma" + gem "rails" + gem "rainbow" + gem "rbnacl" + gem "rb-readline" + gem "re2" + gem "redis" + gem "redis-rack" + gem "rest-client" + gem "rmagick" + gem "rpam2" + gem "rspec" + gem "rubocop" + gem "rubocop-performance" + gem "ruby-libvirt" + gem "ruby-lxc" + gem "ruby-progressbar" + gem "ruby-terminfo" + gem "ruby-vips" + gem "rubyzip" + gem "rugged" + gem "sassc" + gem "scrypt" + gem "semian" + gem "sequel" + gem "sequel_pg" + gem "simplecov" + gem "sinatra" + gem "slop" + gem "snappy" + gem "sqlite3" + gem "taglib-ruby" + gem "thrift" + gem "tilt" + gem "tiny_tds" + gem "treetop" + gem "typhoeus" + gem "tzinfo" + gem "unf_ext" + gem "uuid4r" + gem "whois" + gem "zookeeper" + end + G + + bundle :lock, :env => { "DEBUG_RESOLVER" => "1" } + + if Bundler.feature_flag.bundler_3_mode? + expect(out).to display_total_steps_of(1874) else - expect(out).to include("BUNDLER: Finished resolution (372 steps)") + expect(out).to display_total_steps_of(1922) + end + end + + private + + RSpec::Matchers.define :display_total_steps_of do |expected_steps| + match do |out| + out.include?("BUNDLER: Finished resolution (#{expected_steps} steps)") + end + + failure_message do |out| + actual_steps = out.scan(/BUNDLER: Finished resolution \((\d+) steps\)/).first.first + + "Expected resolution to finish in #{expected_steps} steps, but took #{actual_steps}" end end end diff --git a/spec/bundler/realworld/parallel_spec.rb b/spec/bundler/realworld/parallel_spec.rb index 2a5154ffbf..97c0e0cab4 100644 --- a/spec/bundler/realworld/parallel_spec.rb +++ b/spec/bundler/realworld/parallel_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "parallel", :realworld => true, :sometimes => true do +RSpec.describe "parallel", :realworld => true do it "installs" do gemfile <<-G source "https://rubygems.org" diff --git a/spec/bundler/runtime/platform_spec.rb b/spec/bundler/runtime/platform_spec.rb index 215ba8628f..79ca69a810 100644 --- a/spec/bundler/runtime/platform_spec.rb +++ b/spec/bundler/runtime/platform_spec.rb @@ -84,9 +84,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 x86-darwin-100" end - it "allows specifying only-ruby-platform" do - simulate_platform "java" - + it "allows specifying only-ruby-platform on jruby", :jruby do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "nokogiri" @@ -100,6 +98,20 @@ RSpec.describe "Bundler.setup with multi platform stuff" do expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 RUBY" end + it "allows specifying only-ruby-platform" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "nokogiri" + gem "platform_specific" + G + + bundle "config set force_ruby_platform true" + + bundle "install" + + expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 RUBY" + end + it "allows specifying only-ruby-platform on windows with dependency platforms" do simulate_windows do install_gemfile <<-G diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index a259100b2a..68d8537715 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -22,7 +22,6 @@ require_relative "support/indexes" require_relative "support/matchers" require_relative "support/permissions" require_relative "support/platforms" -require_relative "support/sometimes" require_relative "support/sudo" $debug = false @@ -104,7 +103,7 @@ RSpec.configure do |config| all_output = all_commands_output if example.exception && !all_output.empty? - message = example.exception.message + all_output + message = all_output + "\n" + example.exception.message (class << example.exception; self; end).send(:define_method, :message) do message end diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index c4018eb818..a7cc1ce810 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -275,14 +275,12 @@ module Spec def install_gemfile(*args) gemfile(*args) opts = args.last.is_a?(Hash) ? args.last : {} - opts[:retry] ||= 0 bundle :install, opts end def lock_gemfile(*args) gemfile(*args) opts = args.last.is_a?(Hash) ? args.last : {} - opts[:retry] ||= 0 bundle :lock, opts end diff --git a/spec/bundler/support/sometimes.rb b/spec/bundler/support/sometimes.rb deleted file mode 100644 index 65a95ed59c..0000000000 --- a/spec/bundler/support/sometimes.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -module Sometimes - def run_with_retries(example_to_run, retries) - example = RSpec.current_example - example.metadata[:retries] ||= retries - - retries.times do |t| - example.metadata[:retried] = t + 1 - example.instance_variable_set(:@exception, nil) - example_to_run.run - break unless example.exception - end - - if e = example.exception - new_exception = e.exception(e.message + "[Retried #{retries} times]") - new_exception.set_backtrace e.backtrace - example.instance_variable_set(:@exception, new_exception) - end - end -end - -RSpec.configure do |config| - config.include Sometimes - config.alias_example_to :sometimes, :sometimes => true - config.add_setting :sometimes_retry_count, :default => 5 - - config.around(:each, :sometimes => true) do |example| - retries = example.metadata[:retries] || RSpec.configuration.sometimes_retry_count - run_with_retries(example, retries) - end - - config.after(:suite) do - message = proc do |color, text| - colored = RSpec::Core::Formatters::ConsoleCodes.wrap(text, color) - notification = RSpec::Core::Notifications::MessageNotification.new(colored) - formatter = RSpec.configuration.formatters.first - formatter.message(notification) if formatter.respond_to?(:message) - end - - retried_examples = RSpec.world.example_groups.map do |g| - g.descendants.map do |d| - d.filtered_examples.select do |e| - e.metadata[:sometimes] && e.metadata.fetch(:retried, 1) > 1 - end - end - end.flatten - - message.call(retried_examples.empty? ? :green : :yellow, "\n\nRetried examples: #{retried_examples.count}") - - retried_examples.each do |e| - message.call(:cyan, " #{e.full_description}") - path = RSpec::Core::Metadata.relative_path(e.location) - message.call(:cyan, " [#{e.metadata[:retried]}/#{e.metadata[:retries]}] " + path) - end - end -end -- cgit v1.2.3