Question

I have a feature spec like spec/features/awesome_feature_spec.rb which requires spec/shared_examples/awesome_spec.rb. The latter contains all the shared_examples I am using in awesome_feature_spec.rb. When an example fails and I edit a file to fix it and save it, guard is trying to run that example again, but it directly runs awesome_feature.rbinstead of awesome_feature_spec.rb since the failed shared example is in awesome_feature.rb. This causes an error of course, since it needs to run awesome_feature_spec.rb which is the actual feature spec.

This is how my Guardfile looks like:

guard :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" }
  watch(%r{^spec/shared_examples.*/(.+)\.rb$})      { |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' }
end

Can anyone help me making guard run the feature spec and not the file which contains the shared examples?

Thank you very much in advance :)

Was it helpful?

Solution 2

It's confirmed issue in guard-rspec (https://github.com/guard/guard-rspec/issues/243). If you update guard-rspec to version 4.5.0 it should be fixed.

OTHER TIPS

EDIT: I didn't read the question properly. This won't solve the question above, but if anyone else happens to come across this question when googling for an answer about guard-rspec only running failing specs, hopefully this will help.


This is the 'focus mode' feature of guard-rspec. It remembers any failed specs from the last run and keeps running them until they pass.

To disable it, add failed_mode: :none to your RSpec options in Guardfile:

rspec_opts = {
  failed_mode: :none,
  # other options...
}

guard :rspec, rspec_opts do
  # watches, etc...
end

See: https://github.com/guard/guard-rspec for more details.

Sorry this is late but others may come seeking answers.

I'm not sure that this is exactly what you need but it sounds like you're after a finer-grained control over which files to execute.

Conditional Watch sounds like it could give you that finer control.

The syntax can be changed into a slightly less verbose syntax but the point is that you can pull in the parameters and pass them to a method with more complex logic, I believe that the params are an array of size 3 and of the form:

["path/to/controller", "controller_name", "controller"]

However, it's been a while since I set this up so you can take a peek at them by doing something like the following.

#add a watch to all view files in the app directory and print the params to stdout
watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |params| puts params}

and then just play around with the logic you want.

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