Sha256: 86b5d4dfbb12753667b624e985ae77458102a7008f6025a54f4f3fec8d7ec99a

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Dependencies
    module Queries
      module Gems
        ##
        # @api private
        #
        class RSpec
          class << self
            ##
            # @return [Boolean]
            #
            # @internal
            #   `Style/TernaryParentheses` is disabled since `defined?` has too low priority without parentheses.
            #
            # rubocop:disable Style/TernaryParentheses
            def loaded?
              (defined? ::RSpec) ? true : false
            end
            # rubocop:enable Style/TernaryParentheses

            ##
            # @return [ConvenientService::Dependencies::Queries::Version]
            #
            # @internal
            #   https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/version.rb
            #
            def version
              loaded? ? Version.new(::RSpec::Core::Version::STRING) : Version.null_version
            end

            ##
            # @return [RSpec::Core::Example, nil]
            #
            # @internal
            #   NOTE: Returns `nil` in environments where RSpec is NOT fully loaded, e.g: irb, rails console, etc.
            #
            #   `::RSpec.current_example` docs:
            #   - https://www.rubydoc.info/github/rspec/rspec-core/RSpec.current_example
            #   - https://github.com/rspec/rspec-core/blob/v3.12.0/lib/rspec/core.rb#L122
            #   - https://relishapp.com/rspec/rspec-core/docs/metadata/current-example
            #
            def current_example
              return unless loaded?

              ##
              # NOTE: This happens in Ruby-only projects where RSpec is loaded by `Bundler.require`, not by `bundle exec rspec`.
              #
              return unless ::RSpec.respond_to?(:current_example)

              ::RSpec.current_example
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/dependencies/queries/gems/rspec.rb
convenient_service-0.19.0 lib/convenient_service/dependencies/queries/gems/rspec.rb