Sha256: 4c60962935b31bb0563ae7ff7dca475280f9ffdd8b66f3e90456aac85ce7b2f8

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

require 'expect'

module Spectus
  # This class evaluate the expectation with the passed block.
  #
  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.1 lib/spectus/sandbox.rb