Parent

Included Modules

Spork::Server

An abstract class that is implemented to create a server

(This was originally based off of spec_server.rb from rspec-rails (David Chelimsky), which was based on Florian Weber’s TDDMate)

Attributes

run_strategy[R]
port[RW]

Public Class Methods

new(options = {}) click to toggle source
    # File lib/spork/server.rb, line 14
14:   def initialize(options = {})
15:     @run_strategy = options[:run_strategy]
16:     @port = options[:port]
17:   end
run(options = {}) click to toggle source
    # File lib/spork/server.rb, line 19
19:   def self.run(options = {})
20:     new(options).listen
21:   end

Public Instance Methods

abort() click to toggle source
    # File lib/spork/server.rb, line 50
50:   def abort
51:     run_strategy.abort
52:   end
listen() click to toggle source

Sets up signals and starts the DRb service. If it’s successful, it doesn’t return. Not ever. You don’t need to override this.

    # File lib/spork/server.rb, line 24
24:   def listen
25:     raise RuntimeError, "you must call Spork.using_spork! before starting the server" unless Spork.using_spork?
26:     trap("SIGINT") { sig_int_received }
27:     trap("SIGTERM") { abort; exit!(0) }
28:     trap("USR2") { abort; restart } if Signal.list.has_key?("USR2")
29:     @drb_service = DRb.start_service("druby://127.0.0.1:#{port}", self)
30:     Spork.each_run { @drb_service.stop_service } if @run_strategy.class == Spork::RunStrategy::Forking
31:     stderr.puts "Spork is ready and listening on #{port}!"
32:     stderr.flush
33:     DRb.thread.join
34:   end
run(argv, stderr, stdout) click to toggle source

This is the public facing method that is served up by DRb. To use it from the client side (in a testing framework):

  DRb.start_service("druby://localhost:0") # this allows Ruby to do some magical stuff so you can pass an output stream over DRb.
                                           # see http://redmine.ruby-lang.org/issues/show/496 to see why localhost:0 is used.
  spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
  spec_server.run(options.argv, $stderr, $stdout)

When implementing a test server, don’t override this method: override run_tests instead.

    # File lib/spork/server.rb, line 46
46:   def run(argv, stderr, stdout)
47:     run_strategy.run(argv, stderr, stdout)
48:   end

Private Instance Methods

restart() click to toggle source
    # File lib/spork/server.rb, line 55
55:     def restart
56:       stderr.puts "restarting"
57:       stderr.flush
58:       config       = ::Config::CONFIG
59:       ruby         = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
60:       command_line = [ruby, $0, ARGV].flatten.join(' ')
61:       exec(command_line)
62:     end
sig_int_received() click to toggle source
    # File lib/spork/server.rb, line 64
64:     def sig_int_received
65:       stdout.puts "\n"
66:       if run_strategy.running?
67:         abort
68:         stderr.puts "Running tests stopped.  Press CTRL-C again to stop the server."
69:         stderr.flush
70:       else
71:         exit!(0)
72:       end
73:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.