Class: Spex::Check

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Includes:
Test::Unit::Assertions
Defined in:
lib/spex/check.rb

Direct Known Subclasses

FileCheck, ProcessCheck

Defined Under Namespace

Classes: Option, UnknownOptionError

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, options = {}) ⇒ Check

Returns a new instance of Check.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spex/check.rb', line 47

def initialize(target, options = {})
  @target = target
  if options.is_a?(Hash)
    @options = options
    @active = true
  else
    @options = {}
    @active = options
  end
  validate!
end

Class Attribute Details

.descriptionObject

Returns the value of attribute description.



44
45
46
# File 'lib/spex/check.rb', line 44

def description
  @description
end

.nameObject

Returns the value of attribute name.



44
45
46
# File 'lib/spex/check.rb', line 44

def name
  @name
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



46
47
48
# File 'lib/spex/check.rb', line 46

def options
  @options
end

#targetObject (readonly)

Returns the value of attribute target.



46
47
48
# File 'lib/spex/check.rb', line 46

def target
  @target
end

Class Method Details

.[](name) ⇒ Object



14
15
16
# File 'lib/spex/check.rb', line 14

def self.[](name)
  registry[name]
end

.as(name, description) ⇒ Object



22
23
24
25
26
# File 'lib/spex/check.rb', line 22

def self.as(name, description)
  self.name = name
  self.description = description
  Check.registry[name.to_sym] = self
end

.each(&block) ⇒ Object



10
11
12
# File 'lib/spex/check.rb', line 10

def self.each(&block)
  registry.each(&block)
end

.example(description, text) ⇒ Object



28
29
30
# File 'lib/spex/check.rb', line 28

def self.example(description, text)
  examples << [description, text]
end

.examplesObject



32
33
34
# File 'lib/spex/check.rb', line 32

def self.examples
  @examples ||= []
end

.option(name, description = nil, &block) ⇒ Object



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

def self.option(name, description = nil, &block)
  options[name] = Option.new(name, description, &block)
end

.optionsObject



36
37
38
# File 'lib/spex/check.rb', line 36

def self.options
  @options ||= {}
end

.registryObject



18
19
20
# File 'lib/spex/check.rb', line 18

def self.registry
  @registry ||= {}
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/spex/check.rb', line 68

def active?
  @active
end

#afterObject



78
79
# File 'lib/spex/check.rb', line 78

def after
end

#beforeObject



75
76
# File 'lib/spex/check.rb', line 75

def before
end

#prepareObject



72
73
# File 'lib/spex/check.rb', line 72

def prepare
end

#to_sObject



81
82
83
# File 'lib/spex/check.rb', line 81

def to_s
  "#{self.class.description} of #{target}"
end

#validate!Object



59
60
61
62
63
64
65
66
# File 'lib/spex/check.rb', line 59

def validate!
  options.each do |key, value|
    option = self.class.options[key]
    unless option
      raise UnknownOptionError, key.to_s
    end
  end
end