Sha256: b777507f65c999dbb191b72a76b3affc36ffd0b1efe1154ba38f7464055ba004

Contents?: true

Size: 1.58 KB

Versions: 13

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module RSpec
    module Matchers
      module Custom
        class CacheItsValue
          def matches?(block_expectation)
            @block_expectation = block_expectation

            ##
            # NOTE: Identical to `block_expectation.call.object_id == block_expectation.call.object_id`.
            #
            block_expectation.call.equal?(block_expectation.call)
          end

          def supports_block_expectations?
            true
          end

          def description
            "cache its value"
          end

          def failure_message
            "expected #{printable_block_expectation} to cache its value"
          end

          def failure_message_when_negated
            "expected #{printable_block_expectation} NOT to cache its value"
          end

          ##
          # NOTE: An example of how RSpec extracts block source, but they marked it as private.
          # https://github.com/rspec/rspec-expectations/blob/311aaf245f2c5493572bf683b8c441cb5f7e44c8/lib/rspec/matchers/built_in/change.rb#L437
          #
          # TODO: `printable_block_expectation` when `method_source` is available.
          # https://github.com/banister/method_source
          #
          # def printable_block_expectation
          #   @printable_block_expectation ||= block_expectation.source
          # end
          #
          def printable_block_expectation
            @printable_block_expectation ||= "{ ... }"
          end

          private

          attr_reader :block_expectation
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.11.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.10.1 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.10.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.9.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.8.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.7.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.6.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.5.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.4.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.3.1 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.3.0 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb
convenient_service-0.2.1 lib/convenient_service/rspec/matchers/custom/cache_its_value.rb