Class: Lime::Scenario
- Inherits:
-
Object
- Object
- Lime::Scenario
- Defined in:
- lib/lime/scenario.rb
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#feature ⇒ Object
readonly
Parent feature.
-
#label ⇒ Object
readonly
Description of scenario.
-
#scope ⇒ Object
readonly
Evaluation scope.
-
#steps ⇒ Object
readonly
List scenario steps.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Iterate over steps.
-
#initialize(feature, settings = {}, &block) ⇒ Scenario
constructor
A new instance of Scenario.
-
#match_regexp(str) ⇒ Object
Convert matching string into a regular expression.
-
#ordered? ⇒ Boolean
Scenario steps must be run in order.
-
#run(step) ⇒ Object
Run a step in the context of this scenario.
-
#size(&block) ⇒ Object
Number of steps.
-
#skip? ⇒ Boolean, String
Skip this scenario from runs.
-
#to_s ⇒ Object
Provided the scenario label.
-
#topic ⇒ Object
FIXME.
-
#type ⇒ Object
The type is “Scenario”.
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
#feature ⇒ Object (readonly)
Parent feature.
21 22 23 |
# File 'lib/lime/scenario.rb', line 21 def feature @feature end |
#label ⇒ Object (readonly)
Description of scenario.
24 25 26 |
# File 'lib/lime/scenario.rb', line 24 def label @label end |
#scope ⇒ Object (readonly)
Evaluation scope.
30 31 32 |
# File 'lib/lime/scenario.rb', line 30 def scope @scope end |
#steps ⇒ Object (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.
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.
35 36 37 |
# File 'lib/lime/scenario.rb', line 35 def skip? @skip end |
#to_s ⇒ Object
Provided the scenario label.
60 61 62 |
# File 'lib/lime/scenario.rb', line 60 def to_s @label.to_s end |
#topic ⇒ Object
FIXME
65 66 |
# File 'lib/lime/scenario.rb', line 65 def topic end |
#type ⇒ Object
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 |