How to use exec_prefork method of Spork Package

Best Spork_ruby code snippet using Spork.exec_prefork


Source:spork_spec.rb Github


Full Screen

...24 @ran25 end26 27 it "only runs the preload block when preforking" do28 Spork.exec_prefork { spec_helper_simulator }29 @ran.should == [:prefork]30 end31 32 it "only runs the each_run block when running" do33 Spork.exec_prefork { spec_helper_simulator }34 @ran.should == [:prefork]35 36 Spork.exec_each_run37 @ran.should == [:prefork, :each_run]38 end39 40 it "runs both blocks when Spork not activated" do41 spec_helper_simulator.should == [:prefork, :each_run]42 end43 44 it "prevents blocks from being ran twice" do45 Spork.exec_prefork { spec_helper_simulator }46 Spork.exec_each_run47 @ran.clear48 Spork.exec_prefork { spec_helper_simulator }49 Spork.exec_each_run50 @ran.should == []51 end52 53 it "runs multiple prefork and each_run blocks at different locations" do54 Spork.prefork { }55 Spork.each_run { }56 spec_helper_simulator.should == [:prefork, :each_run]57 end58 59 it "expands a caller line, preserving the line number" do60 Spork.send(:expanded_caller, "/boo/../yah.rb:31").should == "/yah.rb:31"61 end62 63 describe "#using_spork?" do64 it "returns true if Spork is being used" do65 Spork.using_spork?.should be_false66 Spork.exec_prefork { }67 Spork.using_spork?.should be_true68 end69 end70 describe "#trap_method" do71 before(:each) do72 Spork.exec_prefork { }73 74 Object.class_eval do75 class TrapTest76 def self.output77 @output ||= []78 end79 80 def hello81 TrapTest.output << 'hello'82 end83 84 def goodbye85 TrapTest.output << 'goodbye'86 end87 88 def say_something!89 TrapTest.output << 'something'90 end91 end92 end93 @trap_test = TrapTest.new94 end95 96 after(:each) do97 Object.send(:remove_const, :TrapTest)98 end99 100 it "delays execution of a method until after Spork.exec_each_run is called" do101 Spork.exec_prefork { }102 Spork.trap_method(TrapTest, :hello)103 @trap_test.hello104 @trap_test.goodbye105 Spork.exec_each_run106 TrapTest.output.should == ['goodbye', 'hello']107 end108 109 it "works with methods that have punctuation" do110 Spork.trap_method(TrapTest, :say_something!)111 @trap_test.say_something!112 TrapTest.output.should == []113 Spork.exec_each_run114 TrapTest.output.should == ['something']115 end116 end117 118 describe "#trap_class_method" do119 before(:each) do120 Object.class_eval do121 class TrapTest122 def self.output123 @output ||= []124 end125 126 def self.hello127 output << 'hello'128 end129 130 def self.goodbye131 output << 'goodbye'132 end133 end134 end135 end136 137 after(:each) do138 Object.send(:remove_const, :TrapTest)139 end140 141 it "delays execution of a method until after Spork.exec_each_run is called" do142 Spork.exec_prefork { }143 Spork.trap_class_method(TrapTest, :hello)144 TrapTest.hello145 TrapTest.goodbye146 Spork.exec_each_run147 TrapTest.output.should == ['goodbye', 'hello']148 end149 end150end...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?