group :development do gem 'guard' end
$ bundle
$ bundle exec guard init
$ bundle exec guard
group :development do # And updates gems when needed gem 'guard-bundler', require: false end
$ bundle install
$ guard init bundler
guard :bundler do watch('Gemfile') end
$ bundle install
$ bundle exec guard
gem 'guard-rspec', require: false
$ guard init rspec
# Note: The cmd option is now required due to the increasing number of ways # rspec may be run, below are examples of the most common uses. # * bundler: 'bundle exec rspec' # * bundler binstubs: 'bin/rspec' # * spring: 'bin/rsspec' (This will use spring if running and you have # installed the spring binstubs per the docs) # * zeus: 'zeus rspec' (requires the server to be started separetly) # * 'just' rspec: 'rspec' guard :rspec, cmd: 'bundle exec 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" } watch('spec/rails_helper.rb') { "spec" } # 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
ruby watch('spec/spec_helper.rb') { "spec” }
ruby guard :rspec, cmd: 'bundle exec rspec' do
$ bundle exec rspec spec
rubywatch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
$ bundle exec spec spec/models/user_spec.rb
"app/views/units/index.html.slim".match(%r{^app/views/(.+)/(.*)\.(.*)\.(erb|haml|slim)$})
group :development, :test do # Integrates jasmine js testing gem 'jasmine-rails' # With guard gem 'guard-jasmine', git: "git://github.com/guard/guard-jasmine.git", branch: "jasmine-2" # Checks ruby code grammar gem 'rubocop', require: false # With rspec gem 'rubocop-rspec' # With guard gem 'guard-rubocop' end group :development do # Automagically launches tests for changed files gem 'guard' gem 'guard-rspec', require: false # And updates gems when needed gem 'guard-bundler', require: false # And auto starts rails server gem 'guard-rails' # And auto runs migrations gem 'guard-migrate' end
# More info at https://github.com/guard/guard#readme # https://github.com/guard/guard-bundler guard :bundler do watch('Gemfile') end # https://github.com/guard/guard-rspec guard :rspec, cmd: 'zeus rspec' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } # Run the model specs related to the changed model watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } # Controller changes watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } watch('config/routes.rb') { "spec/controllers" } watch('app/controllers/application_controller.rb') { "spec/controllers" } watch(%r{^spec/support/(.+)\.rb$}) { "spec" } watch('spec/rails_helper.rb') { "spec" } watch('spec/spec_helper.rb') { "spec" } # Capybara features specs watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/acceptance/#{m[1]}" } watch(%r{^app/views/(.+)/(.*)\.(.*)\.(erb|haml|slim)$}) { |m| "spec/acceptance/#{m[1]}" } watch(%r{^app/views/(.+)/_.*\.(erb|haml|slim)$}) { |m| "spec/acceptance/#{m[1].partition('/').first}/#{m[1].partition('/').last}_spec.rb" } end # Checks any changed ruby file for code grammar # https://github.com/yujinakayama/guard-rubocop guard :rubocop, all_on_start: false, cli: ['--out', 'log/rubocop.log'] do watch(%r{^(.+)\.rb$}) { |m| "#{m[1]}.rb" } end # Restarts server on config changes # https://github.com/ranmocy/guard-rails guard :rails, zeus: true, daemon: true do watch('Gemfile.lock') watch(%r{^(config|lib)/.*}) end # Restarts all jasmine tests on any js change # https://github.com/guard/guard-jasmine guard :jasmine, all_on_start: false, server_mount: '/specs' do watch(%r{^app/(.+)\.(js\.coffee|js|coffee)}) { "spec/javascripts" } watch(%r{^spec/javascripts/(.+)\.(js\.coffee|js|coffee)}) { "spec/javascripts" } end # Runs migrations on migrate files changes # https://github.com/glanotte/guard-migrate guard :migrate do watch(%r{^db/migrate/(\d+).+\.rb}) watch('db/seeds.rb') end
$ rubocop --auto-gen-config
$ zeus start
$ bundle exec guard
Source: https://habr.com/ru/post/238667/
All Articles