Class: Lime::Scenario

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

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature, settings = {}, &block) ⇒ Scenario

Returns a new instance of Scenario.



9
10
11
12
13
14
15
16
17
18
# File 'lib/lime/scenario.rb', line 9

def initialize(feature, settings={}, &block)
  @feature = feature

  @label   = settings[:label]
  @skip    = settings[:skip]

  @steps   = []

  @scope = Scope.new(self, &block)
end

Instance Attribute Details

#featureObject (readonly)

Parent feature.



21
22
23
# File 'lib/lime/scenario.rb', line 21

def feature
  @feature
end

#labelObject (readonly)

Description of scenario.



24
25
26
# File 'lib/lime/scenario.rb', line 24

def label
  @label
end

#scopeObject (readonly)

Evaluation scope.



30
31
32
# File 'lib/lime/scenario.rb', line 30

def scope
  @scope
end

#stepsObject (readonly)

List scenario steps.



27
28
29
# File 'lib/lime/scenario.rb', line 27

def steps
  @steps
end

Instance Method Details

#each(&block) ⇒ Object

Iterate over steps.



45
46
47
# File 'lib/lime/scenario.rb', line 45

def each(&block)
  @steps.each(&block)
end

#match_regexp(str) ⇒ Object

Convert matching string into a regular expression. If the string contains parentheticals, e.g. ‘(.*?)`, the text within them is treated as a case-insensitve back-referenceing regular expression and kept verbatium.

To use a regular expression, but leave the resulting match out of the backreferences use ‘?:`, e.g. `(?:d+)`.



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/lime/scenario.rb', line 95

def match_regexp(str)
  ## the old way required double and triple parens
  #str = str.split(/(\(\(.*?\)\))(?!\))/).map{ |x|
  #  x =~ /\A\(\((.*)\)\)\Z/ ? $1 : Regexp.escape(x)
  #}.join
  str = str.split(/(\(.*?\))(?!\))/).map{ |x|
    x =~ /\A\((.*)\)\Z/ ? "(#{$1})" : Regexp.escape(x)
  }.join
  str = str.gsub(/\\\s+/, '\s+')
  Regexp.new(str, Regexp::IGNORECASE)
end

#ordered?Boolean

Scenario steps must be run in order.

Returns:

  • (Boolean)


40
41
42
# File 'lib/lime/scenario.rb', line 40

def ordered?
  true
end

#run(step) ⇒ Object

Run a step in the context of this scenario.



71
72
73
74
75
76
77
78
79
# File 'lib/lime/scenario.rb', line 71

def run(step)
  type = step.type
  desc = step.label
  feature.advice[type].each do |mask, proc|
    if md = match_regexp(mask).match(desc)
      scope.instance_exec(*md[1..-1], &proc)
    end
  end
end

#size(&block) ⇒ Object

Number of steps.



50
51
52
# File 'lib/lime/scenario.rb', line 50

def size(&block)
  @steps.size
end

#skip?Boolean, String

Skip this scenario from runs.

Returns:

  • (Boolean, String)

    reason for skipping



35
36
37
# File 'lib/lime/scenario.rb', line 35

def skip?
  @skip
end

#to_sObject

Provided the scenario label.



60
61
62
# File 'lib/lime/scenario.rb', line 60

def to_s
  @label.to_s
end

#topicObject

FIXME



65
66
# File 'lib/lime/scenario.rb', line 65

def topic
end

#typeObject

The type is “Scenario”. This is used by Ruby Test in test output.



55
56
57
# File 'lib/lime/scenario.rb', line 55

def type
  "Scenario"
end