Class: ScenarioContext::ScenarioProxy

Inherits:
Struct
  • Object
show all
Defined in:
lib/scenario_context/scenario_proxy.rb

Overview

A generic interface to a Scenario or ExampleRow

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scenarioObject

Returns the value of attribute scenario

Returns:

  • (Object)

    the current value of scenario



5
6
7
# File 'lib/scenario_context/scenario_proxy.rb', line 5

def scenario
  @scenario
end

Instance Method Details

#file_colon_lineString

Returns the file name colon line number representation of the scenario.

Returns:

  • (String)

    the file name colon line number representation of the scenario



8
9
10
11
12
13
14
# File 'lib/scenario_context/scenario_proxy.rb', line 8

def file_colon_line
  if outline?
    scenario.file_colon_line
  else
    scenario.scenario_outline.file_colon_line
  end
end

#outlineBoolean

Returns scenario.scenario_outline if the scenario is an outline.

Returns:

  • (Boolean)

    scenario.scenario_outline if the scenario is an outline

Raises:

  • (NotImplementedError)

    unless the scenario is an outline



18
19
20
21
22
23
24
25
26
27
# File 'lib/scenario_context/scenario_proxy.rb', line 18

def outline
  unless outline?
    fail(
      NotImplementedError,
      'ScenarioContext#outline is only available for scenario outlines.'
    )
  end

  scenario.scenario_outline
end

#outline?Boolean

Returns whether @scenario is an outline (ExampleRow) or a not.

Returns:

  • (Boolean)

    whether @scenario is an outline (ExampleRow) or a not



30
31
32
33
34
# File 'lib/scenario_context/scenario_proxy.rb', line 30

def outline?
  return unless defined?(Cucumber::Ast::OutlineTable::ExampleRow)

  scenario.is_a?(Cucumber::Ast::OutlineTable::ExampleRow)
end

#titleString Also known as: name

if @scenario is an outline

Returns:

  • (String)

    the title of the scenario or a pretty scenario “title”



38
39
40
41
42
43
44
45
# File 'lib/scenario_context/scenario_proxy.rb', line 38

def title
  if outline?
    scenario_name = scenario.name.match(/\| (.*) \|/)[1]
    "#{outline.title}: #{scenario_name}"
  else
    scenario.title
  end
end