mirror of
https://github.com/michaeldv/pit.git
synced 2025-12-11 08:53:01 +00:00
First incarnation of Ruby-based pit test suite
This commit is contained in:
59
test/pit_should.rb
Normal file
59
test/pit_should.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
class Hand < RuntimeError
|
||||
def oops(msg)
|
||||
puts "\n#{msg} in #{self.backtrace[1].sub(':', ' line ')}"
|
||||
end
|
||||
end
|
||||
|
||||
class String
|
||||
def should
|
||||
def self.equal(expected)
|
||||
raise Hand unless self == expected
|
||||
print '.'
|
||||
rescue => e
|
||||
e.oops "equal failed: #{self} != #{expected}"
|
||||
end
|
||||
|
||||
def self.match(expected)
|
||||
raise Hand unless self =~ expected
|
||||
print '.'
|
||||
rescue => e
|
||||
e.oops "match failed: #{self} !~ /#{expected.source}/"
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def should_not
|
||||
def self.equal(expected)
|
||||
raise Hand unless self != expected
|
||||
print '.'
|
||||
rescue => e
|
||||
e.oops "not equal failed: #{self} == #{expected}"
|
||||
end
|
||||
|
||||
def self.match(expected)
|
||||
raise Hand unless self !~ expected
|
||||
print '.'
|
||||
rescue => e
|
||||
e.oops "not match failed: #{self} =~ /#{expected.source}/"
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
"123".should.equal "123"
|
||||
"123".should.equal "321"
|
||||
|
||||
"123".should_not.equal "321"
|
||||
"123".should_not.equal "123"
|
||||
|
||||
"abc".should.match /B/i
|
||||
"abc".should.match /xyz/
|
||||
|
||||
"abc".should_not.match /xyz/
|
||||
"abc".should_not.match /abc/
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user