4 require 'test/unit/assertions'
6 class FillMeInError < StandardError
9 def __(value="FILL ME IN")
17 def ___(value=FillMeInError)
31 attr_reader :failure, :failed_test
33 AssertionError = Test::Unit::AssertionFailedError
44 puts " #{test.name} has expanded your awareness."
46 puts " #{test.name} has damaged your karma."
48 @failure = test.failure
58 failure.is_a?(AssertionError)
64 puts "You have not yet reached enlightenment ..."
67 puts "Please meditate on the following code:"
69 puts find_interesting_lines(failure.backtrace)
71 puts failure.backtrace
78 def find_interesting_lines(backtrace)
79 backtrace.reject { |line|
80 line =~ /test\/unit\/|edgecase\.rb/
84 # Hat's tip to Ara T. Howard for the zen statements from his
85 # metakoans Ruby Quiz (http://rubyquiz.com/quiz67.html)
86 def say_something_zenlike
89 puts "Mountains are again merely mountains"
91 case (@pass_count % 10)
93 puts "mountains are merely mountains"
95 puts "learn the rules so you know how to break them properly"
97 puts "remember that silence is sometimes the best answer"
99 puts "sleep is the best meditation"
101 puts "when you lose, don't lose the lesson"
103 puts "things are not what they appear to be: nor are they otherwise"
110 include Test::Unit::Assertions
112 attr_reader :name, :failure
133 # Class methods for the EdgeCase test suite.
135 def inherited(subclass)
136 subclasses << subclass
139 def method_added(name)
140 testmethods << name unless tests_disabled?
143 def run_tests(accumulator)
145 puts "Thinking #{self}"
146 testmethods.each do |m|
147 self.run_test(m, accumulator) if Koan.test_pattern =~ m.to_s
151 def run_test(method, accumulator)
152 test = self.new(method)
156 rescue StandardError => ex
161 rescue StandardError => ex
162 test.failed(ex) if test.passed?
165 accumulator.accumulate(test)
168 def end_of_enlightenment
169 @tests_disabled = true
172 def command_line(args)
176 @test_pattern = Regexp.new($1)
178 @test_pattern = Regexp.new(Regexp.quote($1))
183 fail "Unknown command line argument '#{arg}'"
189 # Lazy initialize list of subclasses
194 # Lazy initialize list of test methods.
200 @tests_disabled ||= false
204 @test_pattern ||= /^test_/
212 EdgeCase::Koan.command_line(ARGV)
213 zen_master = EdgeCase::Sensei.new
214 catch(:edgecase_exit) {
215 EdgeCase::Koan.subclasses.each do |sc|
216 sc.run_tests(zen_master)