<commit_before>module Lita
  module RSpec
    module Matchers
      extend ::RSpec::Matchers::DSL

      matcher :route do |message_body|
        match do
          message = Message.new(robot, message_body, source)

          described_class.routes.any? do |route|
            RouteValidator.new(described_class, route, message, robot).call
          end
        end
      end

      matcher :route_command do |message_body|
        match do
          message = Message.new(robot, "#{robot.mention_name} #{message_body}", source)

          described_class.routes.any? do |route|
            RouteValidator.new(described_class, route, message, robot).call
          end
        end
      end

      # TODO: Check for route match without calling route.
      matcher :route_http do |http_method, path|
        match do
          http.public_send(http_method, path).success?
        end
      end

      # TODO: Check for route match without calling route.
      matcher :route_event do |event_name|
        match do
          described_class.trigger(robot, event_name, {})
        end
      end
    end
  end
end<commit_msg>Remove duplication in route_command matcher.<commit_after>module Lita
  module RSpec
    module Matchers
      extend ::RSpec::Matchers::DSL

      matcher :route do |message_body|
        match do
          message = Message.new(robot, message_body, source)

          described_class.routes.any? do |route|
            RouteValidator.new(described_class, route, message, robot).call
          end
        end
      end

      def route_command(message_body)
        route("#{robot.mention_name} #{message_body}")
      end

      # TODO: Check for route match without calling route.
      matcher :route_http do |http_method, path|
        match do
          http.public_send(http_method, path).success?
        end
      end

      # TODO: Check for route match without calling route.
      matcher :route_event do |event_name|
        match do
          described_class.trigger(robot, event_name, {})
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07543520309477757, 'fraction_numerical': 0.0, 'mean_word_length': 2.1587786259541986, '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': '1652216', 'n_tokens_mistral': 588, 'n_tokens_neox': 578, 'n_words': 165}