Sha256: dde0bdd17f0032c9eb73b1100c17d57a05283b1c81b01a050c05cf058af297c9

Contents?: true

Size: 920 Bytes

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-rspec-1.15.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.14.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.13.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.12.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.11.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.10.0 lib/rubocop/rspec/hook.rb