Is it impossible to use Guard with RubyMine?

前端 未结 5 1191
[愿得一人]
[愿得一人] 2021-01-29 21:07

For some inexplicable reason, RubyMine autosaves every change you make and so every key stroke will trigger Guard to run your tests! And the most ridiculous thing is that there

5条回答
  •  梦毁少年i
    2021-01-29 21:28

    When you run guard with RubyMine for tests, it is extremely useful to configure a separate database environment for guard spec, or else you'll experience strange issues (one process or the other freezes or gives inconsistent results.

    Name your guard spec environment "ci" and create an additional entry in database.yml. I use "ci" for Continuous Automation.

    Then put this in your Guardfile. The key thing is

    'RAILS_ENV' => 'ci'
    

    Here's how I have mine setup:

    group :spec do
      guard :spork, :rspec_port => 1234, :cucumber_env => { 'RAILS_ENV' => 'ci' }, :rspec_env => { 'RAILS_ENV' => 'ci' } do
        watch('config/application.rb')
        watch('config/environment.rb')
        watch(%r{^config/environments/.+.rb$})
        watch(%r{^config/initializers/.+.rb$})
        watch('spec/spec_helper.rb')
        watch(%r{app/models/.+\.rb})
        watch(%r{app/views/.+\.haml})
        watch('Gemfile')
        watch('Gemfile.lock')
        watch('test/test_helper.rb')
      end
    
      # environment is 'ci'
      guard :rspec, :cli => '--drb --drb-port 1234', :version => 2, :all_after_pass => false, :notification => true, :environment => 'ci' 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{^spec/.+_spec.rb$})
        watch(%r{^app/(.+).rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
        watch(%r{^lib/(.+).rb$})                           { |m| "spec/lib/#{m[1]}_spec.rb" }
        watch(%r{^app/controllers/(.+)_(controller).rb$})  do |m|
          ["spec/routing/#{m[1]}_routing_spec.rb",
           "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
           "spec/acceptance/#{m[1]}_spec.rb",
           "spec/requests/#{m[1]}_spec.rb"]
        end
    
        watch(%r{^spec/support/(.+).rb$})                  { "spec" }
        watch('config/routes.rb')                          { "spec/routing" }
        watch('app/controllers/application_controller.rb')  { "spec/controllers" }
        # Capybara request specs
        watch(%r{^app/views/(.+)/.*.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }
      end
    end
    

    I then run

    bundle exec guard -g spec
    

    I also don't mind having RubyMine save files automatically every 60 seconds even if that kicks off Guard, as my a new MBP Retina does not noticeably slow down when running Guard.

    BTW, Guard running specs is really great as you will find failing tests much faster than trying to run the tests yourself in RubyMine. I.e., the test basically is about done by the time my finger releases from cmd-s to save.

    I run this from the terminal. I haven't tried running with RubyMine. Anybody want to comment on the advantages of doing that? I guess having the stack dump clickable would be nice.

提交回复
热议问题