<commit_before>require "spec_helper"

RSpec.describe MatchingExceptions do
  class CustomError < StandardError
    attr_reader :custom_attribute

    def initialize(message, custom_attribute)
      @custom_attribute = custom_attribute
      super(message)
    end
  end

  it "has a version number" do
    expect(MatchingExceptions::VERSION).not_to be nil
  end

  it "allows exceptions to be rescued by message" do
    rescued = false

    begin
      raise StandardError.new("error message")
    rescue ME.matches("message")
      rescued = true
    end

    expect(rescued).to be_truthy
  end

  it "allows exceptions to be rescued by regular expressions" do
    rescued = false

    begin
      raise StandardError.new("error message")
    rescue ME.matches(/MESSAGE/i)
      rescued = true
    end

    expect(rescued).to be_truthy
  end

  it "rescues by specified attribute" do
    rescued = false

    begin
      raise CustomError.new("blabla", "custom message")
    rescue ME.matches(/message/, attribute: :custom_attribute)
      rescued = true
    end

    expect(rescued).to be_truthy
  end

  it "ignores non existing attributes" do
    rescued = false

    begin
      raise CustomError.new("blabla", "custom message")
    rescue ME.matches(/message/, attribute: :foo)
      rescued = true
    rescue
    end

    expect(rescued).to be_falsy
  end
end
<commit_msg>Adds test case for multiple rescues.<commit_after>require "spec_helper"

RSpec.describe MatchingExceptions do
  class CustomError < StandardError
    attr_reader :custom_attribute

    def initialize(message, custom_attribute)
      @custom_attribute = custom_attribute
      super(message)
    end
  end

  it "has a version number" do
    expect(MatchingExceptions::VERSION).not_to be nil
  end

  it "allows exceptions to be rescued by message" do
    rescued = false

    begin
      raise StandardError.new("error message")
    rescue ME.matches("message")
      rescued = true
    end

    expect(rescued).to be_truthy
  end

  it "allows exceptions to be rescued by regular expressions" do
    rescued = false

    begin
      raise StandardError.new("error message")
    rescue ME.matches(/MESSAGE/i)
      rescued = true
    end

    expect(rescued).to be_truthy
  end

  it "rescues by specified attribute" do
    rescued = false

    begin
      raise CustomError.new("blabla", "custom message")
    rescue ME.matches(/message/, attribute: :custom_attribute)
      rescued = true
    end

    expect(rescued).to be_truthy
  end

  it "ignores non existing attributes" do
    rescued = false

    begin
      raise CustomError.new("blabla", "custom message")
    rescue ME.matches(/message/, attribute: :foo)
      rescued = true
    rescue
    end

    expect(rescued).to be_falsy
  end

  context 'when there are multiple rescues' do
    it 'rescues the correct error' do
      rescued = false

      begin
        raise StandardError.new("rescue me!")
      rescue ME.matches(/not me/)
        rescued = false
      rescue ME.matches(/me!/)
        rescued = true
      end

      expect(rescued).to be_truthy
    end
  end
end

{'fraction_non_alphanumeric': 0.07435897435897436, 'fraction_numerical': 0.0, 'mean_word_length': 2.7602409638554217, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3288933', 'n_tokens_mistral': 946, 'n_tokens_neox': 943, 'n_words': 284}