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 136 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 151 def after(&block); @after << block; end
before(&block)
click to toggle source
# File lib/bacon.rb, line 150 def before(&block); @before << block; end
behaves_like(*names)
click to toggle source
# File lib/bacon.rb, line 153 def behaves_like(*names) names.each { |name| instance_eval(&Shared[name]) } end
change?(&block)
click to toggle source
# File lib/bacon.rb, line 230 def change?(&block); lambda{}.change?(&block); end
describe(*args, &block)
click to toggle source
# File lib/bacon.rb, line 218 def describe(*args, &block) context = Bacon::Context.new(args.join(' '), &block) (parent_context = self).methods(false).each {|e| class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)} } @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 157 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 228 def raise?(*args, &block); block.raise?(*args); end
run()
click to toggle source
# File lib/bacon.rb, line 142 def run return unless name =~ RestrictContext Counter[:context_depth] += 1 Bacon.handle_specification(name) { instance_eval(&block) } Counter[:context_depth] -= 1 self end
run_requirement(description, spec)
click to toggle source
# File lib/bacon.rb, line 172 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 164 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 229 def throw?(*args, &block); block.throw?(*args); end