Best Spinach_ruby code snippet using Spinach.run_step
scenario_runner_test.rb
Source:scenario_runner_test.rb
...30 subject.step_definitions31 end32 end33 describe '#run' do34 describe 'hooks (no #run_step stub)' do35 before(:each) do36 subject.stubs(:step_definitions).returns step_definitions = stub37 step_definitions.stubs(:before_each)38 step_definitions.stubs(:after_each)39 step_definitions.stubs(:step_location_for)40 end41 let(:scenario) { stub(feature: feature, steps: [steps.first], name: 'test' ) }42 it 'runs hooks in order (no #run_step stub)' do43 hooks = sequence('hooks')44 Spinach.hooks.expects(:run_before_scenario).with(scenario, step_definitions).in_sequence(hooks)45 Spinach.hooks.expects(:run_around_scenario).with(scenario, step_definitions).in_sequence(hooks).yields46 Spinach.hooks.expects(:run_before_step).with(steps.first, step_definitions).in_sequence(hooks)47 Spinach.hooks.expects(:run_around_step).with(steps.first, step_definitions).in_sequence(hooks).yields48 Spinach.hooks.expects(:run_after_step).with(steps.first, step_definitions).in_sequence(hooks)49 Spinach.hooks.expects(:run_after_scenario).with(scenario, step_definitions).in_sequence(hooks)50 subject.run51 end52 end53 describe 'hooks' do54 before(:each) do55 subject.stubs(:step_definitions).returns step_definitions = stub56 step_definitions.stubs(:before_each)57 step_definitions.stubs(:after_each)58 end59 it 'runs hooks in order' do60 hooks = sequence('hooks')61 Spinach.hooks.expects(:run_before_scenario).with(scenario, step_definitions).in_sequence(hooks)62 Spinach.hooks.expects(:run_around_scenario).with(scenario, step_definitions).in_sequence(hooks).yields63 Spinach.hooks.expects(:run_before_step).with(steps.first, step_definitions).in_sequence(hooks)64 subject.expects(:run_step).with(steps.first)65 Spinach.hooks.expects(:run_after_step).with(steps.first, step_definitions).in_sequence(hooks)66 Spinach.hooks.expects(:run_before_step).with(steps.last, step_definitions).in_sequence(hooks)67 subject.expects(:run_step).with(steps.last)68 Spinach.hooks.expects(:run_after_step).with(steps.last, step_definitions).in_sequence(hooks)69 Spinach.hooks.expects(:run_after_scenario).with(scenario, step_definitions).in_sequence(hooks)70 subject.run71 end72 it "runs before_each before run steps" do73 before_each = sequence('before_each')74 subject.stubs(:steps).returns steps = stub75 step_definitions.expects(:before_each).in_sequence(before_each)76 steps.expects(:each).in_sequence(before_each)77 subject.run78 end79 it "runs after_each after run steps" do80 after_each = sequence('after_each')81 Spinach.hooks.expects(:run_after_step).in_sequence(after_each).twice82 step_definitions.expects(:after_each).in_sequence(after_each)83 subject.run84 end85 it 'raises if around_scenario hook does not yield' do86 subject.stubs(:step_definitions).returns stub87 Spinach.hooks.stubs(:run_around_scenario).with(scenario, step_definitions)88 e = proc do89 subject.run90 end.must_raise Spinach::HookNotYieldException91 e.hook.must_match /around_scenario/92 end93 it 'raises if around_step hook does not yield' do94 step_definitions.stubs(:step_location_for)95 Spinach.hooks.stubs(:run_around_step).with(steps.first, step_definitions)96 e = proc do97 subject.run98 end.must_raise Spinach::HookNotYieldException99 e.hook.must_match /around_step/100 end101 end102 end103 describe '#run_step' do104 before do105 @step = stub(name: 'Go shopping', keyword: "key")106 @step_definitions = stub107 @step_definitions.stubs(:step_location_for).with('Go shopping').returns @location = [ "" ]108 subject.stubs(:step_definitions).returns @step_definitions109 end110 describe 'when the step is successful' do111 it 'runs the successful hooks' do112 @step_definitions.stubs(:execute).with(@step).returns true113 Spinach.hooks.expects(:run_on_successful_step).with(@step, @location, @step_definitions)114 subject.run_step(@step)115 end116 end117 describe 'when the step fails' do118 before do119 @failure_exception = Class.new(StandardError)120 Spinach.stubs(:config).returns({ failure_exceptions: [@failure_exception] })121 @step_definitions.stubs(:execute).with(@step).raises @failure_exception122 end123 it 'sets the exception' do124 subject.run_step(@step)125 subject.instance_variable_get(:@exception).must_be_kind_of(@failure_exception)126 end127 it 'runs the failed hooks' do128 Spinach.hooks.expects(:run_on_failed_step).with(@step, kind_of(@failure_exception), @location, @step_definitions)129 subject.run_step(@step)130 end131 end132 describe 'when the step is undefined' do133 before do134 @step_definitions.stubs(:execute).with(@step).raises Spinach::StepNotDefinedException, @step135 end136 it 'sets the exception' do137 subject.run_step(@step)138 subject.instance_variable_get(:@exception).must_be_kind_of(Spinach::StepNotDefinedException)139 end140 it 'runs the undefined hooks' do141 Spinach.hooks.expects(:run_on_undefined_step).with(@step, kind_of(Spinach::StepNotDefinedException), @step_definitions)142 subject.run_step(@step)143 end144 end145 describe 'when the step is pending' do146 before do147 @step_definitions.148 stubs(:execute).149 with(@step).150 raises Spinach::StepPendingException, @step151 end152 it 'does not set the exception' do153 subject.run_step(@step)154 subject.instance_variable_get(:@exception).must_be_kind_of(NilClass)155 end156 it 'sets the has_pending_step' do157 subject.run_step(@step)158 subject.instance_variable_get(:@has_pending_step).must_equal(true)159 end160 it 'runs the pending hooks' do161 Spinach.hooks.expects(:run_on_pending_step).with(@step, kind_of(Spinach::StepPendingException))162 subject.run_step(@step)163 end164 end165 describe 'when the step raises an error' do166 before do167 @step_definitions.stubs(:execute).with(@step).raises StandardError168 end169 it 'sets the exception' do170 subject.run_step(@step)171 subject.instance_variable_get(:@exception).must_be_kind_of(StandardError)172 end173 it 'runs the error hooks' do174 Spinach.hooks.expects(:run_on_error_step).with(@step, kind_of(StandardError), @location, @step_definitions)175 subject.run_step(@step)176 end177 end178 end179 end180 end181end...
scenario_runner.rb
Source:scenario_runner.rb
...48 Spinach.hooks.run_before_step step, step_definitions49 if @exception || @has_pending_step50 Spinach.hooks.run_on_skipped_step step, step_definitions51 else52 run_step(step)53 end54 Spinach.hooks.run_after_step step, step_definitions55 end56 step_definitions.after_each57 end58 raise Spinach::HookNotYieldException.new('around_scenario') if !scenario_run && !@exception59 Spinach.hooks.run_after_scenario @scenario, step_definitions60 !@exception61 end62 # Runs a particular step.63 #64 # @param [GherkinRuby::AST::Step] step65 # The step to be run.66 #67 # @api semipublic68 def run_step(step)69 step_location = step_definitions.step_location_for(step.name)70 step_run = false71 Spinach.hooks.run_around_step step, step_definitions do72 step_run = true73 step_definitions.execute(step)74 end75 raise Spinach::HookNotYieldException.new('around_step') if !step_run76 Spinach.hooks.run_on_successful_step step, step_location, step_definitions77 rescue Spinach::HookNotYieldException => e78 raise e79 rescue *Spinach.config[:failure_exceptions] => e80 @exception = e81 Spinach.hooks.run_on_failed_step step, @exception, step_location, step_definitions82 rescue Spinach::StepNotDefinedException => e...
run_step
Using AI Code Generation
1step 'I search for "([^"]*)" on google' do |arg1|2 @browser.text_field(:name => 'q').set arg13 @browser.button(:name => 'btnG').click4step 'I should see "([^"]*)" in the search results' do |arg1|
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!