Class: Spex::Check
- Inherits:
-
Object
show all
- Extended by:
- Enumerable
- Includes:
- Test::Unit::Assertions
- Defined in:
- lib/spex/check.rb
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
.description ⇒ Object
Returns the value of attribute description.
44
45
46
|
# File 'lib/spex/check.rb', line 44
def description
@description
end
|
.name ⇒ Object
Returns the value of attribute name.
44
45
46
|
# File 'lib/spex/check.rb', line 44
def name
@name
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
46
47
48
|
# File 'lib/spex/check.rb', line 46
def options
@options
end
|
#target ⇒ Object
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
|
.examples ⇒ Object
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
|
.options ⇒ Object
36
37
38
|
# File 'lib/spex/check.rb', line 36
def self.options
@options ||= {}
end
|
.registry ⇒ Object
18
19
20
|
# File 'lib/spex/check.rb', line 18
def self.registry
@registry ||= {}
end
|
Instance Method Details
#active? ⇒ Boolean
68
69
70
|
# File 'lib/spex/check.rb', line 68
def active?
@active
end
|
#after ⇒ Object
78
79
|
# File 'lib/spex/check.rb', line 78
def after
end
|
#before ⇒ Object
75
76
|
# File 'lib/spex/check.rb', line 75
def before
end
|
#prepare ⇒ Object
72
73
|
# File 'lib/spex/check.rb', line 72
def prepare
end
|
#to_s ⇒ Object
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
|