Class: Gurke::Scenario

Inherits:
Object
  • Object
show all
Defined in:
lib/gurke/scenario.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature, file, line, tags, raw) ⇒ Scenario

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Scenario.



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

def initialize(feature, file, line, tags, raw)
  @feature = feature
  @steps   = RunList.new
  @file    = file
  @line    = line
  @tags    = tags
  @raw     = raw
end

Instance Attribute Details

#exceptionException (readonly)

Exception that led to either pending or failed state.

Returns:

  • (Exception)

    Exception or nil of none given.



93
94
95
# File 'lib/gurke/scenario.rb', line 93

def exception
  @exception
end

#featureFeature (readonly)

The feature that contains this scenario.

Returns:



20
21
22
# File 'lib/gurke/scenario.rb', line 20

def feature
  @feature
end

#fileString (readonly)

Return path to file containing this scenario.

Returns:

  • (String)

    File path.



8
9
10
# File 'lib/gurke/scenario.rb', line 8

def file
  @file
end

#lineFixnum (readonly)

Return line number where the scenario is defined.

Returns:

  • (Fixnum)

    Line number.



14
15
16
# File 'lib/gurke/scenario.rb', line 14

def line
  @line
end

#rawObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/gurke/scenario.rb', line 34

def raw
  @raw
end

#stepsArray<Step> (readonly)

List of this scenario’s steps.

This does not include background steps.

Returns:

  • (Array<Step>)

    Steps.



28
29
30
# File 'lib/gurke/scenario.rb', line 28

def steps
  @steps
end

#tagsObject (readonly)

Returns the value of attribute tags.



31
32
33
# File 'lib/gurke/scenario.rb', line 31

def tags
  @tags
end

Instance Method Details

#backgroundsArray<Background>

Return all backgrounds for this scenario.

They are taken from the feature containing this scenario.

Returns:



61
62
63
# File 'lib/gurke/scenario.rb', line 61

def backgrounds
  feature.backgrounds
end

#failed!(error = nil) ⇒ Object

Call to mark scenario as failed.

Parameters:

  • error (Exception) (defaults to: nil)

    Given an exception as reason.



99
100
101
102
# File 'lib/gurke/scenario.rb', line 99

def failed!(error = nil)
  @exception = error
  @state     = :failed
end

#failed?Boolean

Check if scenario has failed.

Returns:

  • (Boolean)

    True if failed, false otherwise.



85
86
87
# File 'lib/gurke/scenario.rb', line 85

def failed?
  @state == :failed
end

#nameString

Return name of the scenario.

Returns:

  • (String)

    Scenario name.



51
52
53
# File 'lib/gurke/scenario.rb', line 51

def name
  raw.name
end

#pending!(error) ⇒ Object

Call to mark scenario as pending. Will do nothing if scenario is already failed.

Parameters:

  • error (Exception)

    Given an exception as reason.



109
110
111
112
113
114
# File 'lib/gurke/scenario.rb', line 109

def pending!(error)
  return if failed?

  @exception = error
  @state     = :pending
end

#pending?Boolean

Check if scenario is pending.

Returns:

  • (Boolean)

    True if pending, false otherwise.



77
78
79
# File 'lib/gurke/scenario.rb', line 77

def pending?
  @state == :pending
end

#run(runner, reporter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



118
119
120
121
122
123
124
125
126
# File 'lib/gurke/scenario.rb', line 118

def run(runner, reporter)
  reporter.invoke :before_scenario, self

  runner.hook :scenario, world do
    run_scenario runner, reporter
  end
ensure
  reporter.invoke :after_scenario, self
end

#tag_namesArray<String>

Return a list of tag names as strings.

Returns:

  • (Array<String>)

    Tag names.



69
70
71
# File 'lib/gurke/scenario.rb', line 69

def tag_names
  @tag_names ||= tags.map(&:name)
end