Sha256: 887b0f0ee339298c3218959ff8c17946c1526ab49e05b6368f17e2b6510d0623

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "spectus/exam"

require_relative "base"

module RSpec
  module ExpectationTarget
    # Wraps the target of an expectation with a block.
    #
    # @example
    #   expect { something } # => ExpectationTarget::Block wrapping something
    #
    #   # used with `to`
    #   expect { actual }.to be(42)
    #
    #   # with `not_to`
    #   expect { actual }.not_to be(4)
    #
    # @note `RSpec::ExpectationTarget::Block` is not intended to be instantiated
    #   directly by users. Use `expect` instead.
    class Block < Base
      protected

      # @param matcher  [#matches?] The matcher.
      # @param negate   [Boolean]   The assertion is positive or negative.
      #
      # @return [nil] Write a message to STDOUT.
      #
      # @raise [SystemExit] Terminate execution immediately by calling
      #   `Kernel.exit(false)` with a failure message written to STDERR.
      def absolute_requirement(matcher:, negate:)
        exam = ::Spectus::Exam.new(
          callable:  @actual,
          isolation: false,
          negate:    negate,
          matcher:   matcher
        )

        result(
          actual:  exam.actual,
          error:   exam.exception,
          got:     exam.got,
          matcher: matcher,
          negate:  negate,
          valid:   exam.valid?
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
r_spec-1.0.0.beta8 lib/r_spec/expectation_target/block.rb
r_spec-1.0.0.beta7 lib/r_spec/expectation_target/block.rb
r_spec-1.0.0.beta6 lib/r_spec/expectation_target/block.rb