class Speck::Check

Represents a queued thing to be checked of some sort, within a `Speck`.

Attributes

expectation[RW]

The block to be executed, determining the success or failure of this particular `Check`. If it accepts an argument, the result of the target block will be passed as that argument.

status[RW]

The status of the `Check`. `nil` indicates the `Check` hasn’t been executed, and `true` or `false` indicate the success of the latest execution

target[RW]

The `target` of a `Check` is a block that returns an object to be passed to the `expectation`. It represents the object that the `Check` is intended to, well, check.

Public Class Methods

new(target = nil, &expectation) click to toggle source
# File lib/speck/check.rb, line 26
def initialize(target = nil, &expectation)
  @target = target.respond_to?(:call) ? target : ->{target}
  @expectation = expectation
  Speck.current.checks << self if Speck.current
end

Public Instance Methods

execute() click to toggle source

Executes this `Check`, raising an error if the expectation returns nil or false.

# File lib/speck/check.rb, line 35
def execute
  call = @expectation.arity == 0 ? ->{@target.call; @expectation.call} : ->{@expectation[@target.call]}
  @status = call.call ? :passed : :failed
  raise Exception::CheckFailed unless passed?
  return self
end
passed?() click to toggle source
# File lib/speck/check.rb, line 22
def passed?
  status == :passed
end