[rspec-users] executing code after each step of a story

Armin Joellenbeck armin.joellenbeck at googlemail.com
Tue Jan 1 07:33:05 EST 2008


Hello and happy new year,

David's answer and some digging in RDoc of RSpec has lead to the
following code sceleton:

class Listener

  def run_started(number_of_scenarios)
  end

  def run_ended
  end

  def story_started(title, description)
  end

  def story_ended(title, description)
  end

  def scenario_started(story_title, scenario_title)
  end

  def scenario_succeeded(story_title, scenario_title)
  end

  def scenario_failed(story_title, scenario_title, exception)
  end

  def scenario_pending(story_title, scenario_title, message)
  end

  def step_succeeded(kind_of_step, step_line, *args)
  end

  def step_failed(kind_of_step, step_line, *args)
  end

  def step_pending(kind_of_step, step_line, *args)
  end

  def collected_steps(*args)
  end

end


Spec::Story::Runner.register_listener(Listener.new)


The above instance methods of Listener has to be implemented. The seem
to me self-explaining. Only the last one, Listener# collected_steps,
needs further investigation. But I have not needed it yet.

Hope this helps,

Armin


More information about the rspec-users mailing list