gurke 2.0.0.dev.1.b18 → 2.0.0.dev.1.b19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTliYzQwOGExYjAzODMxMTE3YWZhMmU1ZDhmZDM5YjZjZWM5Y2E5ZA==
4
+ MzAxYTk2ODk0YzgxZWM2OTBkM2QzY2ZkYTIzOWI2NWIyODJmYjE0Zg==
5
5
  data.tar.gz: !binary |-
6
- ZjdiNTE1MDQ5NTk5ZmY4YTIwZGZhZWM2MmRhZGYwMWQ1YWRhZjVjYQ==
6
+ YTQ2NWJmMzY0MGE2Y2NjMjRiMWEwMTc5ODhlZGU3Nzg5ZmU5Y2ZjMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2EzNTBhOTE4OTFmOWQ2ZjU0NzI1MWY2YjhhMGE1N2EyNGJiNjNlYTA5NTNl
10
- MmVmM2Y0NWM4NTVhYzIxNDY0OTY5ZDBiZTZkYTIwODAwMDljMzIxNTNkMTYy
11
- Y2JmZmZiZjc3ZTYwNTdkMzlhNzgyOTMwZjk3NzEzZWIzNDRjNGU=
9
+ MmI4ZGViNDEyYmZmZDAzMWI2MDI4ZmE3OTgzODU5MjJhZDMzZDk2Y2I1MjQ0
10
+ ZWUxNTUwOWUzNDI2ZjNkM2RkMjMyMmE3NWE5YjE0YjIzMjE0YmIxMjgwM2I2
11
+ MzFjZWFjZjllMDhjODEwOGYxMjJmMjcwNWI2Zjk3ZDE2ZmM3NmI=
12
12
  data.tar.gz: !binary |-
13
- NGFiZmE4ODNkMDkxODY3ZWZjYTE1ODBkYzNkYjY4MWU1NTgwNzYxZDEzY2Y4
14
- ZTBlOWY3M2U2ZWQ2MGFjODFiYThhNDEyOWYzZmU3MWQ0M2JlMzVjMTBhZjVh
15
- YzYwNDNhZGNmOTFjZmQ2YmYxYzRkZjU1MmM5ZDdlMDkyMzg2NTg=
13
+ ZjU2ZDUzYzcxOGMxZTk5YTEzZGRlNmRmNmJmOTE4ODlkYWJmZjc3NmI1YTE2
14
+ MDU4MjI2NDYwNjAxNjI0NDgzODM4OWFmYjEzNGFlZmNjODljZDI2Yjc1OTAx
15
+ NmQ1M2RlZjliMjBmYjViNThjMDhlYmMwMmU3MGRhZjNkOTIzNjA=
@@ -30,7 +30,7 @@ module Gurke
30
30
  end if options[:require].any?
31
31
 
32
32
  files = Dir[options[:pattern].to_s] if files.empty? && options[:pattern]
33
- status = Runner.new(files, options).run
33
+ status = Runner.new(Gurke.config, files, options).run
34
34
 
35
35
  Kernel.exit(status)
36
36
  end
@@ -15,11 +15,15 @@ module Gurke
15
15
  # @yield Before any matching action is executed.
16
16
  #
17
17
  def before(action = :scenario, opts = nil, &block)
18
- BEFORE_HOOKS.append action, Hook.new(opts, &block)
18
+ raise ArgumentError.new "Unknown hook: #{action}" unless hooks[action]
19
+
20
+ hooks[action].append :before, Hook.new(opts, &block)
19
21
  end
20
22
 
21
23
  def around(action = :scenario, opts = nil, &block)
22
- AROUND_HOOKS.append action, Hook.new(opts, &block)
24
+ raise ArgumentError.new "Unknown hook: #{action}" unless hooks[action]
25
+
26
+ hooks[action].append :around, Hook.new(opts, &block)
23
27
  end
24
28
 
25
29
  # Define a after filter running after given action.
@@ -35,7 +39,9 @@ module Gurke
35
39
  # @yield After any matching action is executed.
36
40
  #
37
41
  def after(action = :scenario, opts = nil, &block)
38
- AFTER_HOOKS.append action, Hook.new(opts, &block)
42
+ raise ArgumentError.new "Unknown hook: #{action}" unless hooks[action]
43
+
44
+ hooks[action].append :after, Hook.new(opts, &block)
39
45
  end
40
46
 
41
47
  # Include given module into all or specific features or
@@ -58,7 +64,17 @@ module Gurke
58
64
 
59
65
  # @api private
60
66
  def hooks
61
- @hooks ||= Hooks.new
67
+ @hooks ||= begin
68
+ hooks = {
69
+ features: HookSet.new,
70
+ feature: HookSet.new,
71
+ scenario: HookSet.new,
72
+ step: HookSet.new
73
+ }
74
+
75
+ hooks.merge each: hooks[:scenario]
76
+ hooks
77
+ end
62
78
  end
63
79
 
64
80
  # @api private
@@ -73,25 +89,35 @@ module Gurke
73
89
 
74
90
  # @api private
75
91
  class HookSet
76
- attr_reader :hooks
77
-
78
92
  def initialize
79
- @hooks = {}
93
+ @before = []
94
+ @after = []
95
+ @around = []
80
96
  end
81
97
 
82
- def for(action)
83
- hooks[action] ||= []
98
+ def append(set, hook)
99
+ case set
100
+ when :before then @before << hook
101
+ when :after then @after << hook
102
+ when :around then @around << hook
103
+ else raise ArgumentError.new "Unknown hook set: #{set}"
104
+ end
84
105
  end
85
106
 
86
- def append(action, hook)
87
- self.for(action) << hook
107
+ def run(world, &block)
108
+ @before.each{|hook| hook.run world }
109
+ @around.reduce(block){|blk, hook| proc{ hook.run world, blk }}.call
110
+ ensure
111
+ @after.each do |hook|
112
+ begin
113
+ hook.run world
114
+ rescue => e
115
+ warn "Rescued error in after hook: #{e}\n#{e.backtrace.join("\n")}"
116
+ end
117
+ end
88
118
  end
89
119
  end
90
120
 
91
- BEFORE_HOOKS = HookSet.new
92
- AROUND_HOOKS = HookSet.new
93
- AFTER_HOOKS = HookSet.new
94
-
95
121
  # @api private
96
122
  class Hook
97
123
  attr_reader :opts, :block
@@ -4,8 +4,10 @@ module Gurke
4
4
  attr_reader :builder
5
5
  attr_reader :files
6
6
  attr_reader :options
7
+ attr_reader :config
7
8
 
8
- def initialize(files, options = {})
9
+ def initialize(config, files, options = {})
10
+ @config = config
9
11
  @options = options
10
12
  @files = files
11
13
  @builder = Builder.new options
@@ -24,18 +26,7 @@ module Gurke
24
26
  end
25
27
 
26
28
  def hook(scope, world, &block)
27
- Configuration::BEFORE_HOOKS.for(scope).each{|hook| hook.run world }
28
- Configuration::AROUND_HOOKS.for(scope).reduce(block) do |blk, hook|
29
- proc { hook.run(world, blk) }
30
- end.call
31
- ensure
32
- Configuration::AFTER_HOOKS.for(scope).each do |hook|
33
- begin
34
- hook.run world
35
- rescue => e
36
- warn "Rescued error in after hook: #{e}\n#{e.backtrace.join("\n")}"
37
- end
38
- end
29
+ config.hooks[scope].run world, &block
39
30
  end
40
31
 
41
32
  def with_filtered_backtrace
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gurke
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.dev.1.b18
4
+ version: 2.0.0.dev.1.b19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen