Class: Marso::Scenario
- Includes:
- ScenarioPublish
- Defined in:
- lib/marso/domain/scenario/scenario.rb
Constant Summary collapse
- ISSUES_LIST =
[:error, :failed, :cancelled]
- @@color_options =
nil
- @@color_options_size =
0
Instance Attribute Summary collapse
-
#cancel_steps_upon_issues ⇒ Object
readonly
Returns the value of attribute cancel_steps_upon_issues.
-
#color_theme ⇒ Object
readonly
Returns the value of attribute color_theme.
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
-
#feature_id ⇒ Object
readonly
Returns the value of attribute feature_id.
-
#fname ⇒ Object
readonly
Returns the value of attribute fname.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#realtime_step_stdout ⇒ Object
readonly
Returns the value of attribute realtime_step_stdout.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#story_id ⇒ Object
readonly
Returns the value of attribute story_id.
-
#tree_position ⇒ Object
readonly
Returns the value of attribute tree_position.
Instance Method Summary collapse
- #and(assumption_text, *args, &block) ⇒ Object
- #but(assumption_text, *args, &block) ⇒ Object
- #given(assumption_text, *args, &block) ⇒ Object
-
#initialize(description, ctx = {}) ⇒ Scenario
constructor
description: Hash defined as follow :id => Arbitrary number or string.
- #run ⇒ Object
-
#text(include_id = false) ⇒ Object
include_id will prepend the scenario id to the step’s description.
- #then(assumption_text, *args, &block) ⇒ Object
- #when(assumption_text, *args, &block) ⇒ Object
Methods included from ScenarioPublish
Methods included from TextHelper
#colorized_text, #indented_colorized_text
Constructor Details
#initialize(description, ctx = {}) ⇒ Scenario
description: Hash defined as follow
:id => Arbitrary number or string. Default is randomly generated
(hex string (length 8))
:name => Scenario's name
:steps => array of Step objects
:color_theme => color from gem 'colorize'(e.g. :blue). That allows
to visually group all steps from the same scenario.
Default is randomly choosen from the available set
:cancel_steps_upon_issues => Boolean. If true, all steps defined after
a broken step(i.e. step in status :failed,
:error, or :cancelled) will not be
executed, and will all be set so their
status is :cancelled.
If defined, it overrides the
Config.cancel_steps_upon_issues setting.
:realtime_step_stdout => Boolean. If true, the result of each step is
output to the console in realtime rather than
waiting for the entire scenario to finish and
then display all the steps all at once. Setting
that config to true may make reading the output
harder when multiple scenarios are executed in
paralell.Steps of different scenarios may
indeed be intertwined in the console.
If defined, it overrides the
Config.realtime_step_stdout setting.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/marso/domain/scenario/scenario.rb', line 101 def initialize(description, ctx={}) validate_arguments(description, ctx) if @@color_options.nil? @@color_options = String.colors @@color_options_size = @@color_options.size end @name = description[:name] @fname = description[:name].downcase.gsub(' ', '_') @ctx = ctx.clone @tree_position = 0 @tree_position+=1 unless ctx[:story_id].nil? @tree_position+=1 unless ctx[:feature_id].nil? @story_id = ctx[:story_id] @feature_id = ctx[:feature_id] @id = description.key?(:id) ? description[:id] : SecureRandom.hex(4) @status = description.key?(:status) ? description[:status] : :none @color_theme = description.key?(:color_theme) ? description[:color_theme] : @@color_options[rand(@@color_options_size)] @steps = description.key?(:steps) ? description[:steps].map { |s| Step.new(s.text, @id, @color_theme, s.status, &s.block) } : [] @header = get_header(@id, @ctx) @cancel_steps_upon_issues = description.key?(:cancel_steps_upon_issues) ? description[:cancel_steps_upon_issues] : Marso::Config.get(:cancel_steps_upon_issues) @realtime_step_stdout = description.key?(:realtime_step_stdout) ? description[:realtime_step_stdout] : Marso::Config.get(:realtime_step_stdout) end |
Instance Attribute Details
#cancel_steps_upon_issues ⇒ Object (readonly)
Returns the value of attribute cancel_steps_upon_issues.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def cancel_steps_upon_issues @cancel_steps_upon_issues end |
#color_theme ⇒ Object (readonly)
Returns the value of attribute color_theme.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def color_theme @color_theme end |
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def ctx @ctx end |
#feature_id ⇒ Object (readonly)
Returns the value of attribute feature_id.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def feature_id @feature_id end |
#fname ⇒ Object (readonly)
Returns the value of attribute fname.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def fname @fname end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def header @header end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def name @name end |
#realtime_step_stdout ⇒ Object (readonly)
Returns the value of attribute realtime_step_stdout.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def realtime_step_stdout @realtime_step_stdout end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def status @status end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def steps @steps end |
#story_id ⇒ Object (readonly)
Returns the value of attribute story_id.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def story_id @story_id end |
#tree_position ⇒ Object (readonly)
Returns the value of attribute tree_position.
70 71 72 |
# File 'lib/marso/domain/scenario/scenario.rb', line 70 def tree_position @tree_position end |
Instance Method Details
#and(assumption_text, *args, &block) ⇒ Object
157 158 159 |
# File 'lib/marso/domain/scenario/scenario.rb', line 157 def and(assumption_text, *args, &block) return add_step(:and, assumption_text, *args, &block) end |
#but(assumption_text, *args, &block) ⇒ Object
169 170 171 |
# File 'lib/marso/domain/scenario/scenario.rb', line 169 def but(assumption_text, *args, &block) return add_step(:but, assumption_text, *args, &block) end |
#given(assumption_text, *args, &block) ⇒ Object
153 154 155 |
# File 'lib/marso/domain/scenario/scenario.rb', line 153 def given(assumption_text, *args, &block) return add_step(:given, assumption_text, *args, &block) end |
#run ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/marso/domain/scenario/scenario.rb', line 185 def run previous_step_status = nil scenario_status = :passed no_issues = true processed_steps = @steps.map { |s| runned_step = run_step(s, previous_step_status) print_indented(runned_step.print_description) if @realtime_step_stdout previous_step_status = runned_step.status if no_issues case previous_step_status when :error no_issues = false scenario_status = :error when :failed no_issues = false scenario_status = :failed when :cancelled no_issues = false scenario_status = :failed end end runned_step } updated_scenario = Scenario.new( { :id => @id, :name => @name, :steps => processed_steps, :status => scenario_status, :color_theme => @color_theme }, @ctx) return updated_scenario end |
#text(include_id = false) ⇒ Object
include_id will prepend the scenario id to the step’s description. This can be useful in the case where each step is being output to the console in realtime. In that situation multiple steps from multiple scenarios may be intertwined if they are executed concurently. Without the scenario id, it may be difficult to identify which step belongs to which scenario
179 180 181 182 183 |
# File 'lib/marso/domain/scenario/scenario.rb', line 179 def text(include_id=false) return "{@header}: #{name}\n" + (@steps.any? ? @steps.map { |s| s.text(include_id) }.join("\n") : "") end |
#then(assumption_text, *args, &block) ⇒ Object
165 166 167 |
# File 'lib/marso/domain/scenario/scenario.rb', line 165 def then(assumption_text, *args, &block) return add_step(:then, assumption_text, *args, &block) end |
#when(assumption_text, *args, &block) ⇒ Object
161 162 163 |
# File 'lib/marso/domain/scenario/scenario.rb', line 161 def when(assumption_text, *args, &block) return add_step(:when, assumption_text, *args, &block) end |