Class: Bacon::Context
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
- #behaves_like(*names) ⇒ Object
- #change?(*args, &block) ⇒ Boolean
-
#initialize(name, &block) ⇒ Context
constructor
A new instance of Context.
- #it(description, &block) ⇒ Object
- #raise?(*args, &block) ⇒ Boolean
- #run_requirement(description, spec) ⇒ Object
- #throw?(*args, &block) ⇒ Boolean
Constructor Details
#initialize(name, &block) ⇒ Context
Returns a new instance of Context.
108 109 110 111 112 113 114 |
# File 'lib/bacon.rb', line 108 def initialize(name, &block) @name = name @before, @after = [], [] return unless name =~ RestrictContext Bacon.handle_specification(name) { instance_eval(&block) } end |
Instance Method Details
#after(&block) ⇒ Object
117 |
# File 'lib/bacon.rb', line 117 def after(&block); @after << block; end |
#before(&block) ⇒ Object
116 |
# File 'lib/bacon.rb', line 116 def before(&block); @before << block; end |
#behaves_like(*names) ⇒ Object
119 120 121 |
# File 'lib/bacon.rb', line 119 def behaves_like(*names) names.each { |name| instance_eval(&Shared[name]) } end |
#change?(*args, &block) ⇒ Boolean
161 |
# File 'lib/bacon.rb', line 161 def change?(*args, &block); block.change?(*args); end |
#it(description, &block) ⇒ Object
123 124 125 126 127 |
# File 'lib/bacon.rb', line 123 def it(description, &block) return unless description =~ RestrictName Counter[:specifications] += 1 run_requirement description, block end |
#raise?(*args, &block) ⇒ Boolean
159 |
# File 'lib/bacon.rb', line 159 def raise?(*args, &block); block.raise?(*args); end |
#run_requirement(description, spec) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/bacon.rb', line 129 def run_requirement(description, spec) Bacon.handle_requirement description do begin Counter[:depth] += 1 @before.each { |block| instance_eval(&block) } instance_eval(&spec) @after.each { |block| instance_eval(&block) } rescue Object => e 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 ? ": #@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 |
#throw?(*args, &block) ⇒ Boolean
160 |
# File 'lib/bacon.rb', line 160 def throw?(*args, &block); block.throw?(*args); end |