From 77e72daef132db2e8a63d24525f571920cc2f9e0 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Mon, 7 Jan 2008 20:08:40 +0100 Subject: Tighten code darcs-hash:20080107190840-4fc50-f747c8c40afb24b4f2f7d2cb9b711560c59df84f.gz --- lib/bacon.rb | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/lib/bacon.rb b/lib/bacon.rb index e1b04cc..09750a9 100644 --- a/lib/bacon.rb +++ b/lib/bacon.rb @@ -53,9 +53,7 @@ module Bacon end module TestUnitOutput - def handle_specification(name) - yield - end + def handle_specification(name) yield end def handle_requirement(description) error = yield @@ -74,9 +72,7 @@ module Bacon end module TapOutput - def handle_specification(name) - yield - end + def handle_specification(name) yield end def handle_requirement(description) ErrorLog.replace "" @@ -110,23 +106,18 @@ module Bacon class Context def initialize(name, &block) - @before = [] - @after = [] @name = name + @before, @after = [], [] return unless name =~ RestrictContext - Bacon.handle_specification(name) do - instance_eval(&block) - end + Bacon.handle_specification(name) { instance_eval(&block) } end def before(&block); @before << block; end def after(&block); @after << block; end def behaves_like(*names) - names.each do |name| - instance_eval(&Shared[name]) - end + names.each { |name| instance_eval(&Shared[name]) } end def it(description, &block) @@ -190,7 +181,7 @@ class Proc exceptions << RuntimeError if exceptions.empty? call - # Only to work in 1.9.0, rescue with splat doesn't work there right now + # Only to work in 1.9.0, rescue with splat doesn't work there right now rescue Object => e case e when *exceptions @@ -226,21 +217,14 @@ end class Object - def should(*args, &block) - Should.new(self).be(*args, &block) - end + def should(*args, &block) Should.new(self).be(*args, &block) end end module Kernel private - def describe(name, &block) - Bacon::Context.new(name, &block) - end - - def shared(name, &block) - Bacon::Shared[name] = block - end + def describe(name, &block) Bacon::Context.new(name, &block) end + def shared(name, &block) Bacon::Shared[name] = block end end @@ -300,15 +284,12 @@ class Should desc << @object.inspect << "." << name.to_s desc << "(" << args.map{|x|x.inspect}.join(", ") << ") failed" - satisfy(desc) { |x| - x.__send__(name, *args, &block) - } + satisfy(desc) { |x| x.__send__(name, *args, &block) } end - def equal(value); self == value; end - def match(value); self =~ value; end - - def identical_to(value); self.equal? value; end + def equal(value) self == value end + def match(value) self =~ value end + def identical_to(value) self.equal? value end alias same_as identical_to def flunk(reason="Flunked") -- cgit 1.4.1