Sha256: 57e8e382c92754292791bd07f9515eb0c9ea3e2c1402d677d4741ca320dc9b34

Contents?: true

Size: 1007 Bytes

Versions: 2

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module RSpec
    # Wrapper for RSpec examples
    class Example
      extend RuboCop::NodePattern::Macros

      def_node_matcher :extract_doc_string,     '(send _ _ $str ...)'
      def_node_matcher :extract_metadata,       '(send _ _ _ $...)'
      def_node_matcher :extract_implementation, '(block send args $_)'

      def initialize(node)
        @node = node
      end

      def doc_string
        extract_doc_string(definition)
      end

      def metadata
        extract_metadata(definition)
      end

      def implementation
        extract_implementation(node)
      end

      def eql?(other)
        node.eql?(other.node)
      end

      alias == eql?

      def hash
        [self.class, node].hash
      end

      def to_node
        node
      end

      def definition
        if node.send_type?
          node
        else
          node.children.first
        end
      end

      protected

      attr_reader :node
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-1.9.1 lib/rubocop/rspec/example.rb
rubocop-rspec-1.9.0 lib/rubocop/rspec/example.rb