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.



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

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.



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

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.



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

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



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

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.



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

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.



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

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.



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

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



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

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.



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/gauge.rb', line 92

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|
    step_value = Gauge::Util.step_value(text)
    si = { location: { file: ENV['GAUGE_STEP_FILE'], span: {} },
           block: block, step_text: text,
           recoverable: opts[:continue_on_failure] }
    Gauge::MethodCache.add_step(step_value, si)
  end
  Gauge::MethodCache.add_step_alias(*step_texts)
end