diff options
author | Andre Arko <andre@arko.net> | 2015-07-29 21:41:18 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2015-07-29 21:41:30 -0700 |
commit | 24392e20fe67558d6ffaf8021ed8ddca12df6c2f (patch) | |
tree | 5ea834734d12211dcbf92303ecf1076be28097d4 | |
parent | dfdfd08a609ae07466587b9583bcdfb186ae101a (diff) | |
download | bundler-24392e20fe67558d6ffaf8021ed8ddca12df6c2f.tar.gz |
retry tests that hit rubygems.org up to 5 times
-rw-r--r-- | spec/realworld/edgecases_spec.rb | 2 | ||||
-rw-r--r-- | spec/realworld/parallel_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/sometimes.rb | 52 |
3 files changed, 54 insertions, 2 deletions
diff --git a/spec/realworld/edgecases_spec.rb b/spec/realworld/edgecases_spec.rb index 028c30c293..008eab28d2 100644 --- a/spec/realworld/edgecases_spec.rb +++ b/spec/realworld/edgecases_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe "real world edgecases", :realworld => true do +describe "real world edgecases", :realworld => true, :sometimes => true do # there is no rbx-relative-require gem that will install on 1.9 it "ignores extra gems with bad platforms", :ruby => "~> 1.8.7" do install_gemfile <<-G diff --git a/spec/realworld/parallel_spec.rb b/spec/realworld/parallel_spec.rb index f168a0657e..7154e26dc9 100644 --- a/spec/realworld/parallel_spec.rb +++ b/spec/realworld/parallel_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe "parallel", :realworld => true do +describe "parallel", :realworld => true, :sometimes => true do it "installs" do gemfile <<-G source "https://rubygems.org" diff --git a/spec/support/sometimes.rb b/spec/support/sometimes.rb new file mode 100644 index 0000000000..1655abecc8 --- /dev/null +++ b/spec/support/sometimes.rb @@ -0,0 +1,52 @@ +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 + formatter = + message = lambda {|color, text| + colored = RSpec::Core::Formatters::ConsoleCodes.wrap(text, color) + notification = RSpec::Core::Notifications::MessageNotification.new(colored) + RSpec.configuration.formatters.first.message(notification) + } + 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}") + unless retried_examples.empty? + 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 +end |