Created
September 28, 2009 16:21
-
-
Save ashmoran/195541 to your computer and use it in GitHub Desktop.
Revised version of http://gist.github.com/195533
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BeforeFeatureHooks | |
def initialize | |
@hooks = [] | |
end | |
def register_hook(proc) | |
@hooks << proc | |
end | |
def run(feature) | |
@hooks.each do |hook| | |
hook.call(feature.source_tag_names) | |
end | |
end | |
end | |
class BeforeFeatureListener | |
def initialize(step_mother, io, options) | |
@step_mother, @io, @options = step_mother, io, options | |
end | |
class << self | |
def run_background_once=(state) | |
@run_background_once = state | |
end | |
def run_background_once? | |
@run_background_once | |
end | |
def in_background? | |
@in_background | |
end | |
def background_run? | |
@background_run | |
end | |
def record_background_started | |
@in_background = true | |
end | |
def record_background_complete | |
@in_background = false | |
@background_run = true | |
end | |
def reset_background_run | |
@in_background = false | |
@background_run = false | |
end | |
end | |
def before_feature(feature) | |
self.class.reset_background_run | |
$before_feature_hooks.run(feature) | |
end | |
def before_background(background) | |
self.class.record_background_started | |
end | |
def after_background(background) | |
self.class.record_background_complete | |
end | |
# On the second scenario, we don't visit the background again - | |
# the background steps get copied into the scenario | |
def before_steps(steps) | |
self.class.record_background_started | |
end | |
end | |
$before_feature_hooks = BeforeFeatureHooks.new | |
def BeforeFeature(&proc) | |
$before_feature_hooks.register_hook(proc) | |
end | |
AfterConfiguration do |configuration| | |
configuration.options[:formats] << ["BeforeFeatureListener", nil] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment