Run a block after specs are run.
prevent_double_run - Pass false to disable double run prevention
# File lib/spork.rb, line 45 45: def after_each_run(prevent_double_run = true, &block) 46: return if prevent_double_run && already_ran?(caller.first) 47: after_each_run_procs << block 48: end
# File lib/spork.rb, line 104 104: def detect_and_require(subfolder) 105: ([LIBDIR.to_s] + other_spork_gem_load_paths).uniq.each do |gem_path| 106: Dir.glob(File.join(gem_path, subfolder)).each { |file| require file } 107: end 108: end
Run a block AFTER the fork occurs. By default, if prefork is called twice in the same file and line number, the supplied block will only be ran once.
prevent_double_run - Pass false to disable double run prevention
# File lib/spork.rb, line 31 31: def each_run(prevent_double_run = true, &block) 32: return if prevent_double_run && already_ran?(caller.first) 33: if @state == :using_spork 34: each_run_procs << block 35: else 36: yield 37: end 38: end
Used by the server. Called to run all of the after_each_run blocks.
# File lib/spork.rb, line 79 79: def exec_after_each_run 80: # processes in reverse order similar to at_exit 81: while p = after_each_run_procs.pop; p.call; end 82: true 83: end
Used by the server. Called to run all of the prefork blocks.
# File lib/spork.rb, line 71 71: def exec_each_run(&block) 72: activate_after_each_run_at_exit_hook 73: each_run_procs.each { |p| p.call } 74: each_run_procs.clear 75: yield if block_given? 76: end
Used by the server. Called when loading the prefork blocks of the code.
# File lib/spork.rb, line 65 65: def exec_prefork(&block) 66: using_spork! 67: yield 68: end
# File lib/spork.rb, line 110 110: def other_spork_gem_load_paths 111: @other_spork_gem_load_paths ||= ( 112: Gem.latest_load_paths.grep(/spork/).select do |g| 113: not g.match(%{/spork-[0-9\-.]+/lib}) # don't include other versions of spork 114: end 115: ) 116: end
Run a block, during prefork mode. By default, if prefork is called twice in the same file and line number, the supplied block will only be ran once.
prevent_double_run - Pass false to disable double run prevention
# File lib/spork.rb, line 21 21: def prefork(prevent_double_run = true, &block) 22: return if prevent_double_run && already_ran?(caller.first) 23: yield 24: end
Used by the server. Returns the current state of Spork.
# File lib/spork.rb, line 60 60: def state 61: @state ||= :not_using_spork 62: end
Same as trap_method, but for class methods instead
# File lib/spork.rb, line 100 100: def trap_class_method(klass, method_name) 101: trap_method((class << klass; self; end), method_name) 102: end
Traps an instance method of a class (or module) so any calls to it don’t actually run until Spork.exec_each_run
# File lib/spork.rb, line 86 86: def trap_method(klass, method_name) 87: method_name_without_spork, method_name_with_spork = alias_method_names(method_name, :spork) 88: 89: klass.class_eval alias :#{method_name_without_spork} :#{method_name} unless method_defined?(:#{method_name_without_spork}) def #{method_name}(*args) Spork.each_run(false) do #{method_name_without_spork}(*args) end end, __FILE__, __LINE__ + 1 90: end
# File lib/spork.rb, line 119 119: def activate_after_each_run_at_exit_hook 120: Kernel.module_eval do 121: def at_exit(&block) 122: Spork.after_each_run(false, &block) 123: end 124: end 125: end
# File lib/spork.rb, line 152 152: def after_each_run_procs 153: @after_each_run_procs ||= [] 154: end
# File lib/spork.rb, line 127 127: def alias_method_names(method_name, feature) 128: /^(.+?)([\?\!]{0,1})$/.match(method_name.to_s) 129: ["#{$1}_without_spork#{$2}", "#{$1}_with_spork#{$2}"] 130: end
# File lib/spork.rb, line 132 132: def already_ran 133: @already_ran ||= [] 134: end
# File lib/spork.rb, line 142 142: def already_ran?(caller_script_and_line) 143: return true if already_ran.include?(expanded_caller(caller_script_and_line)) 144: already_ran << expanded_caller(caller_script_and_line) 145: false 146: end
# File lib/spork.rb, line 121 121: def at_exit(&block) 122: Spork.after_each_run(false, &block) 123: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.