Setup for stories

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)

Joe

On Apr 16, 2008, at 6:22 PM, Joe Van D. 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)

The story framework has as simple listener API (not documented, but
otherwise nice):

class StorySetupListener
def run_started(num_scenarios)
# do your stuff here
end

def method_missing(method, *args)
# no-op
end
end

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

Give that a whirl.

Cheers,
David

On 16 Apr 2008, at 23:22, Joe Van D. 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? :slight_smile:

Ashley


http://www.patchspace.co.uk/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs