Class: Specjour::Cucumber::DistributedFormatter
- Inherits:
-
Cucumber::Formatter::Progress
- Object
- Cucumber::Formatter::Progress
- Specjour::Cucumber::DistributedFormatter
- Defined in:
- lib/specjour/cucumber/distributed_formatter.rb
Constant Summary collapse
- OUTCOMES =
[:failed, :skipped, :undefined, :pending, :passed]
Instance Method Summary collapse
- #after_features(features) ⇒ Object
-
#initialize(step_mother, io, options) ⇒ DistributedFormatter
constructor
A new instance of DistributedFormatter.
- #prepare_elements(elements, status, kind) ⇒ Object
- #prepare_failures ⇒ Object
- #prepare_steps(type) ⇒ Object
- #print_exception(e, status, indent) ⇒ Object
- #print_summary ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(step_mother, io, options) ⇒ DistributedFormatter
Returns a new instance of DistributedFormatter.
4 5 6 7 8 9 10 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 4 def initialize(step_mother, io, ) @step_mother = step_mother @io = io @options = @failing_scenarios = [] @step_summary = [] end |
Instance Method Details
#after_features(features) ⇒ Object
12 13 14 15 16 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 12 def after_features(features) print_summary step_mother.scenarios.clear step_mother.steps.clear end |
#prepare_elements(elements, status, kind) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 33 def prepare_elements(elements, status, kind) output = '' if elements.any? output += format_string("\n(::) #{status} #{kind} (::)\n", status) output += "\n" end elements.each_with_index do |element, i| if status == :failed output += print_exception(element.exception, status, 0) else output += format_string(element.backtrace_line, status) output += "\n" end @step_summary << output unless output.nil? || output.empty? end end |
#prepare_failures ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 18 def prepare_failures step_mother.scenarios(:failed).select do |s| s.is_a?(Cucumber::Ast::Scenario) || s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow) end.map do |failure| if failure.is_a?(Cucumber::Ast::Scenario) failure elsif failure.is_a?(Cucumber::Ast::OutlineTable::ExampleRow) failure.scenario_outline end end.each do |failure| @failing_scenarios << format_string("cucumber " + failure.file_colon_line, :failed) + format_string(" # Scenario: " + failure.name, :comment) end end |
#prepare_steps(type) ⇒ Object
51 52 53 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 51 def prepare_steps(type) prepare_elements(step_mother.steps(type), type, 'steps') end |
#print_exception(e, status, indent) ⇒ Object
55 56 57 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 55 def print_exception(e, status, indent) format_string("#{e.} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status) end |
#print_summary ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 59 def print_summary prepare_failures prepare_steps(:failed) prepare_steps(:undefined) @io.(:cucumber_summary=, to_hash) end |
#to_hash ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 69 def to_hash hash = {} [:scenarios, :steps].each do |type| hash[type] = {} OUTCOMES.each do |outcome| hash[type][outcome] = step_mother.send(type, outcome).size end end hash.merge!(:failing_scenarios => @failing_scenarios, :step_summary => @step_summary) hash end |