class Bacon::TestUnitOutput::TapOutput::KnockOutput::Context

Attributes

block[R]
name[R]

Public Class Methods

new(name, &block) click to toggle source
# File lib/bacon.rb, line 131
def initialize(name, &block)
  @name = name
  @before, @after = [], []
  @block = block
end

Public Instance Methods

after(&block) click to toggle source
# File lib/bacon.rb, line 144
def after(&block);  @after << block; end
before(&block) click to toggle source
# File lib/bacon.rb, line 143
def before(&block); @before << block; end
behaves_like(*names) click to toggle source
# File lib/bacon.rb, line 146
def behaves_like(*names)
  names.each { |name| instance_eval(&Shared[name]) }
end
change?(*args, &block) click to toggle source
# File lib/bacon.rb, line 220
def change?(*args, &block); block.change?(*args); end
describe(*args, &block) click to toggle source
# File lib/bacon.rb, line 211
def describe(*args, &block)
  context = Bacon::Context.new(args.join(' '), &block)
  @before.each { |b| context.before(&b) }
  @after.each { |b| context.after(&b) }
  context.run
end
it(description, &block) click to toggle source
# File lib/bacon.rb, line 150
def it(description, &block)
  return  unless description =~ RestrictName
  block ||= lambda { should.flunk "not implemented" }
  Counter[:specifications] += 1
  run_requirement description, block
end
raise?(*args, &block) click to toggle source
# File lib/bacon.rb, line 218
def raise?(*args, &block); block.raise?(*args); end
run() click to toggle source
# File lib/bacon.rb, line 137
def run
  return  unless name =~ RestrictContext
  Bacon.handle_specification(name) { instance_eval(&block) }
  self
end
run_requirement(description, spec) click to toggle source
# File lib/bacon.rb, line 165
def run_requirement(description, spec)
  Bacon.handle_requirement description do
    begin
      Counter[:depth] += 1
      rescued = false
      begin
        @before.each { |block| instance_eval(&block) }
        prev_req = Counter[:requirements]
        instance_eval(&spec)
      rescue Object => e
        rescued = true
        raise e
      ensure
        if Counter[:requirements] == prev_req and not rescued
          raise Error.new(:missing,
                          "empty specification: #{@name} #{description}")
        end
        begin
          @after.each { |block| instance_eval(&block) }
        rescue Object => e
          raise e  unless rescued
        end
      end
    rescue Object => e
      ErrorLog << "#{e.class}: #{e.message}\n"
      e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ }.
        each_with_index { |line, i|
        ErrorLog << "\t#{line}#{i==0 ? ": #@name - #{description}" : ""}\n"
      }
      ErrorLog << "\n"

      if e.kind_of? Error
        Counter[e.count_as] += 1
        e.count_as.to_s.upcase
      else
        Counter[:errors] += 1
        "ERROR: #{e.class}"
      end
    else
      ""
    ensure
      Counter[:depth] -= 1
    end
  end
end
should(*args, &block) click to toggle source
Calls superclass method
# File lib/bacon.rb, line 157
def should(*args, &block)
  if Counter[:depth]==0
    it('should '+args.first,&block)
  else
    super(*args,&block)
  end
end
throw?(*args, &block) click to toggle source
# File lib/bacon.rb, line 219
def throw?(*args, &block); block.throw?(*args); end