class Runner def self.load(options = {}) @options = options @inspector = Inspector.new @interactor = Interactor.new(@options) puts "** RSpactor is now watching at '#{Dir.pwd}'#{' and using spec_server' if @options[:drb]}" if initial_spec_run_abort @interactor.start_termination_handler else @interactor.start_termination_handler run_all_specs end Listener.new do |files| run_specs_for_files(files) end end def self.run_all_specs run_spec_command([@inspector.inner_spec_directory(Dir.pwd)]) end def self.run_specs_for_files(files) files_to_spec = [] files.each do |file| spec_file = @inspector.find_spec_file(file) files_to_spec << spec_file if spec_file && !files_to_spec.include?(spec_file) end unless files_to_spec.empty? system("clear;") if @options[:clear] files_to_spec.each { |spec_file| puts spec_file } run_spec_command(files_to_spec) end end def self.run_spec_command(locations) if locations.first base_spec_root = extract_spec_root(locations.first) spec_runner_bin = script_runner(locations.first) locations = locations.join(" ") cmd = "RAILS_ENV=test; " cmd << "#{spec_runner_bin} " cmd << "#{locations} #{spec_opts(base_spec_root)} " cmd << "--drb " if @options[:drb] cmd << "-r #{File.dirname(__FILE__)}/../lib/resulting.rb -f RSpactorFormatter:STDOUT" # puts cmd system(cmd) end end def self.extract_spec_root(file) file[0..file.index("spec") + 4] end def self.spec_opts(base_spec_root) if File.exist?("#{base_spec_root}spec.opts") return "-O #{base_spec_root}spec.opts" else return "-c -f progress" end end def self.initial_spec_run_abort @interactor.wait_for_enter_key("** Hit to skip initial spec run", 3) end def self.script_runner(file) # root = file[0..file.index("spec") - 1] # if File.exist?(root + "script/spec") # return root + "script/spec" # else # "spec" # end "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby /Library/Ruby/Gems/1.8/gems/rspec-1.1.99.10/bin/spec" end end