Merge remote-tracking branch 'flapflap/de-network_configuration'
[tails-test.git] / features / support / extra_hooks.rb
bloba8addb3503649f9f00200d2c4d987a8a991bffa9
1 require 'cucumber/formatter/pretty'
3 # Sort of inspired by Cucumber::RbSupport::RbHook, but really we just
4 # want an object with a 'tag_expressions' attribute to make
5 # accept_hook?() (used below) happy.
6 class SimpleHook
7   attr_reader :tag_expressions
9   def initialize(tag_expressions, proc)
10     @tag_expressions = tag_expressions
11     @proc = proc
12   end
14   def invoke(arg)
15     @proc.call(arg)
16   end
17 end
19 def BeforeFeature(*tag_expressions, &block)
20   $before_feature_hooks ||= []
21   $before_feature_hooks << SimpleHook.new(tag_expressions, block)
22 end
24 def AfterFeature(*tag_expressions, &block)
25   $after_feature_hooks ||= []
26   $after_feature_hooks << SimpleHook.new(tag_expressions, block)
27 end
29 module ExtraHooks
30   class Pretty < Cucumber::Formatter::Pretty
31     def before_feature(feature)
32       for hook in $before_feature_hooks do
33         hook.invoke(feature) if feature.accept_hook?(hook)
34       end
35       super if defined?(super)
36     end
38     def after_feature(feature)
39       for hook in $after_feature_hooks do
40         hook.invoke(feature) if feature.accept_hook?(hook)
41       end
42       super if defined?(super)
43     end
44   end
45 end