Class: Loupe::Test
- Inherits:
-
Object
- Object
- Loupe::Test
- Defined in:
- lib/loupe/test.rb
Overview
Test
The parent class for tests. Tests should inherit from this class in order to be run.
Instance Attribute Summary collapse
- #color ⇒ Loupe::Color readonly
- #file ⇒ String readonly
- #line_number ⇒ Integer readonly
- #name ⇒ String readonly
- #reporter ⇒ Loupe::Reporter readonly
Class Method Summary collapse
- .add_line_number(number) ⇒ void
- .classes ⇒ Hash<Class, Array<Integer>>
- .inherited(test_class) ⇒ void
-
.run(method_name, options = {}) ⇒ Loupe::Reporter
Run a single test with designated by ‘method_name`.
- .test_list ⇒ Array<Symbol>
Instance Method Summary collapse
- #after ⇒ void
- #before ⇒ void
- #initialize(reporter, method_name, options = {}) ⇒ Loupe::Test constructor
-
#run ⇒ void
Run the instantiated test, which corresponds to a single method.
Constructor Details
#initialize(reporter, method_name, options = {}) ⇒ Loupe::Test
111 112 113 114 115 116 117 |
# File 'lib/loupe/test.rb', line 111 def initialize(reporter, method_name, = {}) @reporter = reporter @color = Color.new([:color]) @name = method_name @method = method(method_name) @file, @line_number = @method.source_location end |
Instance Attribute Details
#file ⇒ String (readonly)
62 63 64 |
# File 'lib/loupe/test.rb', line 62 def file @file end |
#line_number ⇒ Integer (readonly)
59 60 61 |
# File 'lib/loupe/test.rb', line 59 def line_number @line_number end |
#name ⇒ String (readonly)
68 69 70 |
# File 'lib/loupe/test.rb', line 68 def name @name end |
#reporter ⇒ Loupe::Reporter (readonly)
56 57 58 |
# File 'lib/loupe/test.rb', line 56 def reporter @reporter end |
Class Method Details
.add_line_number(number) ⇒ void
This method returns an undefined value.
77 78 79 |
# File 'lib/loupe/test.rb', line 77 def self.add_line_number(number) classes[@current_class] << number end |
.classes ⇒ Hash<Class, Array<Integer>>
71 72 73 |
# File 'lib/loupe/test.rb', line 71 def self.classes @classes ||= {} end |
.inherited(test_class) ⇒ void
This method returns an undefined value.
83 84 85 86 87 |
# File 'lib/loupe/test.rb', line 83 def self.inherited(test_class) @current_class = test_class classes[test_class] = [] super end |
.run(method_name, options = {}) ⇒ Loupe::Reporter
Run a single test with designated by ‘method_name`
99 100 101 102 103 104 105 |
# File 'lib/loupe/test.rb', line 99 def self.run(method_name, = {}) reporter = [:interactive] ? PagedReporter.new() : PlainReporter.new() new(reporter, method_name, ).run reporter rescue Expectation::ExpectationFailed reporter end |
.test_list ⇒ Array<Symbol>
90 91 92 |
# File 'lib/loupe/test.rb', line 90 def self.test_list instance_methods(false).grep(/^test.*/) end |
Instance Method Details
#after ⇒ void
This method returns an undefined value.
134 |
# File 'lib/loupe/test.rb', line 134 def after; end |
#before ⇒ void
This method returns an undefined value.
131 |
# File 'lib/loupe/test.rb', line 131 def before; end |
#run ⇒ void
This method returns an undefined value.
Run the instantiated test, which corresponds to a single method.
122 123 124 125 126 127 128 |
# File 'lib/loupe/test.rb', line 122 def run @reporter.increment_test_count before @method.call after @reporter.increment_success_count end |