How to use at_exit method of Spork Package

Best Spork_ruby code snippet using Spork.at_exit

spork.rb

Source:spork.rb Github

copy

Full Screen

...60 61 # Used by the server. Called to run all of the prefork blocks.62 def exec_each_run(&block)63 @state = :run64 activate_after_each_run_at_exit_hook65 each_run_procs.each { |p| p.call }66 each_run_procs.clear67 yield if block_given?68 end69 70 # Used by the server. Called to run all of the after_each_run blocks.71 def exec_after_each_run72 # processes in reverse order similar to at_exit73 while p = after_each_run_procs.pop; p.call; end74 true75 end76 # Traps an instance method of a class (or module) so any calls to it don't actually run until Spork.exec_each_run77 def trap_method(klass, method_name)78 method_name_without_spork, method_name_with_spork = alias_method_names(method_name, :spork)79 80 klass.class_eval <<-EOF, __FILE__, __LINE__ + 181 alias :#{method_name_without_spork} :#{method_name} unless method_defined?(:#{method_name_without_spork}) 82 def #{method_name}(*args, &block)83 Spork.each_run(false) do84 #{method_name_without_spork}(*args, &block)85 end86 end87 EOF88 end89 90 # Same as trap_method, but for class methods instead91 def trap_class_method(klass, method_name)92 trap_method((class << klass; self; end), method_name)93 end94 95 def detect_and_require(subfolder)96 ([LIBDIR.to_s] + other_spork_gem_load_paths).uniq.each do |gem_path|97 Dir.glob(File.join(gem_path, subfolder)).each { |file| require file }98 end99 end100 # This method is used to auto-discover peer plugins such as spork-testunit.101 def other_spork_gem_load_paths102 @other_spork_gem_load_paths ||= Spork::GemHelpers.latest_load_paths.grep(/spork/).select do |g|103 not g.match(%r{/spork-[0-9\-.]+/lib}) # don't include other versions of spork104 end105 end106 private107 def activate_after_each_run_at_exit_hook108 Kernel.module_eval do109 def at_exit(&block)110 Spork.after_each_run(false, &block)111 end112 end113 end114 def alias_method_names(method_name, feature)115 /^(.+?)([\?\!]{0,1})$/.match(method_name.to_s)116 ["#{$1}_without_spork#{$2}", "#{$1}_with_spork#{$2}"]117 end118 119 def already_ran120 @already_ran ||= []121 end122 123 def expanded_caller(caller_line)...

Full Screen

Full Screen

spec_helper.rb

Source:spec_helper.rb Github

copy

Full Screen

1module Kernel2 alias :__at_exit :at_exit3 def at_exit(&block)4 __at_exit do5 exit_status = $!.status if $!.is_a?(SystemExit)6 block.call7 exit exit_status if exit_status8 end9 end10end11require 'rubygems'12prefork = -> {13 ENV["RAILS_ENV"] ||= 'test'14 require 'rails/mongoid'15 # Spork.trap_class_method(Rails::Mongoid, :load_models)16 # Spork.trap_method(Rails::Application, :eager_load!)17 # Spork.trap_method(Rails::Application::RoutesReloader, :reload!)18 require 'factory_girl_rails'...

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:

YouTube

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?

Helpful

NotHelpful