Class: Testy::Test
- Inherits:
-
Object
- Object
- Testy::Test
- Defined in:
- lib/testy.rb
Defined Under Namespace
Classes: BadResult, OrderedHash, Result
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tests ⇒ Object
Returns the value of attribute tests.
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Test
constructor
A new instance of Test.
- #run(port = STDOUT) ⇒ Object
- #test(name, &block) ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ Test
Returns a new instance of Test.
46 47 48 49 50 51 |
# File 'lib/testy.rb', line 46 def initialize(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} @name = args.first || [:name] || ['name'] @tests = OrderedHash.new @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
44 45 46 |
# File 'lib/testy.rb', line 44 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
42 43 44 |
# File 'lib/testy.rb', line 42 def name @name end |
#tests ⇒ Object
Returns the value of attribute tests.
43 44 45 |
# File 'lib/testy.rb', line 43 def tests @tests end |
Instance Method Details
#run(port = STDOUT) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/testy.rb', line 57 def run port = STDOUT instance_eval(&@block) if @block report = OrderedHash.new failures = 0 tests.each do |name, block| result = Result.new report[name] = begin block.call(result) raise BadResult, name unless result.ok? {'success' => result.actual} rescue Object => e failures += 1 failure = OrderedHash.new unless e.is_a?(BadResult) error = OrderedHash.new error['class'] = e.class.name error['message'] = e..to_s error['backtrace'] = e.backtrace||[] failure['error'] = error end failure['expect'] = result.expect failure['actual'] = result.actual {'failure' => failure} end end port << {name => report}.to_yaml failures end |
#test(name, &block) ⇒ Object
53 54 55 |
# File 'lib/testy.rb', line 53 def test(name, &block) @tests[name.to_s] = block end |