Sha256: 67f00b9550d4a5dfc8e83b4ec0d12bd588cb5156780b805df68791c6d0923512
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
require "test/unit" # Test::Unit loads a default test if the suite is empty, and the only # purpose of that test is to fail. As having empty contexts is a common # practice, we decided to overwrite TestSuite#empty? in order to # allow them. Having a failure when no tests have been defined seems # counter-intuitive. class Test::Unit::TestSuite def empty? false end end # We added setup, test and context as class methods, and the instance # method setup now iterates on the setup blocks. Note that all setup # blocks must be defined with the block syntax. Adding a setup instance # method defeats the purpose of this library. class Test::Unit::TestCase def self.setup(&block) setup_blocks << block end def setup self.class.setup_blocks.each do |block| instance_eval(&block) end end def self.context(name, &block) subclass = Class.new(self.superclass) subclass.setup_blocks.unshift(*setup_blocks) subclass.class_eval(&block) const_set(context_name(name), subclass) end def self.test(name, &block) define_method(test_name(name), &block) end private def self.setup_blocks @setup_blocks ||= [] end def self.context_name(name) "#{name.gsub(/(^| )(\w)/) { $2.upcase }}Test".to_sym end def self.test_name(name) "test_#{name.gsub(/\s+/,'_')}".to_sym end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
citrusbyte-contest-0.0.3 | lib/contest.rb |