Skip to content

Instantly share code, notes, and snippets.

@amyroi
Created May 19, 2017 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyroi/ff79ce617aa05624e56c257981f1a00b to your computer and use it in GitHub Desktop.
Save amyroi/ff79ce617aa05624e56c257981f1a00b to your computer and use it in GitHub Desktop.
Guardfile target submodule
# Sample Guardfile use options chdir
paths = %w(spec submodule/spec)
dirs = %w(./ submodule/)
dirs.each do |dir|
guard :rspec, cmd: 'bin/spring rspec', chdir: dir do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)
watch(%r{#{dir}spec/.+_spec\.rb})
watch(%r{#{dir}app/(.+)\.rb}) { |m| "#{dir}spec/#{m[1]}_spec.rb" }
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.call("#{dir}routing/#{m[1]}_routing"),
rspec.spec.call("#{dir}controllers/#{m[1]}_controller"),
rspec.spec.call("#{dir}acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment