guard-hydra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-rspec-hydra.gemspec
4
+ gemspec
@@ -0,0 +1,12 @@
1
+ Use Guard with Hydra and get super-parallel test execution! Awesome!
2
+
3
+
4
+ Options:
5
+
6
+ * `:runner_log`: The location of the runner log where output is printed
7
+ * `:clear_runner_log`: Remove the runner log before each run
8
+ * `:show_runner_log`: Show the runner log after each run
9
+ * `:hydra_config`: The location of your Hydra config file
10
+ * `:test_matchers`: What glob would match the kind of tests you want to run
11
+ * `:all_on_start`: Run all tests when starting Guard
12
+
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "guard-hydra"
6
+ s.version = '0.0.1'
7
+ s.authors = ["John Bintz"]
8
+ s.email = ["john@coswellproductions.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{Use Hydra to run all specs. Super-fast!}
11
+ s.description = %q{Use Hydra to run all specs. Super-fast!}
12
+
13
+ s.rubyforge_project = "guard-rspec-hydra"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'guard', '>= 0.5.0'
21
+ s.add_dependency 'hydra'
22
+ end
@@ -0,0 +1 @@
1
+ require 'guard/hydra'
@@ -0,0 +1,111 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ require 'hydra'
5
+ require 'hydra/master'
6
+
7
+ class Guard::Hydra < Guard::Guard
8
+ MATCHERS = {
9
+ :rspec => '**/*_spec.rb'
10
+ }
11
+
12
+ def initialize(watchers = [], options = {})
13
+ super
14
+ @options = {
15
+ :runner_log => 'hydra-runner.log',
16
+ :clear_runner_log => true,
17
+ :show_runner_log => true,
18
+ :hydra_config => 'config/hydra.yml',
19
+ :test_matchers => [ :rspec ],
20
+ :all_on_start => false,
21
+ :env => 'test'
22
+ }.merge(@options)
23
+ end
24
+
25
+ def start
26
+ super
27
+ Guard::UI.info "Guard::Hydra is waiting to run tests..."
28
+
29
+ begin
30
+ ENV['RAILS_ENV'] = @options[:env]
31
+ require rails_application
32
+ rescue LoadError
33
+ Guard::UI.info "Not a Rails app, using default environment settings"
34
+ end
35
+
36
+ @did_fail = false
37
+
38
+ run_all if @options[:all_on_start]
39
+ end
40
+
41
+ def run_on_change(files = [])
42
+ if !(files = ensure_files(files)).empty?
43
+ Guard::UI.info "Running Hydra on #{files.join(', ')}"
44
+ if run_hydra(files)
45
+ run_all if @did_fail
46
+ @did_fail = false
47
+ else
48
+ @did_fail = true
49
+ end
50
+ end
51
+ end
52
+
53
+ def run_all
54
+ Guard::UI.info "Running Hydra on all matching tests..."
55
+ run_hydra(ensure_files(matching_tests))
56
+ end
57
+
58
+ private
59
+ def run_hydra(files = [])
60
+ if !files.empty?
61
+ File.unlink @options[:runner_log] if runner_log? && @options[:clear_runner_log]
62
+
63
+ start = Time.now
64
+
65
+ hydra = Hydra::Master.new(
66
+ :listeners => [ Hydra::Listener::ProgressBar.new ],
67
+ :files => files,
68
+ :environment => @options[:env],
69
+ :config => @options[:hydra_config]
70
+ )
71
+
72
+ Guard::UI.info sprintf("Tests completed in %.6f seconds", Time.now - start)
73
+
74
+ puts File.read(@options[:runner_log]) if runner_log? && @options[:show_runner_log]
75
+ hydra.failed_files.empty?
76
+ else
77
+ Guard::UI.info "No files matched!"
78
+ false
79
+ end
80
+ end
81
+
82
+ def runner_log?
83
+ File.exist?(@options[:runner_log])
84
+ end
85
+
86
+ def rails_application
87
+ File.expand_path('config/application')
88
+ end
89
+
90
+ def matching_tests
91
+ Guard::Watcher.match_files(self, match_test_matchers).uniq
92
+ end
93
+
94
+ def match_test_matchers(source = nil)
95
+ @options[:test_matchers].collect do |match|
96
+ path = MATCHERS[match]
97
+ path = File.join(source, path) if source
98
+ Dir[path]
99
+ end.flatten
100
+ end
101
+
102
+ def ensure_files(files = [])
103
+ files.collect do |file|
104
+ if File.directory?(file)
105
+ match_test_matchers(file)
106
+ else
107
+ file
108
+ end
109
+ end.flatten.find_all { |file| File.file?(file) }.uniq
110
+ end
111
+ end
@@ -0,0 +1,4 @@
1
+ guard 'hydra' do
2
+ # All spec files
3
+ watch(%r{spec/**/*_spec.rb})
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-hydra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Bintz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-13 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: guard
17
+ requirement: &77475900 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.5.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *77475900
26
+ - !ruby/object:Gem::Dependency
27
+ name: hydra
28
+ requirement: &77475700 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *77475700
37
+ description: Use Hydra to run all specs. Super-fast!
38
+ email:
39
+ - john@coswellproductions.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - guard-hydra.gemspec
49
+ - lib/guard-hydra.rb
50
+ - lib/guard/hydra.rb
51
+ - lib/guard/hydra/templates/Guardfile
52
+ has_rdoc: true
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project: guard-rspec-hydra
73
+ rubygems_version: 1.6.2
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Use Hydra to run all specs. Super-fast!
77
+ test_files: []