Class: Cucumber::Formatter::Pretty
- Inherits:
-
Object
- Object
- Cucumber::Formatter::Pretty
- Includes:
- Console, Io, Gherkin::Formatter::Escaping, FileUtils
- Defined in:
- lib/cucumber/formatter/pretty.rb
Overview
The formatter used for --format pretty (the default formatter).
This formatter prints the result of the feature executions to plain text - exactly how they were parsed.
If the output is STDOUT (and not a file), there are bright colours to watch too.
Constant Summary
Constants included from ANSIColor
Constants included from Term::ANSIColor
Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP
Instance Method Summary collapse
- #bind_events(config) ⇒ Object
-
#initialize(config) ⇒ Pretty
constructor
A new instance of Pretty.
- #on_attach_called(event) ⇒ Object
- #on_gherkin_source_read(event) ⇒ Object
- #on_step_activated(event) ⇒ Object
- #on_test_case_finished(event) ⇒ Object
- #on_test_case_started(event) ⇒ Object
- #on_test_run_finished(_event) ⇒ Object
- #on_test_step_finished(event) ⇒ Object
- #on_test_step_started(event) ⇒ Object
Methods included from Gherkin::Formatter::Escaping
Methods included from Io
ensure_dir, ensure_file, ensure_io, included, io?, url?
Methods included from Console
#collect_snippet_data, #collect_undefined_parameter_type_names, #do_print_passing_wip, #do_print_profile_information, #do_print_snippets, #do_print_undefined_parameter_type_snippet, #exception_message_string, #format_step, #format_string, #indent, #linebreaks, #print_element_messages, #print_elements, #print_exception, #print_passing_wip, #print_profile_information, #print_snippets, #print_statistics
Methods included from ANSIColor
apply_custom_colors, #cukes, #green_cukes, #red_cukes, #yellow_cukes
Methods included from Term::ANSIColor
#attributes, included, #uncolored
Methods included from Duration
Constructor Details
#initialize(config) ⇒ Pretty
Returns a new instance of Pretty.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cucumber/formatter/pretty.rb', line 32 def initialize(config) @io = ensure_io(config.out_stream, config.error_stream) @config = config @options = config.to_hash @total_duration = 0 @exceptions = [] @gherkin_sources = {} @step_matches = {} @ast_lookup = AstLookup.new(config) @counts = ConsoleCounts.new(config) @issues = ConsoleIssues.new(config, @ast_lookup) @first_feature = true @current_feature_uri = '' @current_scenario_outline = nil @current_examples = nil @current_test_case = nil @in_scenario_outline = false @print_background_steps = false @test_step_output = [] @passed_test_cases = [] @source_indent = 0 @next_comment_to_be_printed = 0 bind_events(config) end |
Instance Method Details
#bind_events(config) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cucumber/formatter/pretty.rb', line 58 def bind_events(config) config.on_event :gherkin_source_read, &method(:on_gherkin_source_read) config.on_event :step_activated, &method(:on_step_activated) config.on_event :test_case_started, &method(:on_test_case_started) config.on_event :test_step_started, &method(:on_test_step_started) config.on_event :test_step_finished, &method(:on_test_step_finished) config.on_event :test_case_finished, &method(:on_test_case_finished) config.on_event :test_run_finished, &method(:on_test_run_finished) config.on_event :undefined_parameter_type, &method(:collect_undefined_parameter_type_names) config.on_event :attach_called, &method(:on_attach_called) end |
#on_attach_called(event) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/cucumber/formatter/pretty.rb', line 141 def on_attach_called(event) return unless event.media_type == 'text/x.cucumber.log+plain' if event.filename @test_step_output.push("#{event.filename}: #{event.src}") else @test_step_output.push(event.src) end end |
#on_gherkin_source_read(event) ⇒ Object
70 71 72 |
# File 'lib/cucumber/formatter/pretty.rb', line 70 def on_gherkin_source_read(event) @gherkin_sources[event.path] = event.body end |
#on_step_activated(event) ⇒ Object
74 75 76 |
# File 'lib/cucumber/formatter/pretty.rb', line 74 def on_step_activated(event) @step_matches[event.test_step.to_s] = event.step_match end |
#on_test_case_finished(event) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/cucumber/formatter/pretty.rb', line 121 def on_test_case_finished(event) @total_duration += DurationExtractor.new(event.result).result_duration @passed_test_cases << event.test_case if config.wip? && event.result.passed? if in_scenario_outline && ![:expand] print_row_data(event.test_case, event.result) else exception_to_be_printed = find_exception_to_be_printed(event.result) return unless exception_to_be_printed print_exception(exception_to_be_printed, event.result.to_sym, 6) @exceptions << exception_to_be_printed end end |
#on_test_case_started(event) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cucumber/formatter/pretty.rb', line 78 def on_test_case_started(event) if !same_feature_as_previous_test_case?(event.test_case.location) if first_feature? @first_feature = false print_profile_information else print_comments(gherkin_source.split("\n").length, 0) @io.puts end @current_feature_uri = event.test_case.location.file @exceptions = [] print_feature_data if feature_has_background? print_background_data @print_background_steps = true @in_scenario_outline = false end else @print_background_steps = false end @current_test_case = event.test_case print_step_header(current_test_case) unless print_background_steps end |
#on_test_run_finished(_event) ⇒ Object
135 136 137 138 139 |
# File 'lib/cucumber/formatter/pretty.rb', line 135 def on_test_run_finished(_event) print_comments(gherkin_source.split("\n").length, 0) unless current_feature_uri.empty? @io.puts print_summary end |
#on_test_step_finished(event) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/cucumber/formatter/pretty.rb', line 108 def on_test_step_finished(event) collect_snippet_data(event.test_step, @ast_lookup) if event.result.undefined? return if in_scenario_outline && ![:expand] exception_to_be_printed = find_exception_to_be_printed(event.result) print_step_data(event.test_step, event.result) if print_step_data?(event, exception_to_be_printed) print_step_output return unless exception_to_be_printed print_exception(exception_to_be_printed, event.result.to_sym, 6) @exceptions << exception_to_be_printed end |
#on_test_step_started(event) ⇒ Object
102 103 104 105 106 |
# File 'lib/cucumber/formatter/pretty.rb', line 102 def on_test_step_started(event) return if event.test_step.hook? print_step_header(current_test_case) if first_step_after_printing_background_steps?(event.test_step) end |