Sha256: e9dc90b42c5ed24ffb964b290a59610f8ee3593a93e13f18e03a2af70b327096

Contents?: true

Size: 1.58 KB

Versions: 7

Compression:

Stored size: 1.58 KB

Contents

module Spectus
  # This class evaluate the expectation with the passed block.
  #
  # @api private
  #
  class Sandbox
    # Execute the untested code from the passed block against the matcher.
    #
    # @param matcher    [#matches?]  The matcher.
    # @param negate     [Boolean]    The negation of the matcher's result.
    # @param object     [#object_id] The front object which is challenged.
    # @param challenges [Array]      The list of challenges.
    def initialize(matcher, negate, object, *challenges)
      @got = negate ^ matcher.matches? do
        @actual = challenges.inject(object) do |subject, challenge|
          @last_challenge = challenge
          @last_challenge.to(subject)
        end
      end
    rescue => e
      @exception = e
    end

    # @!attribute [r] last_challenge
    #
    # @return [Defi::Challenge] The last evaluated challenge.
    attr_reader :last_challenge

    # @!attribute [r] actual
    #
    # @return [#object_id] The value that the subject return through its
    #   challenge.
    attr_reader :actual

    # @!attribute [r] exception
    #
    # @return [#exception, nil] Any possible raised exception.
    attr_reader :exception

    # @!attribute [r] got
    #
    # @return [#object_id] The result of the boolean comparison between the
    #   actual value and the expected value.
    attr_reader :got

    # Report to the spec's requirement level if the test is true or false.
    #
    # @return [Boolean] Report if the test was true or false.
    def valid?
      if defined?(@exception)
        false
      else
        got
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spectus-3.0.6 lib/spectus/sandbox.rb
spectus-3.0.5 lib/spectus/sandbox.rb
spectus-3.0.4 lib/spectus/sandbox.rb
spectus-3.0.3 lib/spectus/sandbox.rb
spectus-3.0.2 lib/spectus/sandbox.rb
spectus-3.0.1 lib/spectus/sandbox.rb
spectus-3.0.0 lib/spectus/sandbox.rb