require'cucumber/formatter/ansicolor'require'cucumber/formatter/duration'require'cucumber/formatter/summary'moduleCucumbermoduleFormatter# This module contains helper methods that are used by formatters# that print output to the terminal.moduleConsoleextendANSIColorincludeDurationincludeSummaryFORMATS=Hash.new{|hash,format|hash[format]=method(format).to_proc}defformat_step(keyword,step_match,status,source_indent)comment=ifsource_indentc=(' # '+step_match.file_colon_line).indent(source_indent)format_string(c,:comment)else''endformat=format_for(status,:param)line=keyword+step_match.format_args(format)+commentformat_string(line,status)enddefformat_string(string,status)fmt=format_for(status)string.split("\n").mapdo|line|ifProc===fmtfmt.call(line)elsefmt%lineendend.join("\n")enddefprint_steps(status)print_elements(step_mother.steps(status),status,'steps')enddefprint_elements(elements,status,kind)ifelements.any?@io.puts(format_string("(::) #{status}#{kind} (::)",status))@io.puts@io.flushendelements.each_with_indexdo|element,i|ifstatus==:failedprint_exception(element.exception,status,0)else@io.puts(format_string(element.backtrace_line,status))end@io.puts@io.flushendenddefprint_countsSTDERR.puts("The #print_counts method is deprecated and will be removed in 0.4. Use #print_stats instead")print_stats(nil)enddefprint_stats(features,profiles=[])@failures=step_mother.scenarios(:failed).select{|s|s.is_a?(Cucumber::Ast::Scenario)||s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow)}@failures.collect!{|s|(s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow))?s.scenario_outline:s}if!@failures.empty?@io.putsformat_string("Failing Scenarios:",:failed)@failures.eachdo|failure|profiles_string=profiles.empty??'':(profiles.map{|profile|"-p #{profile}"}).join(' ')+' '@io.putsformat_string("cucumber #{profiles_string}"+failure.file_colon_line,:failed)+format_string(" # Scenario: "+failure.name,:comment)end@io.putsend@io.putsscenario_summary(step_mother){|status_count,status|format_string(status_count,status)}@io.putsstep_summary(step_mother){|status_count,status|format_string(status_count,status)}@io.puts(format_duration(features.duration))iffeatures&&features.duration@io.flushenddefprint_exception(e,status,indent)@io.puts(format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent),status))enddefprint_snippets(options)returnunlessoptions[:snippets]undefined=step_mother.steps(:undefined)returnifundefined.empty?unknown_programming_language=step_mother.unknown_programming_language?snippets=undefined.mapdo|step|step_name=Undefined===step.exception?step.exception.step_name:step.namestep_multiline_class=step.multiline_arg?step.multiline_arg.class:nilsnippet=@step_mother.snippet_text(step.actual_keyword,step_name,step_multiline_class)snippetend.compact.uniqtext="\nYou can implement step definitions for undefined steps with these snippets:\n\n"text+=snippets.join("\n\n")@io.putsformat_string(text,:undefined)ifunknown_programming_language@io.putsformat_string("\nIf you want snippets in a different programming language, just make sure a file\n"+"with the appropriate file extension exists where cucumber looks for step definitions.",:failed)end@io.puts@io.flushenddefprint_passing_wip(options)returnunlessoptions[:wip]passed=step_mother.scenarios(:passed)ifpassed.any?@io.putsformat_string("\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:",:failed)print_elements(passed,:passed,"scenarios")else@io.putsformat_string("\nThe --wip switch was used, so the failures were expected. All is good.\n",:passed)endenddefembed(file,mime_type,label)# no-opend#define @delayed_announcements = [] in your Formatter if you want to#activate this featuredefannounce(announcement)if@delayed_announcements@delayed_announcements<<announcementelseif@io@io.puts@io.puts(format_string(announcement,:tag))@io.flushendendenddefprint_announcements()@delayed_announcements.each{|ann|print_announcement(ann)}empty_announcementsenddefprint_table_row_announcementsreturnif@delayed_announcements.empty?@io.print(format_string(@delayed_announcements.join(', '),:tag).indent(2))@io.flushempty_announcementsenddefprint_announcement(announcement)@io.puts(format_string(announcement,:tag).indent(@indent))@io.flushenddefempty_announcements@delayed_announcements=[]endprivatedefformat_for(*keys)key=keys.join('_').to_symfmt=FORMATS[key]raise"No format for #{key.inspect}: #{FORMATS.inspect}"iffmt.nil?fmtendendendend