Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 61ebd267a9df253752ac91ba6490a17905a602b0 Dean Strelau committed Mar 23, 2011
Showing with 77 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 Gemfile
  3. +2 −0 Rakefile
  4. +19 −0 guard-forku.gemspec
  5. +39 −0 lib/guard/forku.rb
  6. +9 −0 lib/guard/forku/templates/Guardfile
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in guard-test-fork.gemspec
+gemspec
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1,19 @@
+# -*- encoding: utf-8 -*-
+Gem::Specification.new do |s|
+ s.name = "guard-forku"
+ s.version = '0.1.0'
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Dean Strelau"]
+ s.email = ["dean@mintdigital.com"]
+ s.homepage = "https://github.com/mintdigital/guard-forku"
+ s.summary = %q{A Guard that forks before running tests}
+ s.description = <<-DESC
+See https://github.com/guard/guard and
+https://gitub.com/mintdigital/guard-forku for more.
+DESC
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
@@ -0,0 +1,39 @@
+require 'guard'
+require 'guard/guard'
+
+module Guard
+ class Forku < Guard
+
+ def start
+ UI.info "Loading test_helper"
+ require 'test_helper'
+ ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base)
+ UI.info "Ready"
+ end
+
+ # Called on Ctrl-/ signal
+ #
+ # Run each set of tests serially, as running them together can cause
+ # problems with overlapping DB connections and other wonkiness.
+ def run_all
+ %w[unit functional integration performance].each do |test|
+ load_in_fork(*Dir.glob("test/#{test}/**/*_test.rb"))
+ Process.wait
+ end
+ end
+
+ # Called on file(s) modifications
+ def run_on_change(paths)
+ load_in_fork(*paths)
+ end
+
+ def load_in_fork(*paths)
+ fork do
+ ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
+ paths.each {|p| load p }
+ end
+ end
+ private :load_in_fork
+
+ end
+end
@@ -0,0 +1,9 @@
+guard 'forku' do
+ watch(%r{lib/(.*)\.rb}) { |m| "test/#{m[1]}_test.rb" }
+ watch(%r{test/.*_test\.rb})
+ watch('test/test_helper.rb') { "test" }
+ watch(%r{app/models/(.*)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
+ watch(%r{app/controllers/(.*)\.rb}) { |m| "test/functional/#{m[1]}_test.rb" }
+ watch(%r{app/views/.*\.rb}) { "test/integration" }
+ watch('app/controllers/application_controller.rb') { ["test/functional", "test/integration"] }
+end

0 comments on commit 61ebd26

Please sign in to comment.