Class: Cucumber::Executor
- Defined in:
- lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb
Instance Attribute Summary collapse
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
-
#formatters ⇒ Object
Returns the value of attribute formatters.
-
#lines_for_features ⇒ Object
writeonly
Sets the attribute lines_for_features.
-
#scenario_names ⇒ Object
writeonly
Sets the attribute scenario_names.
Instance Method Summary collapse
- #accept_feature?(feature) ⇒ Boolean
- #accept_scenario?(scenario) ⇒ Boolean
- #create_world ⇒ Object
- #define_step_call_methods(world) ⇒ Object
- #execute_scenario(scenario) ⇒ Object
- #executing_unprepared_row_scenario?(scenario) ⇒ Boolean
-
#initialize(step_mother) ⇒ Executor
constructor
A new instance of Executor.
- #lines_defined_for_current_feature? ⇒ Boolean
- #record_pending_step(step, regexp, args) ⇒ Object
- #register_after_scenario_proc(&proc) ⇒ Object
- #register_after_step_proc(&proc) ⇒ Object
- #register_before_scenario_proc(&proc) ⇒ Object
- #register_world_proc(&proc) ⇒ Object
- #scenario_at_specified_line?(scenario) ⇒ Boolean
- #scenario_has_specified_name?(scenario) ⇒ Boolean
- #visit_feature(feature) ⇒ Object
- #visit_features(features) ⇒ Object
- #visit_header(header) ⇒ Object
- #visit_regular_scenario(scenario) ⇒ Object
- #visit_regular_step(step) ⇒ Object
- #visit_row_scenario(scenario) ⇒ Object
- #visit_row_step(step) ⇒ Object
- #visit_scenario(scenario) ⇒ Object
- #visit_scenario_outline(scenario) ⇒ Object
- #visit_step(step) ⇒ Object
- #visit_step_outline(step) ⇒ Object
Constructor Details
#initialize(step_mother) ⇒ Executor
Returns a new instance of Executor.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 7 def initialize(step_mother) @world_procs = [] @before_scenario_procs = [] @after_scenario_procs = [] @after_step_procs = [] @step_mother = step_mother @executed_scenarios = {} @regular_scenario_cache = {} end |
Instance Attribute Details
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
3 4 5 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 3 def failed @failed end |
#formatters ⇒ Object
Returns the value of attribute formatters.
4 5 6 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 4 def formatters @formatters end |
#lines_for_features=(value) ⇒ Object (writeonly)
Sets the attribute lines_for_features
5 6 7 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 5 def lines_for_features=(value) @lines_for_features = value end |
#scenario_names=(value) ⇒ Object (writeonly)
Sets the attribute scenario_names
5 6 7 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 5 def scenario_names=(value) @scenario_names = value end |
Instance Method Details
#accept_feature?(feature) ⇒ Boolean
97 98 99 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 97 def accept_feature?(feature) feature.scenarios.any? { |s| accept_scenario?(s) } end |
#accept_scenario?(scenario) ⇒ Boolean
92 93 94 95 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 92 def accept_scenario?(scenario) scenario_at_specified_line?(scenario) && scenario_has_specified_name?(scenario) end |
#create_world ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 177 def create_world world = Object.new @world_procs.each do |world_proc| world = world_proc.call(world) end world.extend(World::Pending) world.extend(::Spec::Matchers) if defined?(::Spec::Matchers) define_step_call_methods(world) world end |
#define_step_call_methods(world) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 189 def define_step_call_methods(world) world.instance_variable_set('@__executor', self) world.instance_eval do class << self def run_step(name) _, args, proc = @__executor.instance_variable_get(:@step_mother).regexp_args_proc(name) proc.call_in(self, *args) end %w{given when then and but}.each do |keyword| alias_method Cucumber.language[keyword], :run_step end end end end |
#execute_scenario(scenario) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 79 def execute_scenario(scenario) @error = nil @pending = nil @world = create_world formatters.scenario_executing(scenario) @before_scenario_procs.each{|p| p.call_in(@world, *[])} scenario.accept(self) @after_scenario_procs.each{|p| p.call_in(@world, *[])} formatters.scenario_executed(scenario) end |
#executing_unprepared_row_scenario?(scenario) ⇒ Boolean
153 154 155 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 153 def executing_unprepared_row_scenario?(scenario) accept_scenario?(scenario) && !@executed_scenarios[scenario.name] end |
#lines_defined_for_current_feature? ⇒ Boolean
173 174 175 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 173 def lines_defined_for_current_feature? @lines_for_features && !@lines_for_features[@feature_file].nil? && !@lines_for_features[@feature_file].empty? end |
#record_pending_step(step, regexp, args) ⇒ Object
148 149 150 151 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 148 def record_pending_step(step, regexp, args) @pending = true formatters.step_pending(step, regexp, args) end |
#register_after_scenario_proc(&proc) ⇒ Object
27 28 29 30 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 27 def register_after_scenario_proc(&proc) proc.extend(CoreExt::CallIn) @after_scenario_procs << proc end |
#register_after_step_proc(&proc) ⇒ Object
32 33 34 35 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 32 def register_after_step_proc(&proc) proc.extend(CoreExt::CallIn) @after_step_procs << proc end |
#register_before_scenario_proc(&proc) ⇒ Object
22 23 24 25 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 22 def register_before_scenario_proc(&proc) proc.extend(CoreExt::CallIn) @before_scenario_procs << proc end |
#register_world_proc(&proc) ⇒ Object
18 19 20 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 18 def register_world_proc(&proc) @world_procs << proc end |
#scenario_at_specified_line?(scenario) ⇒ Boolean
157 158 159 160 161 162 163 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 157 def scenario_at_specified_line?(scenario) if lines_defined_for_current_feature? @lines_for_features[@feature_file].inject(false) { |at_line, line| at_line || scenario.at_line?(line) } else true end end |
#scenario_has_specified_name?(scenario) ⇒ Boolean
165 166 167 168 169 170 171 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 165 def scenario_has_specified_name?(scenario) if @scenario_names && !@scenario_names.empty? @scenario_names.include?(scenario.name) else true end end |
#visit_feature(feature) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 43 def visit_feature(feature) @feature_file = feature.file if accept_feature?(feature) formatters.feature_executing(feature) feature.accept(self) @executed_scenarios = {} @regular_scenario_cache = {} end end |
#visit_features(features) ⇒ Object
37 38 39 40 41 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 37 def visit_features(features) formatters.visit_features(features) features.accept(self) formatters.dump end |
#visit_header(header) ⇒ Object
54 55 56 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 54 def visit_header(header) formatters.header_executing(header) end |
#visit_regular_scenario(scenario) ⇒ Object
63 64 65 66 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 63 def visit_regular_scenario(scenario) @regular_scenario_cache[scenario.name] = scenario visit_scenario(scenario) end |
#visit_regular_step(step) ⇒ Object
105 106 107 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 105 def visit_regular_step(step) visit_step(step) end |
#visit_row_scenario(scenario) ⇒ Object
58 59 60 61 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 58 def visit_row_scenario(scenario) execute_scenario(@regular_scenario_cache[scenario.name]) if executing_unprepared_row_scenario?(scenario) visit_scenario(scenario) end |
#visit_row_step(step) ⇒ Object
101 102 103 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 101 def visit_row_step(step) visit_step(step) end |
#visit_scenario(scenario) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 72 def visit_scenario(scenario) if accept_scenario?(scenario) @executed_scenarios[scenario.name] = true execute_scenario(scenario) end end |
#visit_scenario_outline(scenario) ⇒ Object
68 69 70 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 68 def visit_scenario_outline(scenario) visit_regular_scenario(scenario) end |
#visit_step(step) ⇒ Object
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 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 114 def visit_step(step) unless @pending || @error begin regexp, args, proc = step.regexp_args_proc(@step_mother) formatters.step_executing(step, regexp, args) step.execute_in(@world, regexp, args, proc) @after_step_procs.each{|p| p.call_in(@world, *[])} formatters.step_passed(step, regexp, args) rescue ForcedPending => e step.error = e record_pending_step(step, regexp, args) rescue Pending record_pending_step(step, regexp, args) rescue => e @failed = true @error = step.error = e formatters.step_failed(step, regexp, args) end else begin regexp, args, proc = step.regexp_args_proc(@step_mother) step.execute_in(@world, regexp, args, proc) formatters.step_skipped(step, regexp, args) rescue ForcedPending => e step.error = e record_pending_step(step, regexp, args) rescue Pending record_pending_step(step, regexp, args) rescue Exception formatters.step_skipped(step, regexp, args) end end end |
#visit_step_outline(step) ⇒ Object
109 110 111 112 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/executor.rb', line 109 def visit_step_outline(step) regexp, args, proc = step.regexp_args_proc(@step_mother) formatters.step_traced(step, regexp, args) end |