Class: Maze::Hooks::Hooks

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/hooks/hooks.rb

Overview

Provides the ability for callbacks to be provided as part of running Cucumber. These are akin to Cucumber’s BeforeAll, Before, After and AfterAll hooks, but are invoked in such a way that Maze Runner’s hooks do not interfere with callbacks registered by clients.

Instance Method Summary collapse

Constructor Details

#initializeHooks

Returns a new instance of Hooks.



9
10
11
12
13
14
# File 'lib/maze/hooks/hooks.rb', line 9

def initialize
  @before_all = []
  @before = []
  @pre_complete = []
  @after = []
end

Instance Method Details

#after(&block) ⇒ Object

Register blocks to be called from a Cucumber After hook (after the scenario is completed but before MazeRunner does everything it needs to between scenarios)



33
34
35
# File 'lib/maze/hooks/hooks.rb', line 33

def after(&block)
  @after << block
end

#before(&block) ⇒ Object

Register blocks to be called from a Cucumber Before hook (after MazeRunner does everything it needs to)



22
23
24
# File 'lib/maze/hooks/hooks.rb', line 22

def before(&block)
  @before << block
end

#before_all(&block) ⇒ Object

Register blocks to be called from a Cucumber BeforeAll hook (after MazeRunner does everything it needs to)



17
18
19
# File 'lib/maze/hooks/hooks.rb', line 17

def before_all(&block)
  @before_all << block
end

#call_after(scenario) ⇒ Object

For MazeRunner use only, call the registered After blocks

Parameters:

  • scenario

    The current Cucumber scenario



56
57
58
# File 'lib/maze/hooks/hooks.rb', line 56

def call_after(scenario)
  @after.each { |block| block.call(scenario) }
end

#call_before(scenario) ⇒ Object

For MazeRunner use only, call the registered Before blocks

Parameters:

  • scenario

    The current Cucumber scenario



44
45
46
# File 'lib/maze/hooks/hooks.rb', line 44

def call_before(scenario)
  @before.each { |block| block.call(scenario) }
end

#call_before_allObject

For MazeRunner use only, call the registered BeforeAll blocks



38
39
40
# File 'lib/maze/hooks/hooks.rb', line 38

def call_before_all
  @before_all.each(&:call)
end

#call_pre_complete(scenario) ⇒ Object

For MazeRunner use only, call the registered pre-complete blocks

Parameters:

  • scenario

    The current Cucumber scenario



50
51
52
# File 'lib/maze/hooks/hooks.rb', line 50

def call_pre_complete(scenario)
  @pre_complete.each { |block| block.call(scenario) }
end

#pre_complete(&block) ⇒ Object

Register blocks to be called from a Cucumber After hook (before the scenario is completed)



27
28
29
# File 'lib/maze/hooks/hooks.rb', line 27

def pre_complete(&block)
  @pre_complete << block
end