Created
August 29, 2011 22:28
-
-
Save ashmoran/1179590 to your computer and use it in GitHub Desktop.
Hack to speed up Guard::RSpec runs with Guardfile and spec_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Signal to interested subprocesses that they are being run from Guard | |
ENV["GUARD"] = "fast" | |
guard 'rspec', version: 2, cli: "--color --format Fuubar" do | |
watch(%r{^spec/.+_spec\.rb}) | |
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } | |
watch('spec/spec_helper.rb') { "spec" } | |
end | |
# Only run this once to stop Guardfile re-evaluation making a hash of things | |
unless ::Guard::RSpec.instance_methods.include?(:run_on_change_orig) | |
# There's a "hook" branch of Guard that will make this class patch | |
# unnecessary: https://github.com/guard/guard/tree/hook | |
class ::Guard::RSpec | |
# Monkey-patch to indicate to RSpec that it can run slow tests if | |
# only one file was changed | |
alias_method :run_on_change_orig, :run_on_change | |
def run_on_change(paths) | |
if paths.length == 1 && File.read(paths.first).include?("adapter: :slow") | |
ENV["GUARD"] = "all" | |
end | |
run_on_change_orig(paths) | |
ensure | |
ENV["GUARD"] = "fast" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..")).freeze | |
GUARD = ENV["GUARD"] | |
RSpec.configure do |config| | |
config.filter_run(focus: true) | |
config.filter_run_excluding(adapter: :slow) if GUARD == "fast" | |
config.run_all_when_everything_filtered = true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment