lib/lemon/test/suite.rb in lemon-0.5 vs lib/lemon/test/suite.rb in lemon-0.6
- old
+ new
@@ -1,9 +1,10 @@
module Lemon
module Test
require 'lemon/test/case'
+ require 'lemon/dsl'
# Test Suites encapsulate a set of test cases.
#
class Suite
@@ -17,35 +18,40 @@
attr :before_clauses
# List of post-test procedures that apply suite-wide.
attr :after_clauses
- # List of concern procedures that apply suite-wide.
- attr :when_clauses
-
#
- def initialize(*tests)
+ def initialize(*files)
@testcases = []
@before_clauses = {}
@after_clauses = {}
@when_clauses = {}
+ loadfiles(*files)
+ end
+
+ #
+ def loadfiles(*files)
+ Lemon.suite = self
+
# directories glob *.rb files
- tests = tests.flatten.map do |file|
+ files = files.flatten.map do |file|
if File.directory?(file)
Dir[File.join(file, '**', '*.rb')]
else
file
end
end.flatten.uniq
- @test_files = tests
-
- tests.each do |file|
+ files.each do |file|
#file = File.expand_path(file)
- instance_eval(File.read(file), file)
+ #instance_eval(File.read(file), file)
+ load(file)
end
+
+ return Lemon.suite
end
# Load a helper. This method must be used when loading local
# suite support. The usual #require or #load can only be used
# for extenal support libraries (such as a test mock framework).
@@ -73,51 +79,33 @@
#
alias_method :TestCase, :Case
#
- alias_method :testcase, :Case
+ #alias_method :testcase, :Case
# Define a pre-test procedure to apply suite-wide.
def Before(match=nil, &block)
@before_clauses[match] = block #<< Advice.new(match, &block)
end
- alias_method :before, :Before
+ #alias_method :before, :Before
# Define a post-test procedure to apply suite-wide.
def After(match=nil, &block)
@after_clauses[match] = block #<< Advice.new(match, &block)
end
- alias_method :after, :After
+ #alias_method :after, :After
# Define a concern procedure to apply suite-wide.
def When(match=nil, &block)
@when_clauses[match] = block #<< Advice.new(match, &block)
end
# Iterate through this suite's test cases.
def each(&block)
@testcases.each(&block)
- end
-
- # FIXME: This is a BIG FAT HACK! For the life of me I cannot find
- # a way to resolve module constants included in the test cases.
- # Becuase of closure, the constant lookup goes through here, and not
- # the Case singleton class. So to work around wemust note each test
- # before it is run, and reroute the missing constants.
- #
- # This sucks and it is not thread safe. If anyone know how to fix,
- # please let me know. See Unit#call for the other end of this hack.
-
- def self.const_missing(name)
- (class << @@test_stack.last.testcase; self; end).const_get(name)
- end
-
- # Get current running test. Used for the BIG FAT HACK.
- def test_stack
- @@test_stack ||= []
end
end
end