Sha256: 0483e105da9e2887b3156764a3046d977e2a44ca99a2fdc84f48d29f6d1cfdbb

Contents?: true

Size: 1.48 KB

Versions: 6160

Compression:

Stored size: 1.48 KB

Contents

module RSpec
  module Matchers
    module BuiltIn
      # @api private
      # Provides the implementation for `satisfy`.
      # Not intended to be instantiated directly.
      class Satisfy < BaseMatcher
        def initialize(description=nil, &block)
          @description = description
          @block = block
        end

        # @private
        def matches?(actual, &block)
          @block = block if block
          @actual = actual
          @block.call(actual)
        end

        # @private
        def description
          @description ||= "satisfy #{block_representation}"
        end

        # @api private
        # @return [String]
        def failure_message
          "expected #{actual_formatted} to #{description}"
        end

        # @api private
        # @return [String]
        def failure_message_when_negated
          "expected #{actual_formatted} not to #{description}"
        end

      private

        if RSpec::Support::RubyFeatures.ripper_supported?
          def block_representation
            if (block_snippet = extract_block_snippet)
              "expression `#{block_snippet}`"
            else
              'block'
            end
          end

          def extract_block_snippet
            return nil unless @block
            Expectations::BlockSnippetExtractor.try_extracting_single_line_body_of(@block, matcher_name)
          end
        else
          def block_representation
            'block'
          end
        end
      end
    end
  end
end

Version data entries

6,160 entries across 6,091 versions & 84 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.11.0/lib/rspec/matchers/built_in/satisfy.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.11.0/lib/rspec/matchers/built_in/satisfy.rb
affixapi-1.1.101 vendor/bundle/ruby/3.3.0/gems/rspec-expectations-3.13.0/lib/rspec/matchers/built_in/satisfy.rb
moneykit-0.1.15 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/built_in/satisfy.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/built_in/satisfy.rb
affixapi-1.1.100 vendor/bundle/ruby/3.3.0/gems/rspec-expectations-3.13.0/lib/rspec/matchers/built_in/satisfy.rb
affixapi-1.1.99 vendor/bundle/ruby/3.3.0/gems/rspec-expectations-3.13.0/lib/rspec/matchers/built_in/satisfy.rb
affixapi-1.1.94 vendor/bundle/ruby/3.3.0/gems/rspec-expectations-3.13.0/lib/rspec/matchers/built_in/satisfy.rb
affixapi-1.1.93 vendor/bundle/ruby/3.3.0/gems/rspec-expectations-3.13.0/lib/rspec/matchers/built_in/satisfy.rb
mux_ruby-3.18.0 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.11.0/lib/rspec/matchers/built_in/satisfy.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/built_in/satisfy.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/built_in/satisfy.rb
affixapi-1.1.92 vendor/bundle/ruby/3.3.0/gems/rspec-expectations-3.13.0/lib/rspec/matchers/built_in/satisfy.rb
cybrid_api_organization_ruby-0.119.35 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.13.1/lib/rspec/matchers/built_in/satisfy.rb
cybrid_api_bank_ruby-0.119.35 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.13.1/lib/rspec/matchers/built_in/satisfy.rb
cybrid_api_id_ruby-0.119.35 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.13.1/lib/rspec/matchers/built_in/satisfy.rb
cybrid_api_bank_ruby-0.119.34 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.13.1/lib/rspec/matchers/built_in/satisfy.rb
cybrid_api_id_ruby-0.119.34 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.13.1/lib/rspec/matchers/built_in/satisfy.rb
cybrid_api_organization_ruby-0.119.34 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.13.1/lib/rspec/matchers/built_in/satisfy.rb
cybrid_api_id_ruby-0.119.32 vendor/bundle/ruby/3.2.0/gems/rspec-expectations-3.13.1/lib/rspec/matchers/built_in/satisfy.rb