diff --git a/README.md b/README.md new file mode 100644 index 0000000..e431264 --- /dev/null +++ b/README.md @@ -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 + diff --git a/guard-rspec-hydra.gemspec b/guard-hydra.gemspec similarity index 69% rename from guard-rspec-hydra.gemspec rename to guard-hydra.gemspec index 3d0c52d..abf963a 100644 --- a/guard-rspec-hydra.gemspec +++ b/guard-hydra.gemspec @@ -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 diff --git a/lib/guard-hydra.rb b/lib/guard-hydra.rb new file mode 100644 index 0000000..b7a82ec --- /dev/null +++ b/lib/guard-hydra.rb @@ -0,0 +1 @@ +require 'guard/hydra' diff --git a/lib/guard-rspec-hydra.rb b/lib/guard-rspec-hydra.rb deleted file mode 100644 index 6248e02..0000000 --- a/lib/guard-rspec-hydra.rb +++ /dev/null @@ -1 +0,0 @@ -require 'guard/rspec-hydra' diff --git a/lib/guard/hydra.rb b/lib/guard/hydra.rb new file mode 100644 index 0000000..18190a1 --- /dev/null +++ b/lib/guard/hydra.rb @@ -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 diff --git a/lib/guard/hydra/templates/Guardfile b/lib/guard/hydra/templates/Guardfile new file mode 100644 index 0000000..255d427 --- /dev/null +++ b/lib/guard/hydra/templates/Guardfile @@ -0,0 +1,4 @@ +guard 'hydra' do + # All spec files + watch(%r{spec/**/*_spec.rb}) +end diff --git a/lib/guard/rspec-hydra.rb b/lib/guard/rspec-hydra.rb deleted file mode 100644 index b794f5b..0000000 --- a/lib/guard/rspec-hydra.rb +++ /dev/null @@ -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