Sha256: 0873f6524c256857c5e1b0d3489e93bc8a1942a856746af0eeafc02269962f44

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

require 'expect'

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
    def initialize(definition, &actual)
      @got = ::Expect.this(&actual).to(definition)
    rescue => e
      @exception = e
    end

    # Return the result as a positive or a negative assertion.
    #
    # @param [Boolean] negate
    #
    # @return [Boolean] Report if the test was true or false.
    def pass?(negate)
      if defined?(@exception)
        false
      else
        negate ^ @got
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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