Module: Kernel

Defined in:
lib/gauge.rb

Instance Method Summary collapse

Instance Method Details

#after_scenario(options, &block) ⇒ Object

Invoked after execution of every scenario.

Examples:

after_scenario({tags: ['tag2', 'tag1'], operator: 'OR'}) do
   puts "I am the after_scenario hook"
end

Parameters:

  • block (block)

    this block is called while executing the after_scenario hook

  • options ({tags: ['list', 'of', 'tags'], operator: 'OR' | 'AND'})

    specify tags and operator for which this after_scenario execution hook should run.



129
# File 'lib/gauge.rb', line 129

tagged_hook "after_scenario"

#after_spec(options, &block) ⇒ Object

Invoked after execution of every specification.

Examples:

after_spec({tags: ['tag2', 'tag1'], operator: 'OR'}) do
   puts "I am the after_spec hook"
end

Parameters:

  • block (block)

    this block is called while executing the after_spec hook

  • options ({tags: ['list', 'of', 'tags'], operator: 'OR' | 'AND'})

    specify tags and operator for which this after_spec execution hook should run.



125
# File 'lib/gauge.rb', line 125

tagged_hook "after_spec"

#after_step(options, &block) ⇒ Object

Invoked after execution of every step.

Examples:

after_step({tags: ['tag2', 'tag1'], operator: 'OR'}) do
   puts "I am the after_step hook"
end

Parameters:

  • block (block)

    this block is called while executing the after_step hook

  • options ({tags: ['list', 'of', 'tags'], operator: 'OR' | 'AND'})

    specify tags and operator for which this after_step execution hook should run.



121
# File 'lib/gauge.rb', line 121

tagged_hook "after_step"

#after_suite(&block) ⇒ Object

Invoked after execution of the entire suite.

Examples:

after_suite do
   puts "I am the after_suite hook"
end

Parameters:

  • block (block)

    this block is called while executing the after_suite hook



133
# File 'lib/gauge.rb', line 133

hook "after_suite"

#before_scenario(options, &block) ⇒ Object

Invoked before execution of every scenario.

Examples:

before_scenario({tags: ['tag2', 'tag1'], operator: 'OR'}) do
   puts "I am the before_scenario hook"
end

Parameters:

  • block (block)

    this block is called while executing the before_scenario hook

  • options ({tags: ['list', 'of', 'tags'], operator: 'OR' | 'AND'})

    specify tags and operator for which this before_scenario execution hook should run.



127
# File 'lib/gauge.rb', line 127

tagged_hook "before_scenario"

#before_spec(options, &block) ⇒ Object

Invoked before execution of every specification.

Examples:

before_spec({tags: ['tag2', 'tag1'], operator: 'OR'}) do
   puts "I am the before_spec hook"
end

Parameters:

  • block (block)

    this block is called while executing the before_spec hook

  • options ({tags: ['list', 'of', 'tags'], operator: 'OR' | 'AND'})

    specify tags and operator for which this before_spec execution hook should run.



123
# File 'lib/gauge.rb', line 123

tagged_hook "before_spec"

#before_step(options, &block) ⇒ Object

Invoked before execution of every step.

Examples:

before_step({tags: ['tag2', 'tag1'], operator: 'OR'}) do
   puts "I am the before_step hook"
end

Parameters:

  • block (block)

    this block is called while executing the before_step hook

  • options ({tags: ['list', 'of', 'tags'], operator: 'OR' | 'AND'})

    specify tags and operator for which this before_step execution hook should run.



119
# File 'lib/gauge.rb', line 119

tagged_hook "before_step"

#before_suite(&block) ⇒ Object

Invoked before execution of the entire suite.

Examples:

before_suite do
   puts "I am the before_suite hook"
end

Parameters:

  • block (block)

    this block is called while executing the before_suite hook



131
# File 'lib/gauge.rb', line 131

hook "before_suite"

#step(*args, &block) ⇒ Object

Specify implementation for a given step

Examples:

step 'this is a simple step' do
  puts 'hello there!'
end
# step with parameters
# * say "hello" to "gauge"
step 'say <what> to <who>' do |what, who|
  puts "say #{what} to #{who}"
end
# step with aliases, two step texts can map to the same definition
# provided they have the same parameter signature
# * say "hello" to "gauge"
# * When you meet "gauge", say "hello"

step 'say <what> to <who>', 'When you meet <who>, say <what>' do |what, who|
  puts "say #{what} to #{who}"
end
# step with table
# * Step that takes a table
#        |Product|       Description           |
#        |-------|-----------------------------|
#        |Gauge  |BDD style testing with ease  |
#        |Mingle |Agile project management     |
#        |Snap   |Hosted continuous integration|
#        |Gocd   |Continuous delivery platform |

step 'Step that takes a table <table>' do |table|
  # note the extra <table> that is added to the description
    puts x.columns.join("|")
    x.rows.each { |r| puts r.join("|") }
end
# for a given step say
# setting :continue_on_failure=>true in implementation will not break on failure of this step
# and will continue to execute the next step in the scenario
# * say "hello" to "gauge"
step 'say <what> to <who>', :continue_on_failure => false do |what, who|
  puts "say #{what} to #{who}"
  raise "Some Failure"
end

Parameters:

  • step_texts (string, ...)

    the step text(s)

  • opts (Hash)

    pass :continue_on_failure => true to tell Gauge not to break on failure for this step

  • block (block)

    the implementation block for given step.



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/gauge.rb', line 105

def step(*args, &block)
  opts = args.select {|x| x.is_a? Hash}
  step_texts = args-opts
  opts = {:continue_on_failure => false}.merge opts.reduce({}, :merge)
  step_texts.each do |text|
    parameterized_step_text = Gauge::Connector.step_value(text)
    Gauge::MethodCache.add_step(parameterized_step_text, &block)
    Gauge::MethodCache.add_step_text(parameterized_step_text, text)
    Gauge::MethodCache.set_recoverable(parameterized_step_text) if opts[:continue_on_failure]
  end
  Gauge::MethodCache.add_step_alias(*step_texts)
end