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
- #should(*args, &block) ⇒ 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/vendor/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/vendor/bacon.rb', line 117 def after(&block); @after << block; end |
#before(&block) ⇒ Object
116 |
# File 'lib/vendor/bacon.rb', line 116 def before(&block); @before << block; end |
#behaves_like(*names) ⇒ Object
119 120 121 |
# File 'lib/vendor/bacon.rb', line 119 def behaves_like(*names) names.each { |name| instance_eval(&Shared[name]) } end |
#change?(*args, &block) ⇒ Boolean
186 |
# File 'lib/vendor/bacon.rb', line 186 def change?(*args, &block); block.change?(*args); end |
#it(description, &block) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/vendor/bacon.rb', line 123 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) ⇒ Boolean
184 |
# File 'lib/vendor/bacon.rb', line 184 def raise?(*args, &block); block.raise?(*args); end |
#run_requirement(description, spec) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/vendor/bacon.rb', line 138 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.}\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) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/vendor/bacon.rb', line 130 def should(*args, &block) if Counter[:depth]==0 it('should '+args.first,&block) else super(*args,&block) end end |
#throw?(*args, &block) ⇒ Boolean
185 |
# File 'lib/vendor/bacon.rb', line 185 def throw?(*args, &block); block.throw?(*args); end |