Getting Guard tests to run AUTOMATICALLY

33 views
Skip to first unread message

Jason Hsu, Rubyist

unread,
Jan 8, 2015, 8:12:16 PM1/8/15
to rubyonra...@googlegroups.com
I'm going through Hartl's Rails tutorial, which now uses Rails 4.2 and Guard with minitest.

Having Guard up and running does not automatically run tests; I have to press Enter to trigger the tests.

I can get the tests to run automatically upon starting Guard by changing "guard :minitest, spring: true, all_on_start: false do" in the Guardfile to "guard :minitest, spring: true do".  (This change means that the all_on_start parameter is set to true by default.)

How can I get the tests to run automatically when I modify files in the app?  While I don't need this automatic testing to get through railstutorial.org, I want to have this capability for working on more serious apps.  I'd like the tests to begin BEFORE I click on the terminal window that I have dedicated to Guard testing.
Message has been deleted

Dennis Krupenik

unread,
Jan 10, 2015, 12:07:45 AM1/10/15
to rubyonra...@googlegroups.com
you need some *watch* directives in the Guardfile, like so:

guard :rspec, cmd: 'bundle exec rspec' do

  watch(%r{^spec/support/(.+)\.rb$}) { "spec" }

  watch('spec/spec_helper.rb') { "spec" }


  watch(%r{^spec/.+_spec\.rb$})

  watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }

  watch(%r{^app/controllers/(.+)\.rb$}) { |m| "spec/integration/#{m[1]}_spec.rb" }

  watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }

end

Jason Hsu, Rubyist

unread,
Jan 10, 2015, 1:09:58 AM1/10/15
to rubyonra...@googlegroups.com
I've tried out the complete sample app from https://github.com/mhartl/sample_app_3rd_edition to ensure that I didn't overlook something.

Now I realize that Guard does respond by automatically executing a test when one of the files it watches changes.  Unfortunately, it takes a few MINUTES to respond and doesn't even provide any visible indication during these minutes.  I should note that my normal development environment is in Vagrant.

Why does Guard respond so slowly?  Spring is supposed to speed up the testing process, but I have a hard time believing that it's accomplishing anything.

Norbert Melzer

unread,
Jan 10, 2015, 8:01:08 AM1/10/15
to Rails Mailinglist

Have you installed the correct inotify bindings or is guard Running in fallback Mode?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e81b8bf7-961b-460e-8f78-a203532c5c76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages