Class: Spork::Runner
- Inherits:
-
Object
- Object
- Spork::Runner
- Defined in:
- lib/spork/runner.rb
Overview
This is used by bin/spork. It’s wrapped in a class because it’s easier to test that way.
Instance Attribute Summary collapse
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
Instance Method Summary collapse
-
#find_server ⇒ Object
Returns a server for the specified (or the detected default) testing framework.
-
#initialize(args, output, error) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
- #supported_servers_text ⇒ Object
Constructor Details
#initialize(args, output, error) ⇒ Runner
Returns a new instance of Runner.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spork/runner.rb', line 13 def initialize(args, output, error) raise ArgumentError, "expected array of args" unless args.is_a?(Array) @output = output @error = error @options = {} opt = OptionParser.new opt. = "Usage: spork [test framework name] [options]\n\n" opt.separator "Options:" opt.on("-b", "--bootstrap") {|ignore| @options[:bootstrap] = true } opt.on("-d", "--diagnose") {|ignore| @options[:diagnose] = true } opt.on("-h", "--help") {|ignore| @options[:help] = true } non_option_args = args.select { |arg| ! args[0].match(/^-/) } @options[:server_matcher] = non_option_args[0] opt.parse!(args) if @options[:help] @output.puts opt @output.puts @output.puts supported_servers_text exit(0) end end |
Instance Attribute Details
#server ⇒ Object (readonly)
Returns the value of attribute server.
7 8 9 |
# File 'lib/spork/runner.rb', line 7 def server @server end |
Class Method Details
.run(args, output, error) ⇒ Object
9 10 11 |
# File 'lib/spork/runner.rb', line 9 def self.run(args, output, error) self.new(args, output, error).run end |
Instance Method Details
#find_server ⇒ Object
Returns a server for the specified (or the detected default) testing framework. Returns nil if none detected, or if the specified is not supported or available.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/spork/runner.rb', line 47 def find_server if [:server_matcher] @server = Spork::Server.supported_servers([:server_matcher]).first unless @server @error.puts <<-ERROR #{[:server_matcher].inspect} didn't match a supported test framework. #{supported_servers_text} ERROR return end unless @server.available? @error.puts <<-USEFUL_ERROR I can't find the helper file #{@server.helper_file} for the #{@server.server_name} testing framework. Are you running me from the project directory? USEFUL_ERROR return end else @server = Spork::Server.available_servers.first if @server.nil? @error.puts <<-USEFUL_ERROR I can't find any testing frameworks to use. Are you running me from a project directory? USEFUL_ERROR return end end @server end |
#run ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/spork/runner.rb', line 79 def run return false unless find_server ENV["DRB"] = 'true' @error.puts "Using #{server.server_name}" @error.flush case when [:bootstrap] server.bootstrap when [:diagnose] require 'spork/diagnoser' Spork::Diagnoser.install_hook!(server.entry_point) server.preload Spork::Diagnoser.output_results(@output) return true else return(false) unless server.preload server.run return true end end |
#supported_servers_text ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/spork/runner.rb', line 37 def supported_servers_text text = StringIO.new text.puts "Supported test frameworks:" text.puts Spork::Server.supported_servers.sort { |a,b| a.server_name <=> b.server_name }.map { |s| (s.available? ? '(*) ' : '( ) ') + s.server_name } text.puts "\nLegend: ( ) - not detected in project (*) - detected\n" text.string end |