Class: Funktional::Context
- Inherits:
-
Object
- Object
- Funktional::Context
show all
- Defined in:
- lib/funktional/context.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, parent, &blk) ⇒ Context
Returns a new instance of Context.
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/funktional/context.rb', line 13
def initialize(name, parent, &blk)
Funktional.add_context(self)
self.name = name
self.parent = parent
self.setup_blocks = []
self.teardown_blocks = []
self.should_blocks = []
self.sub_contexts = []
merge_block(&blk)
Funktional.remove_context
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
122
123
124
|
# File 'lib/funktional/context.rb', line 122
def method_missing(method, *args, &blk)
test_unit_class.send(method, *args, &blk)
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/funktional/context.rb', line 6
def name
@name
end
|
#parent ⇒ Object
Returns the value of attribute parent.
7
8
9
|
# File 'lib/funktional/context.rb', line 7
def parent
@parent
end
|
#setup_blocks ⇒ Object
Returns the value of attribute setup_blocks.
9
10
11
|
# File 'lib/funktional/context.rb', line 9
def setup_blocks
@setup_blocks
end
|
#should_blocks ⇒ Object
Returns the value of attribute should_blocks.
11
12
13
|
# File 'lib/funktional/context.rb', line 11
def should_blocks
@should_blocks
end
|
#sub_contexts ⇒ Object
Returns the value of attribute sub_contexts.
8
9
10
|
# File 'lib/funktional/context.rb', line 8
def sub_contexts
@sub_contexts
end
|
#teardown_blocks ⇒ Object
Returns the value of attribute teardown_blocks.
10
11
12
|
# File 'lib/funktional/context.rb', line 10
def teardown_blocks
@teardown_blocks
end
|
Instance Method Details
#assigned(target) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/funktional/context.rb', line 68
def assigned(target)
recorder = StackRecorder.new(target)
self.should_blocks << AssignedShouldBlock.new(recorder, self)
return recorder
end
|
#build ⇒ Object
117
118
119
120
|
# File 'lib/funktional/context.rb', line 117
def build
self.should_blocks.map(&:to_test)
sub_contexts.each { |context| context.build }
end
|
#context(name, &blk) ⇒ Object
30
31
32
|
# File 'lib/funktional/context.rb', line 30
def context(name, &blk)
self.sub_contexts << Context.new(name, self, &blk)
end
|
#count(selector) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/funktional/context.rb', line 61
def count(selector)
recorder = StackRecorder.new(selector)
self.should_blocks << CountShouldBlock.new(recorder, self)
return recorder
end
|
#element(selector) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/funktional/context.rb', line 54
def element(selector)
recorder = StackRecorder.new(selector)
self.should_blocks << ElementShouldBlock.new(recorder, self)
return recorder
end
|
#flashed(kind) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/funktional/context.rb', line 75
def flashed(kind)
recorder = StackRecorder.new(kind)
self.should_blocks << FlashedShouldBlock.new(recorder, self)
return recorder
end
|
#full_name ⇒ Object
82
83
84
85
|
# File 'lib/funktional/context.rb', line 82
def full_name
parent_name = parent.full_name if sub_context?
return [parent_name, name].join(" ").strip
end
|
#merge_block(&blk) ⇒ Object
26
27
28
|
# File 'lib/funktional/context.rb', line 26
def merge_block(&blk)
blk.bind(self).call
end
|
#run_all_setup_blocks(binding) ⇒ Object
95
96
97
98
|
# File 'lib/funktional/context.rb', line 95
def run_all_setup_blocks(binding)
run_parent_setup_blocks(binding)
run_current_setup_blocks(binding)
end
|
#run_all_teardown_blocks(binding) ⇒ Object
110
111
112
113
114
115
|
# File 'lib/funktional/context.rb', line 110
def run_all_teardown_blocks(binding)
teardown_blocks.reverse.each do |teardown_block|
teardown_block.bind(binding).call
end
self.parent.run_all_teardown_blocks(binding) if sub_context?
end
|
#run_current_setup_blocks(binding) ⇒ Object
104
105
106
107
108
|
# File 'lib/funktional/context.rb', line 104
def run_current_setup_blocks(binding)
setup_blocks.each do |setup_block|
setup_block.bind(binding).call
end
end
|
#run_parent_setup_blocks(binding) ⇒ Object
100
101
102
|
# File 'lib/funktional/context.rb', line 100
def run_parent_setup_blocks(binding)
self.parent.run_all_setup_blocks(binding) if sub_context?
end
|
#setup(&blk) ⇒ Object
Also known as:
before
34
35
36
|
# File 'lib/funktional/context.rb', line 34
def setup(&blk)
self.setup_blocks << blk
end
|
#should(options, &blk) ⇒ Object
46
47
48
|
# File 'lib/funktional/context.rb', line 46
def should(options, &blk)
self.should_blocks << ShouldBlock.build(options, self, &blk)
end
|
#should_not(options, &blk) ⇒ Object
50
51
52
|
# File 'lib/funktional/context.rb', line 50
def should_not(options, &blk)
self.should_blocks << ShouldNotBlock.build(options, self, &blk)
end
|
#sub_context? ⇒ Boolean
87
88
89
|
# File 'lib/funktional/context.rb', line 87
def sub_context?
parent.is_a?(self.class)
end
|
#teardown(&blk) ⇒ Object
Also known as:
after
40
41
42
|
# File 'lib/funktional/context.rb', line 40
def teardown(&blk)
self.teardown_blocks << blk
end
|
#test_unit_class ⇒ Object
91
92
93
|
# File 'lib/funktional/context.rb', line 91
def test_unit_class
sub_context? ? parent.test_unit_class : parent
end
|