Class: Spinach::Hooks

Inherits:
Object
  • Object
show all
Includes:
Hookable
Defined in:
lib/spinach/hooks.rb

Overview

Spinach's hooks is a subscription mechanism to allow developers to define certain callbacks given several Spinach signals, like running a feature, executing a particular step and such.

Instance Method Summary (collapse)

Methods included from Hookable

included

Instance Method Details

- (Object) after_feature

Runs after every feature

Examples:

Spinach.hooks.after_feature do |feature_data|
  # feature_data is a hash of the parsed feature data
end


40
# File 'lib/spinach/hooks.rb', line 40

hook :after_feature

- (Object) after_run

Runs after the entire spinach run

Examples:

Spinach.hooks.after_run do |status|
  # status is true when the run is successful, false otherwise
end


24
# File 'lib/spinach/hooks.rb', line 24

hook :after_run

- (Object) after_scenario

Runs after every scenario

Examples:

Spinach.hooks.after_scenario do |scenario_data|
  # feature_data is a hash of the parsed scenario data
end


73
# File 'lib/spinach/hooks.rb', line 73

hook :after_scenario

- (Object) after_step

Runs after every step execution

Examples:

Spinach.hooks.before_step do |step_data|
  # step_data contains a hash with this step's data
end


89
# File 'lib/spinach/hooks.rb', line 89

hook :after_step

- (Object) around_scenario

Runs around every scenario

Examples:

Spinach.hooks.around_scenario do |scenario_data, &block|
  # feature_data is a hash of the parsed scenario data
  block.call
end


65
# File 'lib/spinach/hooks.rb', line 65

hook :around_scenario

- (Object) before_feature

Runs before every feature,

Examples:

Spinach.hooks.before_feature do |feature_data|
  # feature_data is a hash of the parsed feature data
end


32
# File 'lib/spinach/hooks.rb', line 32

hook :before_feature

- (Object) before_run

Runs before the entire spinach run

Examples:

Spinach.hooks.before_run do
  # Whatever
end


16
# File 'lib/spinach/hooks.rb', line 16

hook :before_run

- (Object) before_scenario

Runs before every scenario

Examples:

Spinach.hooks.before_scenario do |scenario_data|
  # feature_data is a hash of the parsed scenario data
end


57
# File 'lib/spinach/hooks.rb', line 57

hook :before_scenario

- (Object) before_step

Runs before every step execution

Examples:

Spinach.hooks.before_step do |step_data|
  # step_data contains a hash with this step's data
end


81
# File 'lib/spinach/hooks.rb', line 81

hook :before_step

- (Object) on_error_step

Runs after every step execution that raises an exception

Examples:

Spinach.hooks.on_error_step do |step_data, location|
  # step_data contains a hash with this step's data
  # step_location contains a string indication this step definition's
  # location
end


119
# File 'lib/spinach/hooks.rb', line 119

hook :on_error_step

- (Object) on_failed_step

Runs after every failed step execution

Examples:

Spinach.hooks.on_failed_step do |step_data, location|
  # step_data contains a hash with this step's data
  # step_location contains a string indication this step definition's
  # location
end


109
# File 'lib/spinach/hooks.rb', line 109

hook :on_failed_step

- (Object) on_skipped_step

Runs every time a step is skipped because there has been an unsuccessful one just before.

Examples:

Spinach.hooks.on_undefined_step do |step_data|
  # step_data contains a hash with this step's data
end


138
# File 'lib/spinach/hooks.rb', line 138

hook :on_skipped_step

- (Object) on_successful_step

Runs after every successful step execution

Examples:

Spinach.hooks.on_successful_step do |step_data, location|
  # step_data contains a hash with this step's data
  # step_location contains a string indication this step definition's
  # location
end


99
# File 'lib/spinach/hooks.rb', line 99

hook :on_successful_step

- (Object) on_tag(tag)

Runs before running a scenario with a particular tag

Examples:

Spinach.hooks.on_tag('javascript') do
  # change capybara driver
end

Parameters:

  • tag (String)

    the tag to match



149
150
151
152
153
154
155
# File 'lib/spinach/hooks.rb', line 149

def on_tag(tag)
  before_scenario do |scenario|
    tags = scenario.tags
    next unless tags.any?
    yield(scenario) if tags.include? tag.to_s
  end
end

- (Object) on_undefined_feature

Runs when an undefined feature is found

Examples:

Spinach.hooks.on_undefined_feature do |feature_data, exception|
  # feature_data is a hash of the parsed feature data
  # exception contains the thrown exception
end


49
# File 'lib/spinach/hooks.rb', line 49

hook :on_undefined_feature

- (Object) on_undefined_step

Runs every time a step which is not defined is called

Examples:

Spinach.hooks.on_undefined_step do |step_data, location|
  # step_data contains a hash with this step's data
  # step_location contains a string indication this step definition's
  # location
end


129
# File 'lib/spinach/hooks.rb', line 129

hook :on_undefined_step