|
| 1 | +# A sample Guardfile |
| 2 | +# More info at https://github.com/guard/guard#readme |
| 3 | + |
| 4 | +## Uncomment and set this to only include directories you want to watch |
| 5 | +# directories %w(app lib config test spec features) \ |
| 6 | +# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")} |
| 7 | + |
| 8 | +## Note: if you are using the `directories` clause above and you are not |
| 9 | +## watching the project directory ('.'), then you will want to move |
| 10 | +## the Guardfile to a watched dir and symlink it back, e.g. |
| 11 | +# |
| 12 | +# $ mkdir config |
| 13 | +# $ mv Guardfile config/ |
| 14 | +# $ ln -s config/Guardfile . |
| 15 | +# |
| 16 | +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" |
| 17 | + |
| 18 | +# Note: The cmd option is now required due to the increasing number of ways |
| 19 | +# rspec may be run, below are examples of the most common uses. |
| 20 | +# * bundler: 'bundle exec rspec' |
| 21 | +# * bundler binstubs: 'bin/rspec' |
| 22 | +# * spring: 'bin/rspec' (This will use spring if running and you have |
| 23 | +# installed the spring binstubs per the docs) |
| 24 | +# * zeus: 'zeus rspec' (requires the server to be started separately) |
| 25 | +# * 'just' rspec: 'rspec' |
| 26 | +notification :terminal_notifier |
| 27 | +guard :rspec, cmd: "bundle exec rspec" do |
| 28 | + require "guard/rspec/dsl" |
| 29 | + dsl = Guard::RSpec::Dsl.new(self) |
| 30 | + |
| 31 | + # Feel free to open issues for suggestions and improvements |
| 32 | + |
| 33 | + # RSpec files |
| 34 | + rspec = dsl.rspec |
| 35 | + watch(rspec.spec_helper) { rspec.spec_dir } |
| 36 | + watch(rspec.spec_support) { rspec.spec_dir } |
| 37 | + watch(rspec.spec_files) |
| 38 | + |
| 39 | + # Ruby files |
| 40 | + ruby = dsl.ruby |
| 41 | + dsl.watch_spec_files_for(ruby.lib_files) |
| 42 | + |
| 43 | + # Rails files |
| 44 | + rails = dsl.rails(view_extensions: %w(erb haml slim)) |
| 45 | + dsl.watch_spec_files_for(rails.app_files) |
| 46 | + dsl.watch_spec_files_for(rails.views) |
| 47 | + |
| 48 | + watch(rails.controllers) do |m| |
| 49 | + [ |
| 50 | + rspec.spec.call("routing/#{m[1]}_routing"), |
| 51 | + rspec.spec.call("controllers/#{m[1]}_controller"), |
| 52 | + rspec.spec.call("acceptance/#{m[1]}") |
| 53 | + ] |
| 54 | + end |
| 55 | + |
| 56 | + # Rails config changes |
| 57 | + watch(rails.spec_helper) { rspec.spec_dir } |
| 58 | + watch(rails.routes) { "#{rspec.spec_dir}/routing" } |
| 59 | + watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } |
| 60 | + |
| 61 | + # Capybara features specs |
| 62 | + watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") } |
| 63 | + watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") } |
| 64 | + |
| 65 | + # Turnip features and steps |
| 66 | + watch(%r{^spec/acceptance/(.+)\.feature$}) |
| 67 | + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| |
| 68 | + Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance" |
| 69 | + end |
| 70 | +end |
| 71 | + |
| 72 | +# Guard-Rails supports a lot options with default values: |
| 73 | +# daemon: false # runs the server as a daemon. |
| 74 | +# debugger: false # enable ruby-debug gem. |
| 75 | +# environment: 'development' # changes server environment. |
| 76 | +# force_run: false # kills any process that's holding the listen port before attempting to (re)start Rails. |
| 77 | +# pid_file: 'tmp/pids/[RAILS_ENV].pid' # specify your pid_file. |
| 78 | +# host: 'localhost' # server hostname. |
| 79 | +# port: 3000 # server port number. |
| 80 | +# root: '/spec/dummy' # Rails' root path. |
| 81 | +# server: thin # webserver engine. |
| 82 | +# start_on_start: true # will start the server when starting Guard. |
| 83 | +# timeout: 30 # waits untill restarting the Rails server, in seconds. |
| 84 | +# zeus_plan: server # custom plan in zeus, only works with `zeus: true`. |
| 85 | +# zeus: false # enables zeus gem. |
| 86 | +# CLI: 'rails server' # customizes runner command. Omits all options except `pid_file`! |
| 87 | + |
| 88 | +guard 'rails' do |
| 89 | + watch('Gemfile.lock') |
| 90 | + watch(%r{^(config|lib)/.*}) |
| 91 | +end |
0 commit comments