I am trying to use Guard
instead of Autotest
for RSpec
, but I'm somewhat confused by its behavior. When I run bundle exec guard
it just launches a pry
window. I thought it is supposed to behave like Autotest where it just continues to run tests in the background every time there is a change. What am I missing here?
When I launch bundle exec guard
, this is what I get:
18:52:44 - INFO - Guard is using TerminalTitle to send notifications.
18:52:44 - INFO - Guard::RSpec is running
18:52:44 - INFO - Guard is now watching at '/path/to/my/application'
[1] guard(main)>
I'm not really sure what to make of this.
Have you generated your Guardfile? (./Guardfile in your app directory). Mine looks like this:
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
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" }
# 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
Your output listed above looks correct, Guard gives you an interactive shell as well as triggering things when files change.
使用-i
选项运行它应该会有所帮助
bundle exec guard -i
Guard is running Pry for user interactions with it. Probably you haven't set to run RSpec guard at startup. To run it manually type rspec
and hit return. It will run your Guard. To run all guards (if you have more than this one) just type all
and hit return.
PS Guard is still watching and will run your guard on file change, but it is showing Pry prompt to allow user interactions (described above).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.