diff options
author | Christian Neukirchen <chneukirchenÂÂ@gmail.com> | 2007-05-30 17:50:23 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchenÂÂ@gmail.com> | 2007-05-30 17:50:23 +0200 |
commit | 60f8cc954044f0f5031dc0d62ecd4afc6fa96ac5 (patch) | |
tree | 4e1881c6184528c1b7661a8de37fd7dfbd1c656f | |
parent | cfbc28a77e29e57d414306509870be28436ef923 (diff) | |
download | bacon-60f8cc954044f0f5031dc0d62ecd4afc6fa96ac5.tar.gz bacon-60f8cc954044f0f5031dc0d62ecd4afc6fa96ac5.tar.xz bacon-60f8cc954044f0f5031dc0d62ecd4afc6fa96ac5.zip |
Externalize spec/req handling
darcs-hash:20070530155023-67a46-586bfeaf53b3f306ff039af27103b1cc421d1e8f.gz
-rw-r--r-- | lib/bacon.rb | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb index 3641b0d..bda684d 100644 --- a/lib/bacon.rb +++ b/lib/bacon.rb @@ -10,6 +10,18 @@ module Bacon Counter[:failed], Counter[:error]] end + def self.handle_specification(name) + puts name + yield + puts + end + + def self.handle_requirement(description) + print "- #{description}" + error = yield + puts " [#{error}]" + end + class Error < RuntimeError attr_accessor :count_as @@ -25,9 +37,9 @@ module Bacon @after = [] @name = name - puts name - instance_eval(&block) - puts + Bacon.handle_specification(name) do + instance_eval(&block) + end end def before(&block); @before << block; end @@ -35,35 +47,36 @@ module Bacon def it(description, &block) Bacon::Counter[:requirements] += 1 - run_specify description, block + run_requirement description, block end - def run_specify(description, spec) - print "- #{description}" - - @before.each { |block| instance_eval(&block) } - instance_eval(&spec) - @after.each { |block| instance_eval(&block) } - rescue Object => e - if e.kind_of? Bacon::Error - puts " [#{e.count_as.to_s.upcase}]" - Bacon::Counter[e.count_as] += 1 - else - puts " [ERROR: #{e.class}]" - Bacon::Counter[:errors] += 1 + def run_requirement(description, spec) + Bacon.handle_requirement description do + begin + @before.each { |block| instance_eval(&block) } + instance_eval(&spec) + @after.each { |block| instance_eval(&block) } + rescue Object => e + ErrorLog << "#{e.class}: #{e.message}\n" + e.backtrace.find_all { |line| line !~ /\/bacon.rb:\d+/ }. + each_with_index { |line, i| + ErrorLog << "\t#{line}#{i==0?": "+@name + " - "+description:""}\n" + } + ErrorLog << "\n" + + if e.kind_of? Bacon::Error + Bacon::Counter[e.count_as] += 1 + e.count_as.to_s.upcase + else + Bacon::Counter[:errors] += 1 + "ERROR: #{e.class}" + end + else + "" + end end - - ErrorLog << "#{e.class}: #{e.message}\n" - e.backtrace.find_all { |line| line !~ /\/bacon.rb:\d+/ }. - each_with_index { |line, i| - ErrorLog << "\t#{line}#{i==0?": "+@name + " - "+description:""}\n" - } - ErrorLog << "\n" - else - puts end end - end |