I read an excellent post by John Lam, about his talk at TechEd 2008 on IronRuby
In the post he has screen shots of some ironRuby code for at simple unit-testing framework.
I tried looking around to find the code, but could not find it anywhere.
Hence I decided to type it in myself (reminds me of the days when you would get a hold of a C64 magazine and type in some example and three hours later see a baloon flying around your screen ...)
Anyway this is not code I made, this is John Lams work:
$examples = 0
$messages = []
class PositiveExpectation
def initialize(obj)
@obj = obj
end
def ==(other)
$examples += 1
if @obj != other
$messages << "Want #{@obj.inspect} got #{other.inspect}"
print "E"
else
print "OK"
end
end
end
class Object
def should
PositiveExpectation.new(self)
end
end
def it(description)
print "\n it #{description}: "
yield
end
def describe(description)
print "#{description}"
yield
puts "\nend\n"
end
at_exit do
puts "#{$messages.length} / #{$examples} failed"
if $messages.length > 0
puts "Failures: "
$messages.each { |m| puts "- #{m}"}
end
end