Class: Bacon::Specification
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Instance Method Summary collapse
- #execute_block ⇒ Object
- #finalize ⇒ Object
-
#initialize(context, description, block, before_filters, after_filters) ⇒ Specification
constructor
A new instance of Specification.
- #postpone_block(seconds, &block) ⇒ Object
- #run ⇒ Object
- #run_after_filters ⇒ Object
- #run_before_filters ⇒ Object
- #run_postponed_block(block) ⇒ Object
Constructor Details
#initialize(context, description, block, before_filters, after_filters) ⇒ Specification
Returns a new instance of Specification.
135 136 137 138 139 140 141 142 |
# File 'lib/mac_bacon.rb', line 135 def initialize(context, description, block, before_filters, after_filters) @context, @description, @block = context, description, block @before_filters, @after_filters = before_filters.dup, after_filters.dup @postponed_blocks_count = 0 @exception_occurred = false @error = "" end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
133 134 135 |
# File 'lib/mac_bacon.rb', line 133 def description @description end |
Instance Method Details
#execute_block ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/mac_bacon.rb', line 193 def execute_block begin yield rescue Object => e @exception_occurred = true ErrorLog << "#{e.class}: #{e.}\n" e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ }. each_with_index { |line, i| ErrorLog << "\t#{line}#{i==0 ? ": #{@context.name} - #{@description}" : ""}\n" } ErrorLog << "\n" @error = if e.kind_of? Error Counter[e.count_as] += 1 e.count_as.to_s.upcase else Counter[:errors] += 1 "ERROR: #{e.class}" end end end |
#finalize ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/mac_bacon.rb', line 179 def finalize if Counter[:requirements] == @number_of_requirements_before # the specification did not contain any requirements, so it flunked # TODO ugh, exceptions for control flow, need to clean this up execute_block { raise Error.new(:missing, "empty specification: #{@context.name} #{@description}") } end execute_block { run_after_filters } Counter[:depth] -= 1 Bacon.handle_requirement_end(@error) @context.specification_did_finish(self) end |
#postpone_block(seconds, &block) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/mac_bacon.rb', line 164 def postpone_block(seconds, &block) # If an exception occurred, we definitely don't need to schedule any more blocks unless @exception_occurred @postponed_blocks_count += 1 performSelector("run_postponed_block:", withObject:block, afterDelay:seconds) end end |
#run ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/mac_bacon.rb', line 152 def run Bacon.handle_requirement_begin(@description) execute_block do Counter[:depth] += 1 run_before_filters @number_of_requirements_before = Counter[:requirements] @context.instance_eval(&@block) end finalize if @postponed_blocks_count == 0 end |
#run_after_filters ⇒ Object
148 149 150 |
# File 'lib/mac_bacon.rb', line 148 def run_after_filters @after_filters.each { |f| @context.instance_eval(&f) } end |
#run_before_filters ⇒ Object
144 145 146 |
# File 'lib/mac_bacon.rb', line 144 def run_before_filters @before_filters.each { |f| @context.instance_eval(&f) } end |
#run_postponed_block(block) ⇒ Object
172 173 174 175 176 177 |
# File 'lib/mac_bacon.rb', line 172 def run_postponed_block(block) # If an exception occurred, we definitely don't need execute any more blocks execute_block(&block) unless @exception_occurred @postponed_blocks_count -= 1 finalize if @postponed_blocks_count == 0 end |