lib/rspactor/runner.rb in guillaumegentil-rspactor-0.3.4 vs lib/rspactor/runner.rb in guillaumegentil-rspactor-0.4

- old
+ new

@@ -21,21 +21,21 @@ start_interactor start_listener end def start_interactor - @interactor = Interactor.new(dir) + @interactor = Interactor.new(dir, options) aborted = @interactor.wait_for_enter_key("** Hit <enter> to skip initial spec run", 3) @interactor.start_termination_handler run_all_specs unless aborted end def start_listener @inspector = Inspector.new(dir) Listener.new(Inspector::EXTENSIONS) do |files| - spec_changed_files(files) unless git_head_changed? + changed_files(files) unless git_head_changed? end.run(dir) end def load_dotfile dotfile = File.join(ENV['HOME'], '.rspactor') @@ -60,31 +60,44 @@ cmd = [ruby_opts, spec_runner, paths, spec_opts].flatten.join(' ') @last_run_failed = run_command(cmd) end end + def run_cucumber_command + cmd = [ruby_opts, cucumber_runner, cucumber_opts].flatten.join(' ') + @last_run_failed = run_command(cmd) + system('killall java') if options[:kill] + end + def last_run_failed? @last_run_failed == false end protected def run_command(cmd) - $stderr.puts "#{cmd}" system(cmd) $?.success? end - def spec_changed_files(files) - files_to_spec = files.inject([]) do |all, file| - all.concat inspector.determine_spec_files(file) + def changed_files(files) + files = files.inject([]) do |all, file| + all.concat inspector.determine_files(file) end - unless files_to_spec.empty? - puts files_to_spec.join("\n") + unless files.empty? + system("clear;") if @options[:clear] + if files.delete('cucumber') + puts '--- cucumber current tagged features ---' + run_cucumber_command + end + + # specs files + puts files.map { |f| f.to_s.gsub(/#{dir}/, '') }.join("\n") + previous_run_failed = last_run_failed? - run_spec_command(files_to_spec) + run_spec_command(files) if options[:retry_failed] and previous_run_failed and not last_run_failed? run_all_specs end end @@ -97,25 +110,51 @@ opts = File.read('spec/spec.opts').gsub("\n", ' ') else opts = "--color" end - opts << ' ' << formatter_opts + opts << spec_formatter_opts # only add the "progress" formatter unless no other (besides growl) is specified opts << ' -f progress' unless opts.scan(/\s(?:-f|--format)\b/).length > 1 opts end - def formatter_opts - "-r #{File.dirname(__FILE__)}/../rspec_growler.rb -f RSpecGrowler:STDOUT" + def cucumber_opts + if File.exist?('features/support/cucumber.opts') + opts = File.read('features/support/cucumber.opts').gsub("\n", ' ') + else + opts = "--format progress --drb " + end + + opts << " --tags current" + opts << cucumber_formatter_opts + opts << " --require features" # because cucumber_formatter_opts overwrite default features require + opts << " features" + opts end + def spec_formatter_opts + " --require #{File.dirname(__FILE__)}/../rspec_growler.rb --format RSpecGrowler:STDOUT" + end + + def cucumber_formatter_opts + " --require #{File.dirname(__FILE__)}/../cucumber_growler.rb" + end + def spec_runner if File.exist?("script/spec") "script/spec" else "spec" + end + end + + def cucumber_runner + if File.exist?("script/cucumber") + "script/cucumber" + else + "cucumber" end end def ruby_opts other = ENV['RUBYOPT'] ? " #{ENV['RUBYOPT']}" : '' \ No newline at end of file