Sha256: 8c2528a50f2b7787667c9810b34bada301c9aa88f465cb4a3cd4b53e104089c1

Contents?: true

Size: 920 Bytes

Versions: 2

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module RSpec
    # Wrapper for RSpec hook
    class Hook < Concept
      STANDARDIZED_SCOPES = %i[each context suite].freeze
      private_constant(:STANDARDIZED_SCOPES)

      def name
        node.method_name
      end

      def knowable_scope?
        return true unless scope_argument

        scope_argument.sym_type?
      end

      def valid_scope?
        STANDARDIZED_SCOPES.include?(scope)
      end

      def example?
        scope.equal?(:each)
      end

      def scope
        case scope_name
        when nil, :each, :example then :each
        when :context, :all       then :context
        when :suite               then :suite
        else
          scope_name
        end
      end

      private

      def scope_name
        scope_argument.to_a.first
      end

      def scope_argument
        node.method_args.first
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-1.16.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.15.1 lib/rubocop/rspec/hook.rb