Re: is there a plain format output for stories?

I’ve created a very simple ‘basic’ formatter, than prints story
scenarios as
. / P / F for passing, pending and failing scenarios. You can get it
here;

http://github.com/digitalronin/rspec/tree/master

Run it by appending " --format=basic " to the command-line when running
your
stories.

Hope it’s useful

David

David S. wrote:

I’ve created a very simple ‘basic’ formatter, than prints story
scenarios as . / P / F for passing, pending and failing scenarios. You
can get it here;

http://github.com/digitalronin/rspec/tree/master

Run it by appending " --format=basic " to the command-line when running
your stories.

Thanks, that is pretty simple. I knocked up this one, which shows
progress like the progress for
examples. I just put it in my spec_helper.rb and do --format
ProgressFormatter

require ‘spec/runner/formatter/base_text_formatter’

     class ProgressFormatter < 

Spec::runner::Formatter::BaseTextFormatter
def initialize(options, where)
super
@successful_scenario_count = 0
@pending_scenario_count = 0
@failed_scenarios = []
@pending_steps = []
@previous_type = nil
end

       def run_started(count)
         @count = count
       end

       def story_started(title, narrative)
         @current_story_title = title
         @output.print '['
         @output.flush
       end

       def story_ended(title, narrative)
         @output.puts ']'
       end

       def scenario_started(story_title, scenario_name)
         @current_scenario_name = scenario_name
         @scenario_already_failed = false
       end

       def scenario_succeeded(story_title, scenario_name)
         @successful_scenario_count += 1
         @output.print '*'
         @output.flush
       end

       def scenario_failed(story_title, scenario_name, err)
         @options.backtrace_tweaker.tweak_backtrace(err)
         @failed_scenarios << [story_title, scenario_name, err] 

unless @scenario_already_failed
@scenario_already_failed = true
@output.print ‘F’
@output.flush
end

       def scenario_pending(story_title, scenario_name, msg)
         @pending_scenario_count += 1 unless 

@scenario_already_failed
@scenario_pending = true
@scenario_already_failed = true
@output.print ‘P’
@output.flush
end

       def run_ended
         @output.print "#@count scenarios: 

#@successful_scenario_count succeeded,
#{@failed_scenarios.size} failed, #@pending_scenario_count pending"
unless @pending_steps.empty?
@output.print “\nPending Steps:”
@pending_steps.each_with_index do |pending, i|
story_name, scenario_name, msg = pending
@output.print “#{i+1}) #{story_name}
(#{scenario_name}): #{msg}”
end
end
unless @failed_scenarios.empty?
@output.print “\nFAILURES:”
@failed_scenarios.each_with_index do |failure, i|
title, scenario_name, err = failure
@output.print %[
#{i+1}) #{title} (#{scenario_name}) FAILED
#{err.class}: #{err.message}
#{err.backtrace.join(“\n”)}
]
end
end
@output.puts “”
end

       def step_upcoming(type, description, *args)
       end

       def step_succeeded(type, description, *args)
         @output.print '.'
         @output.flush
      end

       def step_pending(type, description, *args)
         @pending_steps << [@current_story_title, 

@current_scenario_name, description]
@output.print ‘p’
@output.flush
@scenario_pending = true
@scenario_ok = false
end

       def step_failed(type, description, *args)
         @output.print 'f'
         @output.flush
         @scenario_ok = false
       end

       def collected_steps(steps)
       end

       def method_missing(sym, *args, &block) #:nodoc:
         # noop - ignore unknown messages
       end
     end