Sha256: 4bb60e676a4434e95eeca2b46c011bd784baa07c2b01c6af86013d8a2caefff7

Contents?: true

Size: 927 Bytes

Versions: 30

Compression:

Stored size: 927 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.send_node.first_argument
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rubocop-rspec-1.37.1 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.37.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.36.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.35.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.34.1 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.34.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.33.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.32.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.31.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.30.1 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.30.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.29.1 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.29.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.28.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.27.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.26.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.25.1 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.25.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.24.0 lib/rubocop/rspec/hook.rb
rubocop-rspec-1.23.0 lib/rubocop/rspec/hook.rb