[rspec-users] setup for stories

Ashley Moran ashley.moran at patchspace.co.uk
Wed Apr 16 18:59:40 EDT 2008


On 16 Apr 2008, at 23:22, Joe Van Dyk wrote:
> I've got some code that should run before any stories execute.
> Where's a good place to put that?  (need to create a @sessions and
> @users hash)

Ha, just before I got this reply out I noticed David had written the  
exact same email as me but pressed send first...

Here's a template listener that includes all the hooks I'm aware of:

class MyStoryListener
   def run_started(number_of_scenarios); end
   def story_started(story, narrative); end
   def story_ended(story, narrative); end
   def scenario_started(story, scenario); end
   def scenario_succeeded(story, scenario); end
   def scenario_pending(story, scenario, error); end
   def scenario_failed(story, scenario, error); end
   def run_ended; end
   def method_missing(*args); end
end

(method_missing only useful if you remove some - it also highlights  
unimplemented hooks)

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

BTW does that count as documentation? :)

Ashley

-- 
http://www.patchspace.co.uk/
http://aviewfromafar.net/





More information about the rspec-users mailing list