Class: Speck::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/speck/check.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lambda, description = "<undocumented>") ⇒ Check



40
41
42
43
# File 'lib/speck/check.rb', line 40

def initialize(lambda, description = "<undocumented>")
  @lambda = lambda
  @description = description
end

Instance Attribute Details

#descriptionObject

A description for the check. Usually a relevant line of code.



11
12
13
# File 'lib/speck/check.rb', line 11

def description
  @description
end

#lambdaObject

A block to be executed.



7
8
9
# File 'lib/speck/check.rb', line 7

def lambda
  @lambda
end

#statusObject

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



17
18
19
# File 'lib/speck/check.rb', line 17

def status
  @status
end

Instance Method Details

#executeObject

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



55
56
57
58
59
# File 'lib/speck/check.rb', line 55

def execute
  @lambda.call.tap {|result| @status = result ? result : false }
  raise Exception::CheckFailed unless success?
  self
end

#success?Boolean

Checks the truthiness of this Check’s status.



21
22
23
# File 'lib/speck/check.rb', line 21

def success?
  !!status
end