Object
This is used by bin/spork. It’s wrapped in a class because it’s easier to test that way.
# File lib/spork/runner.rb, line 12 12: def initialize(args, output, error) 13: raise ArgumentError, "expected array of args" unless args.is_a?(Array) 14: @output = output 15: @error = error 16: @options = {} 17: opt = OptionParser.new 18: opt.banner = "Usage: spork [test framework name] [options]\n\n" 19: 20: opt.separator "Options:" 21: opt.on("-b", "--bootstrap") {|ignore| @options[:bootstrap] = true } 22: opt.on("-d", "--diagnose") {|ignore| @options[:diagnose] = true } 23: opt.on("-h", "--help") {|ignore| @options[:help] = true } 24: opt.on("-p", "--port [PORT]") {|port| @options[:port] = port } 25: non_option_args = args.select { |arg| ! args[0].match(/^-/) } 26: @options[:server_matcher] = non_option_args[0] 27: opt.parse!(args) 28: 29: if @options[:help] 30: @output.puts opt 31: @output.puts 32: @output.puts supported_test_frameworks_text 33: exit(0) 34: end 35: end
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.
# File lib/spork/runner.rb, line 47 47: def find_test_framework 48: Spork::TestFramework.factory(@output, @error, options[:server_matcher]) 49: rescue Spork::TestFramework::NoFrameworksAvailable => e 50: @error.puts e.message 51: rescue Spork::TestFramework::FactoryException => e 52: @error.puts "#{e.message}\n\n#{supported_test_frameworks_text}" 53: end
# File lib/spork/runner.rb, line 55 55: def run 56: return false unless test_framework = find_test_framework 57: ENV["DRB"] = 'true' 58: @error.puts "Using #{test_framework.short_name}" 59: @error.flush 60: 61: case 62: when options[:bootstrap] 63: test_framework.bootstrap 64: when options[:diagnose] 65: require 'spork/diagnoser' 66: 67: Spork::Diagnoser.install_hook!(test_framework.entry_point) 68: test_framework.preload 69: Spork::Diagnoser.output_results(@output) 70: return true 71: else 72: Spork.using_spork! 73: run_strategy = Spork::RunStrategy.factory(test_framework) 74: return(false) unless run_strategy.preload 75: Spork::Server.run(:port => @options[:port] || test_framework.default_port, :run_strategy => run_strategy) 76: return true 77: end 78: end
# File lib/spork/runner.rb, line 37 37: def supported_test_frameworks_text 38: text = StringIO.new 39: 40: text.puts "Supported test frameworks:" 41: text.puts Spork::TestFramework.supported_test_frameworks.sort { |a,b| a.short_name <=> b.short_name }.map { |s| (s.available? ? '(*) ' : '( ) ') + s.short_name } 42: text.puts "\nLegend: ( ) - not detected in project (*) - detected\n" 43: text.string 44: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.