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
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/matchers/built_in/satisfy.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
rspec-expectations-3.7.0 lib/rspec/matchers/built_in/satisfy.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
tdiary-5.0.6 vendor/bundle/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
test_gem2_dh-0.1.0 vendor/bundle/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
echonet_lite-0.1.0 vendor/bundle/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
bibtex_to_scrapbox-0.2.0 gems/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
ta910_helloworld-0.1.1 vendor/bundle/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
ta910_helloworld-0.1.0 vendor/bundle/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
bibtex_to_scrapbox-0.1.0 gems/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/rspec-expectations-3.6.0/lib/rspec/matchers/built_in/satisfy.rb