Sha256: 47befa23ea7c622de8545445542a836048252688e70702c8e8a3ad103070d176

Contents?: true

Size: 758 Bytes

Versions: 1

Compression:

Stored size: 758 Bytes

Contents

require_relative 'matcher'

module Spectus
  # This class evaluate the expectation with the passed block.
  #
  # @api private
  #
  class Sandbox
    attr_reader :exception, :got

    # Execute the untested code from the passed block against the definition.
    #
    # @param [Hash] definition
    # @param [Boolean] negate
    # @yieldparam actual the value which is compared with the expected value.
    def initialize(definition, negate, &actual)
      @got = negate ^ Matcher.pass?(definition, &actual)
    rescue => e
      @exception = e
    end

    # Return the result.
    #
    # @return [Boolean] Report if the test was true or false.
    def pass?
      if defined?(@exception)
        false
      else
        @got
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spectus-2.0.3 lib/spectus/sandbox.rb