Best Spork_ruby code snippet using Spork.exec_each_run
spork_spec.rb
Source:spork_spec.rb
...30 it "only runs the each_run block when running" do31 Spork.exec_prefork { spec_helper_simulator }32 @ran.should == [:prefork]33 34 Spork.exec_each_run35 @ran.should == [:prefork, :each_run]36 end37 38 it "runs both blocks when Spork not activated" do39 spec_helper_simulator.should == [:prefork, :each_run]40 end41 42 it "prevents blocks from being ran twice" do43 Spork.exec_prefork { spec_helper_simulator }44 Spork.exec_each_run45 @ran.clear46 Spork.exec_prefork { spec_helper_simulator }47 Spork.exec_each_run48 @ran.should == []49 end50 51 it "runs multiple prefork and each_run blocks at different locations" do52 Spork.prefork { }53 Spork.each_run { }54 spec_helper_simulator.should == [:prefork, :each_run]55 end56 57 it "expands a caller line, preserving the line number" do58 Spork.send(:expanded_caller, "/boo/../yah.rb:31").should == "/yah.rb:31"59 end60 61 describe "#using_spork?" do62 it "returns true if Spork is being used" do63 Spork.using_spork?.should be_false64 Spork.using_spork!65 Spork.using_spork?.should be_true66 end67 end68 describe "#trap_method" do69 before(:each) do70 Spork.using_spork!71 72 Object.class_eval do73 class TrapTest74 def self.output75 @output ||= []76 end77 78 def hello79 TrapTest.output << 'hello'80 end81 82 def goodbye83 TrapTest.output << 'goodbye'84 end85 86 def say_something!87 TrapTest.output << 'something'88 end89 end90 end91 @trap_test = TrapTest.new92 end93 94 after(:each) do95 Object.send(:remove_const, :TrapTest)96 end97 98 it "delays execution of a method until after Spork.exec_each_run is called" do99 Spork.using_spork!100 Spork.trap_method(TrapTest, :hello)101 @trap_test.hello102 @trap_test.goodbye103 Spork.exec_each_run104 TrapTest.output.should == ['goodbye', 'hello']105 end106 107 it "works with methods that have punctuation" do108 Spork.trap_method(TrapTest, :say_something!)109 @trap_test.say_something!110 TrapTest.output.should == []111 Spork.exec_each_run112 TrapTest.output.should == ['something']113 end114 end115 116 describe "#trap_class_method" do117 before(:each) do118 Object.class_eval do119 class TrapTest120 def self.output121 @output ||= []122 end123 124 def self.hello125 output << 'hello'126 end127 128 def self.goodbye129 output << 'goodbye'130 end131 end132 end133 end134 135 after(:each) do136 Object.send(:remove_const, :TrapTest)137 end138 139 it "delays execution of a method until after Spork.exec_each_run is called" do140 Spork.using_spork!141 Spork.trap_class_method(TrapTest, :hello)142 TrapTest.hello143 TrapTest.goodbye144 Spork.exec_each_run145 TrapTest.output.should == ['goodbye', 'hello']146 end147 end148end...
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!!