Class: MicroTest::TestWrapper
- Inherits:
-
Object
- Object
- MicroTest::TestWrapper
- Defined in:
- lib/micro_test/test_wrapper.rb
Overview
A wrapper class for individual tests. Exists for the purpose of isolating the test method so it can run in its own thread.
Instance Attribute Summary collapse
-
#asserts ⇒ Object
readonly
Returns the value of attribute asserts.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#test_class ⇒ Object
readonly
Returns the value of attribute test_class.
Instance Method Summary collapse
- #after ⇒ Object
-
#assert(value) ⇒ Object
A basic assert method to be used within tests.
-
#before ⇒ Object
callback stubs.
-
#create_method(name) { ... } ⇒ Object
Creates a method on this instance.
-
#failed_asserts ⇒ Object
Returns a list of all failed asserts.
-
#finished? ⇒ Boolean
Indicates if this test has finished running.
-
#initialize(test_class, desc) { ... } ⇒ TestWrapper
constructor
Constructor.
-
#invoke(formatter, options = {}) ⇒ Object
Runs the test code.
-
#passed? ⇒ Boolean
Indicates if this test passed.
-
#reset ⇒ Object
Resets this test in preparation for a clean test run.
Constructor Details
#initialize(test_class, desc) { ... } ⇒ TestWrapper
Constructor.
12 13 14 15 16 17 |
# File 'lib/micro_test/test_wrapper.rb', line 12 def initialize(test_class, desc, &block) @test_class = test_class @desc = desc create_method(:test, &block) reset end |
Instance Attribute Details
#asserts ⇒ Object (readonly)
Returns the value of attribute asserts.
6 7 8 |
# File 'lib/micro_test/test_wrapper.rb', line 6 def asserts @asserts end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
6 7 8 |
# File 'lib/micro_test/test_wrapper.rb', line 6 def desc @desc end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/micro_test/test_wrapper.rb', line 6 def duration @duration end |
#test_class ⇒ Object (readonly)
Returns the value of attribute test_class.
6 7 8 |
# File 'lib/micro_test/test_wrapper.rb', line 6 def test_class @test_class end |
Instance Method Details
#after ⇒ Object
29 |
# File 'lib/micro_test/test_wrapper.rb', line 29 def after; end |
#assert(value) ⇒ Object
A basic assert method to be used within tests.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/micro_test/test_wrapper.rb', line 58 def assert(value) @asserts << assert_info(caller).merge(:value => value) if !value binding.pry(:quiet => true) if @options[:pry] # I don't really like the coupling to the runner here MicroTest::Runner.exit = true if @options[:fail_fast] end value end |
#before ⇒ Object
callback stubs
28 |
# File 'lib/micro_test/test_wrapper.rb', line 28 def before; end |
#create_method(name) { ... } ⇒ Object
Creates a method on this instance.
22 23 24 25 |
# File 'lib/micro_test/test_wrapper.rb', line 22 def create_method(name, &block) eigen = class << self; self; end eigen.send(:define_method, name, &block) end |
#failed_asserts ⇒ Object
Returns a list of all failed asserts.
85 86 87 88 |
# File 'lib/micro_test/test_wrapper.rb', line 85 def failed_asserts return [] if passed? @asserts.select { |a| !a[:value] } end |
#finished? ⇒ Boolean
Indicates if this test has finished running.
73 74 75 |
# File 'lib/micro_test/test_wrapper.rb', line 73 def finished? !@duration.nil? end |
#invoke(formatter, options = {}) ⇒ Object
Runs the test code.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/micro_test/test_wrapper.rb', line 34 def invoke(formatter, ={}) reset @formatter = formatter @options = @formatter.before_test(self) start = Time.now before test @invoked = true after @duration = Time.now - start @formatter.after_test(self) end |
#passed? ⇒ Boolean
Indicates if this test passed.
78 79 80 81 82 |
# File 'lib/micro_test/test_wrapper.rb', line 78 def passed? return true if !@invoked || @asserts.empty? return false if @asserts.empty? @asserts.map{ |a| !!a[:value] }.uniq == [true] end |
#reset ⇒ Object
Resets this test in preparation for a clean test run.
91 92 93 94 95 |
# File 'lib/micro_test/test_wrapper.rb', line 91 def reset @invoked = false @asserts = [] @duration = nil end |