<commit_before>require 'spec_helper'

describe Tries do
  before do
    @error_counter = 0
  end

  context 'when retrying on all errors' do
    it 'retries at least the defined number of times' do
      expect do
        5.tries do
          raise_foo_foo_bar_bar_standard
        end
      end.to_not raise_error
    end

    it 'retries max the defined number of times' do
      expect do
        3.tries do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(BarError)
    end
  end

  context 'when retrying only on one error' do
    it 'retries at least the defined number of times' do
      expect do
        2.tries on: FooError do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(BarError)
    end

    it 'retries max the defined number of times' do
      expect do
        1.tries on: FooError do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(FooError)
    end
  end

  context 'when retrying on multiple errors' do
    it 'retries at least the defined number of times' do
      expect do
        5.tries on: [FooError, BarError] do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(StandardError)
    end

    it 'retries max the defined number of times' do
      expect do
        3.tries on: [FooError, BarError] do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(BarError)
    end
  end

  context 'when specifying a delay' do
    let(:delay) { 1.1 }

    it 'sleeps the specified delay' do
      Kernel.should_receive(:sleep).with(delay).exactly(2).times

      begin
        3.tries on: FooError, delay: delay do
          raise_foo_foo_bar_bar_standard
        end
      rescue StandardError
      end
    end
  end
end

FooError = Class.new(StandardError)
BarError = Class.new(StandardError)

def raise_foo_foo_bar_bar_standard
  @error_counter += 1

  case @error_counter
  when 1
    raise FooError
  when 2
    raise FooError
  when 3
    raise BarError
  when 4
    raise BarError
  when 5
    raise StandardError
  end
end<commit_msg>Reformat spec code<commit_after>require 'spec_helper'

describe Tries do
  before do
    @error_counter = 0
  end

  context 'when retrying on all errors' do
    it 'retries at least the defined number of times' do
      expect do
        5.tries do
          raise_foo_foo_bar_bar_standard
        end
      end.to_not raise_error
    end

    it 'retries max the defined number of times' do
      expect do
        3.tries do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(BarError)
    end
  end

  context 'when retrying only on one error' do
    it 'retries at least the defined number of times' do
      expect do
        2.tries on: FooError do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(BarError)
    end

    it 'retries max the defined number of times' do
      expect do
        1.tries on: FooError do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(FooError)
    end
  end

  context 'when retrying on multiple errors' do
    it 'retries at least the defined number of times' do
      expect do
        5.tries on: [FooError, BarError] do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(StandardError)
    end

    it 'retries max the defined number of times' do
      expect do
        3.tries on: [FooError, BarError] do
          raise_foo_foo_bar_bar_standard
        end
      end.to raise_error(BarError)
    end
  end

  context 'when specifying a delay' do
    let(:delay) { 1.1 }

    it 'sleeps the specified delay' do
      Kernel.should_receive(:sleep).with(delay).exactly(2).times

      begin
        3.tries on: FooError, delay: delay do
          raise_foo_foo_bar_bar_standard
        end
      rescue StandardError
      end
    end
  end
end

FooError = Class.new(StandardError)
BarError = Class.new(StandardError)

def raise_foo_foo_bar_bar_standard
  @error_counter += 1

  case @error_counter
  when 1 then raise FooError
  when 2 then raise FooError
  when 3 then raise BarError
  when 4 then raise BarError
  when 5 then raise StandardError
  end
end
{'fraction_non_alphanumeric': 0.04459203036053131, 'fraction_numerical': 0.008064516129032258, 'mean_word_length': 2.253858024691358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '779994', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1298, 'n_words': 442}