Class: Bacon::Context

Inherits:
Object show all
Includes:
Helpers
Defined in:
lib/mac_bacon.rb,
lib/mac_bacon/helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

converted_xibs, ensure_nib, #load_nib

Constructor Details

#initialize(name, before = nil, after = nil, &block) ⇒ Context

Returns a new instance of Context.



340
341
342
343
344
345
346
347
348
349
350
# File 'lib/mac_bacon.rb', line 340

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

#blockObject (readonly)

Returns the value of attribute block.



338
339
340
# File 'lib/mac_bacon.rb', line 338

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



338
339
340
# File 'lib/mac_bacon.rb', line 338

def name
  @name
end

Instance Method Details

#after(&block) ⇒ Object



376
# File 'lib/mac_bacon.rb', line 376

def after(&block);  @after << block; end

#before(&block) ⇒ Object



375
# File 'lib/mac_bacon.rb', line 375

def before(&block); @before << block; end

#behaves_like(*names) ⇒ Object



378
379
380
# File 'lib/mac_bacon.rb', line 378

def behaves_like(*names)
  names.each { |name| instance_eval(&Shared[name]) }
end

#change?(*args, &block) ⇒ Boolean

Returns:

  • (Boolean)


427
# File 'lib/mac_bacon.rb', line 427

def change?(*args, &block); block.change?(*args); end

#current_specificationObject



362
363
364
# File 'lib/mac_bacon.rb', line 362

def current_specification
  @specifications[@current_specification_index]
end

#describe(*args, &block) ⇒ Object



397
398
399
400
401
402
403
# File 'lib/mac_bacon.rb', line 397

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



382
383
384
385
386
387
# File 'lib/mac_bacon.rb', line 382

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

Returns:

  • (Boolean)


425
# File 'lib/mac_bacon.rb', line 425

def raise?(*args, &block); block.raise?(*args); end

#resumeObject



421
422
423
# File 'lib/mac_bacon.rb', line 421

def resume
  current_specification.resume
end

#runObject



352
353
354
355
356
357
358
359
360
# File 'lib/mac_bacon.rb', line 352

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



389
390
391
392
393
394
395
# File 'lib/mac_bacon.rb', line 389

def should(*args, &block)
  if Counter[:depth]==0
    it('should '+args.first,&block)
  else
    super(*args,&block)
  end
end

#specification_did_finish(spec) ⇒ Object



366
367
368
369
370
371
372
373
# File 'lib/mac_bacon.rb', line 366

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

Returns:

  • (Boolean)


426
# File 'lib/mac_bacon.rb', line 426

def throw?(*args, &block); block.throw?(*args); end

#wait(seconds = nil, &block) ⇒ Object



405
406
407
408
409
410
411
# File 'lib/mac_bacon.rb', line 405

def wait(seconds = nil, &block)
  if seconds
    current_specification.schedule_block(seconds, &block)
  else
    current_specification.postpone_block(&block)
  end
end

#wait_for_change(object_to_observe, key_path, timeout = 1, &block) ⇒ Object



417
418
419
# File 'lib/mac_bacon.rb', line 417

def wait_for_change(object_to_observe, key_path, timeout = 1, &block)
  current_specification.postpone_block_until_change(object_to_observe, key_path, timeout, &block)
end

#wait_max(timeout, &block) ⇒ Object



413
414
415
# File 'lib/mac_bacon.rb', line 413

def wait_max(timeout, &block)
  current_specification.postpone_block(timeout, &block)
end