Question

In my app, guard is working fine but its not reloading if I change the views. How can I add this feature? Here's my Guardfile :

require 'active_support/inflector' 
notification :libnotify

guard :rspec, notification: true, all_on_start: true, cmd: 'spring rspec'  do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb')  { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
watch('config/routes.rb')                           { "spec/routing" }
watch('app/controllers/application_controller.rb')  { "spec/controllers" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$})     { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }


  # Custom Rails Tutorial specs
watch(%r{^app/controllers/(.+)_(controller)\.rb$})  do |m|
  ["spec/routing/#{m[1]}_routing_spec.rb",
   "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
   "spec/acceptance/#{m[1]}_spec.rb",
   (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                     "spec/requests/#{m[1].singularize}_pages_spec.rb")]
end
watch(%r{^app/views/(.+)/}) do |m|
  (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                     "spec/requests/#{m[1].singularize}_pages_spec.rb")
end
watch(%r{^app/controllers/sessions_controller\.rb$}) do |m|                                                                                                  
  "spec/requests/authentication_pages_spec.rb"                                                                                                               
end
end

The Gemfile.lock :

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.0.0)
      actionpack (= 4.0.0)
      mail (~> 2.5.3)
    actionpack (4.0.0)
      activesupport (= 4.0.0)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    activemodel (4.0.0)
      activesupport (= 4.0.0)
      builder (~> 3.1.0)
    activerecord (4.0.0)
      activemodel (= 4.0.0)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.0)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.0)
      i18n (~> 0.6, >= 0.6.4)
      minitest (~> 4.2)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.37)
    annotate (2.5.0)
      rake
    arel (4.0.1)
    atomic (1.1.14)
    bcrypt-ruby (3.0.1)
    better_errors (1.0.1)
      coderay (>= 1.0.0)
      erubis (>= 2.6.6)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    bootstrap-sass (2.3.2.2)
      sass (~> 3.2)
    builder (3.1.4)
    capybara (2.1.0)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    celluloid (0.15.2)
      timers (~> 1.1.0)
    childprocess (0.3.9)
      ffi (~> 1.0, >= 1.0.11)
    coderay (1.0.9)
    coffee-rails (4.0.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.6.3)
    debug_inspector (0.0.2)
    diff-lcs (1.2.4)
    erubis (2.7.0)
    execjs (2.0.2)
    factory_girl (4.2.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.2.1)
      factory_girl (~> 4.2.0)
      railties (>= 3.0.0)
    faker (1.2.0)
      i18n (~> 0.5)
    ffi (1.9.0)
    font-awesome-rails (4.0.0.0)
      railties (>= 3.2, < 5.0)
    formatador (0.2.4)
    guard (2.1.1)
      formatador (>= 0.2.4)
      listen (~> 2.1)
      lumberjack (~> 1.0)
      pry (>= 0.9.12)
      thor (>= 0.18.1)
    guard-rspec (4.0.3)
      guard (>= 2.1.1)
      rspec (~> 2.14)
    hike (1.2.3)
    i18n (0.6.5)
    jbuilder (1.5.2)
      activesupport (>= 3.0.0)
      multi_json (>= 1.2.0)
    jquery-rails (3.0.4)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.8.1)
    libnotify (0.8.2)
      ffi (>= 1.0.11)
    listen (2.1.1)
      celluloid (>= 0.15.2)
      rb-fsevent (>= 0.9.3)
      rb-inotify (>= 0.9)
    lumberjack (1.0.4)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    method_source (0.8.2)
    mime-types (1.25)
    mini_portile (0.5.2)
    minitest (4.7.5)
    modernizr-rails (2.6.2.3)
    multi_json (1.8.2)
    nokogiri (1.6.0)
      mini_portile (~> 0.5.0)
    pg (0.17.0)
    polyglot (0.3.3)
    pry (0.9.12.2)
      coderay (~> 1.0.5)
      method_source (~> 0.8)
      slop (~> 3.4)
    rack (1.5.2)
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (4.0.0)
      actionmailer (= 4.0.0)
      actionpack (= 4.0.0)
      activerecord (= 4.0.0)
      activesupport (= 4.0.0)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.0)
      sprockets-rails (~> 2.0.0)
    rails_12factor (0.0.2)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.1)
    rails_stdout_logging (0.0.3)
    railties (4.0.0)
      actionpack (= 4.0.0)
      activesupport (= 4.0.0)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.1.0)
    rb-fsevent (0.9.3)
    rb-inotify (0.9.2)
      ffi (>= 0.5.0)
    rdoc (3.12.2)
      json (~> 1.4)
    rspec (2.14.1)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    rspec-core (2.14.6)
    rspec-expectations (2.14.3)
      diff-lcs (>= 1.1.3, < 2.0)
    rspec-mocks (2.14.4)
    rspec-rails (2.14.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    sass (3.2.12)
    sass-rails (4.0.1)
      railties (>= 4.0.0, < 5.0)
      sass (>= 3.1.10)
      sprockets-rails (~> 2.0.0)
    sdoc (0.3.20)
      json (>= 1.1.3)
      rdoc (~> 3.10)
    slop (3.4.6)
    spring (0.0.11)
    sprockets (2.10.0)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    thor (0.18.1)
    thread_safe (0.1.3)
      atomic
    tilt (1.4.1)
    timers (1.1.0)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    turbolinks (1.3.0)
      coffee-rails
    tzinfo (0.3.38)
    uglifier (2.2.1)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)
    xpath (2.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  annotate
  bcrypt-ruby (~> 3.0.0)
  better_errors
  binding_of_caller
  bootstrap-sass
  capybara
  childprocess
  coffee-rails (~> 4.0.0)
  factory_girl_rails
  faker
  font-awesome-rails
  guard (~> 2.1.1)
  guard-rspec (~> 4.0.3)
  jbuilder (~> 1.2)
  jquery-rails
  libnotify
  modernizr-rails
  pg
  rails (= 4.0.0)
  rails_12factor
  rb-inotify
  rspec (~> 2.14.0)
  rspec-rails
  sass-rails (~> 4.0.0)
  sdoc
  spring
  turbolinks
  uglifier (>= 1.3.0)
Was it helpful?

Solution

Why do you think that Guard should reload on view change? Changes in views (as in controllers and models) do not affect the development server, so no need in restarting it - you just need to reload the page in the browser. If you want guard to do it automaticaly for you, you need to add those 2 gems to your Gemfile under the :development group:

gem "guard-livereload"
gem "rack-livereload"

You also need to install the corresponding browser extentions to respond to livereload.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top