Class: MinitestBender::Results::Base
- Inherits:
-
Object
- Object
- MinitestBender::Results::Base
- Extended by:
- Forwardable
- Defined in:
- lib/minitest-bender/results/base.rb
Direct Known Subclasses
Constant Summary collapse
- NAME_PREFIX =
'♦'
Instance Attribute Summary collapse
-
#execution_order ⇒ Object
readonly
Returns the value of attribute execution_order.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #context ⇒ Object
- #file_path ⇒ Object
- #formatted_label ⇒ Object
- #formatted_label_and_time ⇒ Object
- #formatted_message ⇒ Object
- #formatted_name_with_context ⇒ Object
- #formatted_time ⇒ Object
-
#initialize(minitest_result) ⇒ Base
constructor
A new instance of Base.
- #name_sort_key ⇒ Object
- #rerun_line(padding) ⇒ Object
- #source_line_number ⇒ Object
-
#source_location ⇒ Object
credit where credit is due: minitest-line.
- #time_with_unit_and_padding_right ⇒ Object
- #to_icon ⇒ Object
Constructor Details
#initialize(minitest_result) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 |
# File 'lib/minitest-bender/results/base.rb', line 15 def initialize(minitest_result) @minitest_result = minitest_result @state = MinitestBender.states.fetch(minitest_result.result_code) @execution_order = state.add_result(self).size end |
Instance Attribute Details
#execution_order ⇒ Object (readonly)
Returns the value of attribute execution_order.
11 12 13 |
# File 'lib/minitest-bender/results/base.rb', line 11 def execution_order @execution_order end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
11 12 13 |
# File 'lib/minitest-bender/results/base.rb', line 11 def state @state end |
Instance Method Details
#context ⇒ Object
21 22 23 |
# File 'lib/minitest-bender/results/base.rb', line 21 def context @context ||= ResultContext.new(adjusted_class_name) end |
#file_path ⇒ Object
74 75 76 |
# File 'lib/minitest-bender/results/base.rb', line 74 def file_path @file_path ||= source_location[0] end |
#formatted_label ⇒ Object
42 43 44 |
# File 'lib/minitest-bender/results/base.rb', line 42 def formatted_label state.formatted_label end |
#formatted_label_and_time ⇒ Object
66 67 68 |
# File 'lib/minitest-bender/results/base.rb', line 66 def formatted_label_and_time "#{formatted_label} #{formatted_time}" end |
#formatted_message ⇒ Object
70 71 72 |
# File 'lib/minitest-bender/results/base.rb', line 70 def state.(self) end |
#formatted_name_with_context ⇒ Object
33 34 35 |
# File 'lib/minitest-bender/results/base.rb', line 33 def formatted_name_with_context "#{Colorizer.colorize(context, :normal)} #{name_prefix} #{Colorizer.colorize(name, :normal, :bold)}" end |
#formatted_time ⇒ Object
62 63 64 |
# File 'lib/minitest-bender/results/base.rb', line 62 def formatted_time Colorizer.colorize(time_with_unit_and_padding_right.rjust(6), :time) end |
#name_sort_key ⇒ Object
29 30 31 |
# File 'lib/minitest-bender/results/base.rb', line 29 def name_sort_key name end |
#rerun_line(padding) ⇒ Object
37 38 39 40 |
# File 'lib/minitest-bender/results/base.rb', line 37 def rerun_line(padding) unformatted = "Rerun: #{rerun_command}" "#{padding}#{Colorizer.colorize(unformatted, :tests)}" end |
#source_line_number ⇒ Object
78 79 80 |
# File 'lib/minitest-bender/results/base.rb', line 78 def source_line_number @source_line_number ||= source_location[1] end |
#source_location ⇒ Object
credit where credit is due: minitest-line
83 84 85 86 87 88 89 |
# File 'lib/minitest-bender/results/base.rb', line 83 def source_location if minitest_at_least_5_11? minitest_result.source_location else minitest_result.method(minitest_result.name).source_location rescue ['unknown', -1] end end |
#time_with_unit_and_padding_right ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/minitest-bender/results/base.rb', line 46 def time_with_unit_and_padding_right time_in_s = time case time_in_s when 0...1 sprintf('%.0fms ', time_in_s * 1000) when 1...10 sprintf('%.2fs ', time_in_s) when 10...100 sprintf('%.1fs ', time_in_s) when 100...10000 sprintf('%.0fs ', time_in_s) else sprintf('%.0fs', time_in_s) end end |
#to_icon ⇒ Object
25 26 27 |
# File 'lib/minitest-bender/results/base.rb', line 25 def to_icon state.colored_icon end |