-
-
Save seancribbs/1718985 to your computer and use it in GitHub Desktop.
Revisions
-
Sean Cribbs revised this gist
Feb 2, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def run_with_retries(example_to_run, retries) config.after(:suite) do formatter = RSpec.configuration.formatters.first color = lambda {|tint, msg| formatter.send(tint, msg) } retried_examples = RSpec.world.example_groups.map do |g| g.descendants.map do |d| d.filtered_examples.select {|e| e.metadata[:sometimes] && e.metadata[:retried] > 1 } end -
Sean Cribbs revised this gist
Feb 2, 2012 . 1 changed file with 40 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,46 @@ # Emulates the QuickCheck ?SOMETIMES macro. module Sometimes def run_with_retries(example_to_run, retries) self.example.metadata[:retries] ||= retries retries.times do |t| self.example.metadata[:retried] = t + 1 self.example.instance_variable_set(:@exception, nil) example_to_run.run break unless self.example.exception end if e = self.example.exception new_exception = e.exception(e.message + "[Retried #{retries} times]") new_exception.set_backtrace e.backtrace self.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 => 3 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 = RSpec.configuration.formatters.first color = lambda {|tint, msg| formatter.send(tint, msg) } retried_examples = RSpec.world.example_groups.flat_map do |g| g.descendants.map do |d| d.filtered_examples.select {|e| e.metadata[:sometimes] && e.metadata[:retried] > 1 } end end.flatten formatter.message color[retried_examples.empty? ? :green : :yellow, "\n\nRetried examples: #{retried_examples.count}"] unless retried_examples.empty? retried_examples.each do |e| formatter.message " #{e.full_description}" formatter.message(color[:yellow, " [#{e.metadata[:retried]}/#{e.metadata[:retries]}] "] + formatter.class.relative_path(e.location)) end end end end -
Sean Cribbs revised this gist
Feb 1, 2012 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # Emulates the QuickCheck ?SOMETIMES macro. RSpec.configure do |config| config.around(:each, :max_retries => lambda { |m| !!m }) do |example| @@ -12,8 +13,4 @@ end end RSpec::Core::ExampleGroup.define_example_method :sometimes, :max_retries => 3 -
myronmarston created this gist
Feb 1, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ RSpec.configure do |config| config.around(:each, :max_retries => lambda { |m| !!m }) do |example| retries = example.metadata[:max_retries] begin example.run rescue => e retries -= 1 retry if retries >= 0 raise end end end describe "Integration" do it 'does something that fails intermittently', :max_retries => 3 do # ... end end