Class: Spork::Server
- Inherits:
-
Object
- Object
- Spork::Server
- Includes:
- CustomIOStreams
- Defined in:
- lib/spork/server.rb
Overview
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)
Instance Attribute Summary (collapse)
-
- (Object) port
Returns the value of attribute port.
-
- (Object) run_strategy
readonly
Returns the value of attribute run_strategy.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) abort
-
- (Server) initialize(options = {})
constructor
A new instance of Server.
-
- (Object) listen
Sets up signals and starts the DRb service.
-
- (Object) run(argv, stderr, stdout)
This is the public facing method that is served up by DRb.
Methods included from CustomIOStreams
Constructor Details
- (Server) initialize(options = {})
A new instance of Server
14 15 16 17 |
# File 'lib/spork/server.rb', line 14 def initialize( = {}) @run_strategy = [:run_strategy] @port = [:port] end |
Instance Attribute Details
- (Object) port
Returns the value of attribute port
36 37 38 |
# File 'lib/spork/server.rb', line 36 def port @port end |
- (Object) run_strategy (readonly)
Returns the value of attribute run_strategy
11 12 13 |
# File 'lib/spork/server.rb', line 11 def run_strategy @run_strategy end |
Class Method Details
+ (Object) run(options = {})
19 20 21 |
# File 'lib/spork/server.rb', line 19 def self.run( = {}) new().listen end |
Instance Method Details
- (Object) abort
53 54 55 |
# File 'lib/spork/server.rb', line 53 def abort run_strategy.abort end |
- (Object) listen
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.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/spork/server.rb', line 24 def listen @run_strategy.assert_ready! trap("SIGINT") { sig_int_received } trap("SIGTERM") { abort; exit!(0) } trap("USR2") { abort; restart } if Signal.list.has_key?("USR2") @drb_service = DRb.start_service("druby://127.0.0.1:#{port}", self) Spork.each_run { @drb_service.stop_service } if @run_strategy.class == Spork::RunStrategy::Forking stderr.puts "Spork is ready and listening on #{port}!" stderr.flush DRb.thread.join end |
- (Object) run(argv, stderr, stdout)
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(.argv, $stderr, $stdout)
When implementing a test server, don't override this method: override run_tests instead.
46 47 48 49 50 51 |
# File 'lib/spork/server.rb', line 46 def run(argv, stderr, stdout) puts "Running tests with args #{argv.inspect}..." result = run_strategy.run(argv, stderr, stdout) puts "Done.\n\n" result end |