Spork

Constants

BINARY
LIBDIR

Public Class Methods

after_each_run(prevent_double_run = true, &block) click to toggle source

Run a block after specs are run.

Parameters

  • 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
detect_and_require(subfolder) click to toggle source
     # 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
each_run(prevent_double_run = true, &block) click to toggle source

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.

Parameters

  • 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
exec_after_each_run() click to toggle source

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
exec_each_run(&block) click to toggle source

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
exec_prefork(&block) click to toggle source

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
other_spork_gem_load_paths() click to toggle source
     # 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
prefork(prevent_double_run = true, &block) click to toggle source

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.

Parameters

  • 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
state() click to toggle source

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
trap_class_method(klass, method_name) click to toggle source

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
trap_method(klass, method_name) click to toggle source

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
using_spork!() click to toggle source

Used by the server. Sets the state to activate spork. Otherwise, prefork and each_run are run in passive mode, allowing specs without a Spork server.

    # File lib/spork.rb, line 51
51:     def using_spork!
52:       @state = :using_spork
53:     end
using_spork?() click to toggle source
    # File lib/spork.rb, line 55
55:     def using_spork?
56:       @state == :using_spork
57:     end

Private Class Methods

activate_after_each_run_at_exit_hook() click to toggle source
     # 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
after_each_run_procs() click to toggle source
     # File lib/spork.rb, line 152
152:       def after_each_run_procs
153:         @after_each_run_procs ||= []
154:       end
alias_method_names(method_name, feature) click to toggle source
     # 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
already_ran() click to toggle source
     # File lib/spork.rb, line 132
132:       def already_ran
133:         @already_ran ||= []
134:       end
already_ran?(caller_script_and_line) click to toggle source
     # 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
at_exit(&block) click to toggle source
     # File lib/spork.rb, line 121
121:           def at_exit(&block)
122:             Spork.after_each_run(false, &block)
123:           end
each_run_procs() click to toggle source
     # File lib/spork.rb, line 148
148:       def each_run_procs
149:         @each_run_procs ||= []
150:       end
expanded_caller(caller_line) click to toggle source
     # File lib/spork.rb, line 136
136:       def expanded_caller(caller_line)
137:         file, line = caller_line.split(/:(\d+)/)
138:         line.gsub(/:.+/, '')
139:         File.expand_path(file, Dir.pwd) + ":" + line
140:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.