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.rb
instead 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 :)
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.