require'cucumber/formatter/ansicolor'require'cucumber/formatter/duration'moduleCucumbermoduleFormattermoduleConsoleextendANSIColorincludeDurationFORMATS=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)ifProc===fmtfmt.call(string)elsefmt%stringendenddefprint_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)@failures=step_mother.scenarios(:failed).select{|s|s.is_a?(Cucumber::Ast::Scenario)}if!@failures.empty?@io.putsformat_string("Failing Scenarios:",:failed)@failures.eachdo|failure|@io.putsformat_string("cucumber "+failure.file_colon_line,:failed)+format_string(" # Scenario: "+failure.name,:comment)end@io.putsend@io.printdump_count(step_mother.scenarios.length,"scenario")print_status_counts{|status|step_mother.scenarios(status)}@io.printdump_count(step_mother.steps.length,"step")print_status_counts{|status|step_mother.steps(status)}@io.puts(format_duration(features.duration))iffeatures@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?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)@io.puts@io.flushenddefprint_passing_wip(options)returnunlessoptions[:wip]passed=step_mother.scenarios(:passed)ifpassed.any?@io.puts"\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:"print_elements(passed,:passed,"scenarios")endenddefannounce(announcement)@io.puts@io.puts(format_string(announcement,:tag))@io.flushendprivatedefprint_status_countscounts=[:failed,:skipped,:undefined,:pending,:passed].mapdo|status|elements=yieldstatuselements.any??format_string("#{elements.length}#{status.to_s}",status):nilend.compactifcounts.any?@io.puts(" (#{counts.join(', ')})")else@io.putsendenddefdump_count(count,what,state=nil)[count,state,"#{what}#{count==1?'':'s'}"].compact.join(" ")enddefformat_for(*keys)key=keys.join('_').to_symfmt=FORMATS[key]raise"No format for #{key.inspect}: #{FORMATS.inspect}"iffmt.nil?fmtendendendend