Sha256: 2326e19a5e0509acc78e82fb4857a8e0b0c8e5508f5b37f16f4ddb2c87dbd23a

Contents?: true

Size: 1.52 KB

Versions: 44

Compression:

Stored size: 1.52 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 # rubocop:disable Lint/UselessAccessModifier

        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

44 entries across 39 versions & 19 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
tdiary-5.0.9 vendor/bundle/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
monero_wallet_gen-0.1.0 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
sb_prime_table-0.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
sb_prime_table-0.1.0 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
tdiary-5.0.8 vendor/bundle/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
tdiary-5.0.7 vendor/bundle/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb