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.
5 6 7 8 9 10 11 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 5 def initialize(step_mother, io, ) @step_mother = step_mother @io = io @options = @failing_scenarios = [] @step_summary = [] end |
Instance Method Details
#after_features(features) ⇒ Object
13 14 15 16 17 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 13 def after_features(features) print_summary step_mother.scenarios.clear step_mother.steps.clear end |
#prepare_elements(elements, status, kind) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 34 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 19 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[2..-1], :failed) + format_string(" # Scenario: " + failure.name, :comment) end end |
#prepare_steps(type) ⇒ Object
52 53 54 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 52 def prepare_steps(type) prepare_elements(step_mother.steps(type), type, 'steps') end |
#print_exception(e, status, indent) ⇒ Object
56 57 58 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 56 def print_exception(e, status, indent) format_string("#{e.} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status) end |
#print_summary ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 60 def print_summary prepare_failures prepare_steps(:failed) prepare_steps(:undefined) @io.(:cucumber_summary=, to_hash) end |
#to_hash ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 70 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 |