Class: PryTest::TestWrapper
- Inherits:
-
Object
- Object
- PryTest::TestWrapper
- Includes:
- MonitorMixin
- Defined in:
- lib/pry-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.
-
#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.
-
#duration ⇒ Object
Rounded duration.
-
#failed_asserts ⇒ Object
Returns a list of all failed asserts.
-
#initialize(test_class, desc) { ... } ⇒ TestWrapper
constructor
Constructor.
-
#invoke(formatter, options = {}) ⇒ Object
Runs the test code.
-
#invoked? ⇒ Boolean
Indicates if this test has been invoked.
-
#passed? ⇒ Boolean
Indicates if this test passed.
-
#refute(value) ⇒ Object
A basic refute method to be used within tests.
Constructor Details
#initialize(test_class, desc) { ... } ⇒ TestWrapper
Constructor.
15 16 17 18 19 20 21 |
# File 'lib/pry-test/test_wrapper.rb', line 15 def initialize(test_class, desc, &block) super() # inits MonitorMixin @test_class = test_class @desc = desc @asserts = [] create_method(:test, &block) end |
Instance Attribute Details
#asserts ⇒ Object (readonly)
Returns the value of attribute asserts.
9 10 11 |
# File 'lib/pry-test/test_wrapper.rb', line 9 def asserts @asserts end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
9 10 11 |
# File 'lib/pry-test/test_wrapper.rb', line 9 def desc @desc end |
#test_class ⇒ Object (readonly)
Returns the value of attribute test_class.
9 10 11 |
# File 'lib/pry-test/test_wrapper.rb', line 9 def test_class @test_class end |
Instance Method Details
#after ⇒ Object
33 |
# File 'lib/pry-test/test_wrapper.rb', line 33 def after; end |
#assert(value) ⇒ Object
A basic assert method to be used within tests.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pry-test/test_wrapper.rb', line 61 def assert(value) info = assert_info(value, caller_locations.first) asserts << info.merge(:value => value) if !value Pry.start unless @options[:disable_pry] # TODO: I don't really like the coupling to the runner here PryTest::Runner.terminate if @options[:fail_fast] end value end |
#before ⇒ Object
callback stubs
32 |
# File 'lib/pry-test/test_wrapper.rb', line 32 def before; end |
#create_method(name) { ... } ⇒ Object
Creates a method on this instance.
26 27 28 29 |
# File 'lib/pry-test/test_wrapper.rb', line 26 def create_method(name, &block) eigen = class << self; self; end eigen.send(:define_method, name, &block) end |
#duration ⇒ Object
Rounded duration.
108 109 110 111 |
# File 'lib/pry-test/test_wrapper.rb', line 108 def duration return nil if @duration.nil? (@duration * 10**4).ceil.to_f / 10**4 end |
#failed_asserts ⇒ Object
Returns a list of all failed asserts.
103 104 105 |
# File 'lib/pry-test/test_wrapper.rb', line 103 def failed_asserts asserts.select { |a| !a[:value] } end |
#invoke(formatter, options = {}) ⇒ Object
Runs the test code.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pry-test/test_wrapper.rb', line 38 def invoke(formatter, ={}) @formatter = formatter @options = @formatter.before_test(self) start = Time.now before test @invoked = true @duration = Time.now - start after @formatter.after_test(self) unless asserts.empty? end |
#invoked? ⇒ Boolean
Indicates if this test has been invoked.
91 92 93 |
# File 'lib/pry-test/test_wrapper.rb', line 91 def invoked? !!@invoked end |
#passed? ⇒ Boolean
Indicates if this test passed.
96 97 98 99 100 |
# File 'lib/pry-test/test_wrapper.rb', line 96 def passed? return false unless invoked? return true if asserts.empty? asserts.map{ |a| !!a[:value] }.uniq == [true] end |
#refute(value) ⇒ Object
A basic refute method to be used within tests.
85 86 87 |
# File 'lib/pry-test/test_wrapper.rb', line 85 def refute(value) assert !value end |