Module Spork
In: lib/spork/runner.rb
lib/spork.rb

Methods

Classes and Modules

Module Spork::AppFramework
Module Spork::CustomIOStreams
Module Spork::RunStrategy
Module Spork::TestFramework
Class Spork::AppFramework
Class Spork::Diagnoser
Class Spork::Forker
Class Spork::RunStrategy
Class Spork::Runner
Class Spork::Server
Class Spork::TestFramework

Constants

BINARY = File.expand_path(File.dirname(__FILE__) + '/../bin/spork')
LIBDIR = File.expand_path("..", File.dirname(__FILE__))

Public Class methods

[Source]

# File lib/spork.rb, line 78
    def detect_and_require(subfolder)
      ([LIBDIR] + Gem.latest_load_paths.grep(/spork/)).uniq.each do |gem_path|
        Dir.glob(File.join(gem_path, subfolder)).each { |file| require file }
      end
    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.

Parameters

  • prevent_double_run - Pass false to disable double run prevention

[Source]

# File lib/spork.rb, line 22
    def each_run(prevent_double_run = true, &block)
      return if prevent_double_run && already_ran?(caller.first)
      if @state == :using_spork
        each_run_procs << block
      else
        yield
      end
    end

Used by the server. Called to run all of the prefork blocks.

[Source]

# File lib/spork.rb, line 52
    def exec_each_run(&block)
      each_run_procs.each { |p| p.call }
      each_run_procs.clear
      yield if block_given?
    end

Used by the server. Called when loading the prefork blocks of the code.

[Source]

# File lib/spork.rb, line 46
    def exec_prefork(&block)
      using_spork!
      yield
    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.

Parameters

  • prevent_double_run - Pass false to disable double run prevention

[Source]

# File lib/spork.rb, line 12
    def prefork(prevent_double_run = true, &block)
      return if prevent_double_run && already_ran?(caller.first)
      yield
    end

Used by the server. Returns the current state of Spork.

[Source]

# File lib/spork.rb, line 41
    def state
      @state ||= :not_using_spork
    end

Same as trap_method, but for class methods instead

[Source]

# File lib/spork.rb, line 74
    def trap_class_method(klass, method_name)
      trap_method((class << klass; self; end), method_name)
    end

Traps an instance method of a class (or module) so any calls to it don‘t actually run until Spork.exec_each_run

[Source]

# File lib/spork.rb, line 59
    def trap_method(klass, method_name)
      method_name_without_spork, method_name_with_spork = alias_method_names(method_name, :spork)
      
      klass.class_eval "alias :\#{method_name_without_spork} :\#{method_name} unless method_defined?(:\#{method_name_without_spork})\ndef \#{method_name}(*args)\nSpork.each_run(false) do\n\#{method_name_without_spork}(*args)\nend\nend\n", __FILE__, __LINE__ + 1
    end

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.

[Source]

# File lib/spork.rb, line 32
    def using_spork!
      @state = :using_spork
    end

[Source]

# File lib/spork.rb, line 36
    def using_spork?
      @state == :using_spork
    end

[Validate]