whoa it really works

This commit is contained in:
John Bintz 2011-08-04 13:35:32 -04:00
parent 69e883a67a
commit a31ffc3bed
7 changed files with 92 additions and 39 deletions

12
README.md Normal file
View File

@ -0,0 +1,12 @@
Use Guard with Hydra and get super-parallel test execution! Awesome!
Options:
* `:runner_log`: The location of the runner log where output is printed
* `:clear_runner_log`: Remove the runner log before each run
* `:show_runner_log`: Show the runner log after each run
* `:hydra_config`: The location of your Hydra config file
* `:test_matchers`: What glob would match the kind of tests you want to run
* `:all_on_start`: Run all tests when starting Guard

View File

@ -2,13 +2,13 @@
$:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "guard-rspec-hydra"
s.name = "guard-hydra"
s.version = '0.0.1'
s.authors = ["John Bintz"]
s.email = ["john@coswellproductions.com"]
s.homepage = ""
s.summary = %q{Extend Guard::RSpec to use Hydra to run all specs. Super-fast!}
s.description = %q{Extend Guard::RSpec to use Hydra to run all specs. Super-fast!}
s.summary = %q{Use Hydra to run all specs. Super-fast!}
s.description = %q{Use Hydra to run all specs. Super-fast!}
s.rubyforge_project = "guard-rspec-hydra"
@ -18,5 +18,5 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency 'guard', '>= 0.5.0'
s.add_dependency 'guard-rspec'
s.add_dependency 'hydra'
end

1
lib/guard-hydra.rb Normal file
View File

@ -0,0 +1 @@
require 'guard/hydra'

View File

@ -1 +0,0 @@
require 'guard/rspec-hydra'

71
lib/guard/hydra.rb Normal file
View File

@ -0,0 +1,71 @@
require 'guard'
require 'guard/guard'
require 'hydra'
require 'hydra/master'
class Guard::Hydra < Guard::Guard
MATCHERS = {
:rspec => '**/*_spec.rb'
}
def initialize(watchers = [], options = {})
super
@options = {
:runner_log => 'hydra-runner.log',
:clear_runner_log => true,
:show_runner_log => true,
:hydra_config => 'config/hydra.yml',
:test_matchers => [ :rspec ],
:all_on_start => false
}.merge(@options)
end
def start
super
Guard::UI.info "Guard::Hydra is waiting to run tests..."
run_all if @options[:all_on_start]
end
def run_on_change(files = [])
files.uniq!
Guard::UI.info "Running Hydra on #{files.join(', ')}"
run_all if run_hydra(files)
end
def run_all
Guard::UI.info "Running Hydra on all matching tests..."
run_hydra(matching_tests)
end
private
def run_hydra(files = [])
File.unlink @options[:runner_log] if runner_log? && @options[:clear_runner_log]
start = Time.now
hydra = Hydra::Master.new(
:listeners => [ Hydra::Listener::ProgressBar.new ],
:files => files.uniq,
:environment => 'test',
:config => @options[:hydra_config]
)
Guard::UI.info sprintf("Tests completed in %.6f seconds", Time.now - start)
puts File.read(@options[:runner_log]) if runner_log? && @options[:show_runner_log]
hydra.failed_files.empty?
end
def runner_log?
File.exist?(@options[:runner_log])
end
def rails_application
File.expand_path('config/application')
end
def matching_tests
Guard::Watcher.match_files(self, @options[:test_matchers].collect { |match| Dir[MATCHERS[match]] }.flatten).uniq
end
end

View File

@ -0,0 +1,4 @@
guard 'hydra' do
# All spec files
watch(%r{spec/**/*_spec.rb})
end

View File

@ -1,34 +0,0 @@
require 'guard'
require 'guard/guard'
require 'guard/rspec'
class Guard::RSpecHydra < Guard::RSpec
def initialize(watchers = [], options = {})
super
@options = {
:rails_env => 'test',
:rake_task => 'hydra:spec',
:runner_log => 'hydra-runner.log',
:show_runner_log => true
}.merge(@options)
end
def start
Guard::UI.info "Guard::Hydra is giving Guard::RSpec super run_all powers. Whoa!"
super
end
def run_all
File.unlink(@options[:runner_log]) if runner_log?
system %{rake RAILS_ENV=#{@options[:rails_env]} #{@options[:rake_task]}}
puts File.read(@options[:runner_log]) if runner_log? && @options[:show_runner_log]
end
private
def runner_log?
File.exist?(@options[:runner_log])
end
end