<commit_before>module RSpec
  module Matchers
    module BuiltIn
      class RaiseError
        def initialize(expected_error_or_message=Exception, expected_message=nil, &block)
          @block = block
          @actual_error = nil
          case expected_error_or_message
          when String, Regexp
            @expected_error, @expected_message = Exception, expected_error_or_message
          else
            @expected_error, @expected_message = expected_error_or_message, expected_message
          end
        end

        def matches?(given_proc, negative_expectation = false)
          @raised_expected_error = false
          @with_expected_message = false
          @eval_block = false
          @eval_block_passed = false
          begin
            given_proc.call
          rescue expected_error_class => @actual_error
            @raised_expected_error = true
            @with_expected_message = verify_message
          rescue Exception => @actual_error
            # This clause should be empty, but rcov will not report it as covered
            # unless something (anything) is executed within the clause
            "http://eigenclass.org/hiki.rb?rcov-0.8.0"
          end

          unless negative_expectation
            eval_block if @raised_expected_error && @with_expected_message && @block
          end
        ensure
          return (@raised_expected_error & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
        end
        alias == matches?

        def does_not_match?(given_proc)
          !matches?(given_proc, :negative_expectation)
        end

        def eval_block
          @eval_block = true
          begin
            @block[@actual_error]
            @eval_block_passed = true
          rescue Exception => err
            @actual_error = err
          end
        end

        def verify_message
          case @expected_message
          when nil
            true
          when Regexp
            @expected_message =~ @actual_error.message
          else
            @expected_message == @actual_error.message
          end
        end

        def failure_message_for_should
          @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
        end

        def failure_message_for_should_not
          "expected no #{expected_error}#{given_error}"
        end

        def description
          "raise #{expected_error}"
        end

        private

        def expected_error_class
          (@expected_error.is_a? Class) ? @expected_error : @expected_error.class
        end

        def expected_error
          case @expected_message
          when nil
            @expected_error
          when Regexp
            "#{@expected_error} with message matching #{@expected_message.inspect}"
          else
            "#{@expected_error} with #{@expected_message.inspect}"
          end
        end

        def format_backtrace(backtrace)
          formatter = Matchers.configuration.backtrace_formatter
          formatter.format_backtrace(backtrace)
        end

        def given_error
          return " but nothing was raised" unless @actual_error

          backtrace = format_backtrace(@actual_error.backtrace)
          [
            ", got #{@actual_error.inspect} with backtrace:",
            *backtrace
          ].join("\n  # ")
        end
      end<commit_msg>Change error instance implementation to match == instances, or classes<commit_after>module RSpec
  module Matchers
    module BuiltIn
      class RaiseError
        def initialize(expected_error_or_message=Exception, expected_message=nil, &block)
          @block = block
          @actual_error = nil
          case expected_error_or_message
          when String, Regexp
            @expected_error, @expected_message = Exception, expected_error_or_message
          else
            @expected_error, @expected_message = expected_error_or_message, expected_message
          end
        end

        def matches?(given_proc, negative_expectation = false)
          @raised_expected_error = false
          @with_expected_message = false
          @eval_block = false
          @eval_block_passed = false
          begin
            given_proc.call
          rescue Exception => @actual_error
            if @actual_error == @expected_error || @actual_error.is_a?(@expected_error)
              @raised_expected_error = true
              @with_expected_message = verify_message
            end
          end

          unless negative_expectation
            eval_block if @raised_expected_error && @with_expected_message && @block
          end
        ensure
          return (@raised_expected_error & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
        end
        alias == matches?

        def does_not_match?(given_proc)
          !matches?(given_proc, :negative_expectation)
        end

        def eval_block
          @eval_block = true
          begin
            @block[@actual_error]
            @eval_block_passed = true
          rescue Exception => err
            @actual_error = err
          end
        end

        def verify_message
          case @expected_message
          when nil
            true
          when Regexp
            @expected_message =~ @actual_error.message
          else
            @expected_message == @actual_error.message
          end
        end

        def failure_message_for_should
          @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
        end

        def failure_message_for_should_not
          "expected no #{expected_error}#{given_error}"
        end

        def description
          "raise #{expected_error}"
        end

        private

        def expected_error_class
          (@expected_error.is_a? Class) ? @expected_error : @expected_error.class
        end

        def expected_error
          case @expected_message
          when nil
            @expected_error.inspect
          when Regexp
            "#{@expected_error} with message matching #{@expected_message.inspect}"
          else
            "#{@expected_error} with #{@expected_message.inspect}"
          end
        end

        def format_backtrace(backtrace)
          formatter = Matchers.configuration.backtrace_formatter
          formatter.format_backtrace(backtrace)
        end

        def given_error
          return " but nothing was raised" unless @actual_error

          backtrace = format_backtrace(@actual_error.backtrace)
          [
            ", got #{@actual_error.inspect} with backtrace:",
            *backtrace
          ].join("\n  # ")
        end
      end
{'fraction_non_alphanumeric': 0.0642846464344446, 'fraction_numerical': 0.00044849753326356705, 'mean_word_length': 1.887354337505395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4429459', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1689, 'n_words': 397}