Class: Bacon::Context
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
- #behaves_like(*names) ⇒ Object
- #change?(*args, &block) ⇒ Boolean
- #current_specification ⇒ Object
- #describe(*args, &block) ⇒ Object
-
#initialize(name, before = nil, after = nil, &block) ⇒ Context
constructor
A new instance of Context.
- #it(description, &block) ⇒ Object
- #raise?(*args, &block) ⇒ Boolean
- #run ⇒ Object
- #should(*args, &block) ⇒ Object
- #specification_did_finish(spec) ⇒ Object
- #throw?(*args, &block) ⇒ Boolean
- #wait(seconds, &block) ⇒ Object
Constructor Details
#initialize(name, before = nil, after = nil, &block) ⇒ Context
Returns a new instance of Context.
252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/mac_bacon.rb', line 252 def initialize(name, before = nil, after = nil, &block) @name = name @before, @after = (before ? before.dup : []), (after ? after.dup : []) @block = block @specifications = [] @current_specification_index = 0 Bacon.add_context(self) instance_eval(&block) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
250 251 252 |
# File 'lib/mac_bacon.rb', line 250 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
250 251 252 |
# File 'lib/mac_bacon.rb', line 250 def name @name end |
Instance Method Details
#after(&block) ⇒ Object
288 |
# File 'lib/mac_bacon.rb', line 288 def after(&block); @after << block; end |
#before(&block) ⇒ Object
287 |
# File 'lib/mac_bacon.rb', line 287 def before(&block); @before << block; end |
#behaves_like(*names) ⇒ Object
290 291 292 |
# File 'lib/mac_bacon.rb', line 290 def behaves_like(*names) names.each { |name| instance_eval(&Shared[name]) } end |
#change?(*args, &block) ⇒ Boolean
323 |
# File 'lib/mac_bacon.rb', line 323 def change?(*args, &block); block.change?(*args); end |
#current_specification ⇒ Object
274 275 276 |
# File 'lib/mac_bacon.rb', line 274 def current_specification @specifications[@current_specification_index] end |
#describe(*args, &block) ⇒ Object
309 310 311 312 313 314 315 |
# File 'lib/mac_bacon.rb', line 309 def describe(*args, &block) context = Bacon::Context.new(args.join(' '), @before, @after, &block) (parent_context = self).methods(false).each {|e| class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)} } context end |
#it(description, &block) ⇒ Object
294 295 296 297 298 299 |
# File 'lib/mac_bacon.rb', line 294 def it(description, &block) return unless description =~ RestrictName block ||= lambda { should.flunk "not implemented" } Counter[:specifications] += 1 @specifications << Specification.new(self, description, block, @before, @after) end |
#raise?(*args, &block) ⇒ Boolean
321 |
# File 'lib/mac_bacon.rb', line 321 def raise?(*args, &block); block.raise?(*args); end |
#run ⇒ Object
264 265 266 267 268 269 270 271 272 |
# File 'lib/mac_bacon.rb', line 264 def run # TODO #return unless name =~ RestrictContext if spec = current_specification spec.performSelector("run", withObject:nil, afterDelay:0) else Bacon.context_did_finish(self) end end |
#should(*args, &block) ⇒ Object
301 302 303 304 305 306 307 |
# File 'lib/mac_bacon.rb', line 301 def should(*args, &block) if Counter[:depth]==0 it('should '+args.first,&block) else super(*args,&block) end end |
#specification_did_finish(spec) ⇒ Object
278 279 280 281 282 283 284 285 |
# File 'lib/mac_bacon.rb', line 278 def specification_did_finish(spec) if (@current_specification_index + 1) < @specifications.size @current_specification_index += 1 run else Bacon.context_did_finish(self) end end |
#throw?(*args, &block) ⇒ Boolean
322 |
# File 'lib/mac_bacon.rb', line 322 def throw?(*args, &block); block.throw?(*args); end |
#wait(seconds, &block) ⇒ Object
317 318 319 |
# File 'lib/mac_bacon.rb', line 317 def wait(seconds, &block) current_specification.postpone_block(seconds, &block) end |