Question

I am trying to get guard to work with Jasmine tests. I have tried guard-jasmine with jasminerice, guard-jasmine with jasmine-rails, and teaspoon. I end up getting the same error - the tests work the first time I set up guard, but every time I save a spec file or a javascript file the tests do not update. This is true when I run the tests in guard, or if I run it in a browser (i.e. /jasmine for jasmine-rails or /teaspoon for teaspoon), the tests work when I run rails s, but do not update the tests when I save them and refresh the page.

I only see this behavior in my spec/javascripts directory, when I run a test in like spec/controllers, guard works as expected.

Any suggestions on what might be the problem?

Here is my Guardfile:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'livereload' do
  watch(%r{app/views/.+\.(erb|haml|slim)$})
  watch(%r{app/helpers/.+\.rb})
  watch(%r{config/locales/.+\.yml})
  # Rails Assets Pipeline
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|sass))).*}) { |m| "/assets/#{m[3]}" }
end

guard :teaspoon do
  # Implementation files
  watch(%r{app/assets/javascripts/(.+).js}) { |m| "#{m[1]}_spec" }

  # Specs / Helpers
  watch(%r{spec/javascripts/(.*)})
end

guard 'rspec', all_after_pass: false, all_on_start: false, bundler: true, cli: "--color --format=doc" 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)$})                 { |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('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  watch(%r{^app/views/(.+)/}) { |m| "spec/requests/#{m[1]}_spec.rb" }

  # Capybara request specs
  #watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{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' }
end

Thank you,

Was it helpful?

Solution

Change

watch(%r{app/assets/javascripts/(.+).js}) { |m| "#{m[1]}_spec" } to

watch(%r{app/assets/javascripts/(.+).js}) { |m| "#{m[1]}_spec.js" }

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