ruby DRY Guardfile,具有已定义的组,可在聚焦模式或默认模式下运行。使用范围焦点或范围defau切换到Guard提示符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby DRY Guardfile,具有已定义的组,可在聚焦模式或默认模式下运行。使用范围焦点或范围defau切换到Guard提示符相关的知识,希望对你有一定的参考价值。

# Run Guard normally. This Guardfile defines 2 groups:
# 1) default: This is the default group and will run all appropriate specs when anything changes.
# 2) focus: This is the group you want when you are focusing on a specific spec or context of specs. When in this
# scope Guard will only run specs tagged with :focus.
#
# Example:
#  context "GET on :index, /", focus: true do
#    ...
#  end
#
# Change scope at the guard prompt:
# > scope focus
# > scope default

guard 'bundler' do
  watch('Gemfile')
end

# Newer versions of guard-rspec require the actual 'rspec' to be in the CLI
# TODO: Determine the version that switched this command and switch it automatically
# based on version of guard-rspec, appropriately
CLI = 'rspec --format doc'
# If on an older version you may want this one:
#CLI = '--format doc'

def watchers
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})               { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch(%r{spec/support/.+\.rb})          { "spec" }
  watch('spec/spec_helper.rb')            { "spec" }
  watch('config/boot.rb')                 { 'spec' }

  # for Padrino
  watch(%r{^app/controllers/(.+).rb$})    { |m| ["spec/app/controllers/#{m[1]}_controller_spec.rb"] }
  watch(%r{^app/models/(.+).rb$})         { |m| ["spec/app/models/#{m[1]}_spec.rb"] }
  watch(%r{^app/app\.rb$})                { "spec" }
  
  # Factories
  watch(%r{^spec/factories/(.+)\.rb$}) do |m|
    %W[
      spec/models/#{m[1].singularize}_spec.rb
      spec/controllers/#{m[1]}_controller_spec.rb
    ]
  end

  # Rabl templates
  watch(%r{^app/views/(.+)/(.+)\.rabl$}) do |m|
    %W[
      spec/models/#{m[1].singularize}_spec.rb
      spec/controllers/#{m[1]}_controller_spec.rb
    ]
  end

  # Whatever else...
end

def rubocop_watchers
  watch(%r{.+\.rb$})
  watch(%r{.+\.rake$})
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

group :default do
  guard :rspec, :cmd => CLI do
    watchers
  end

  guard :rubocop, cli: ['-D'] do
    rubocop_watchers
  end
  
  guard 'yard', port: '8000', cli: '--plugin activerecord --readme README.md' do
    watch(%r{README.md})
    watch(%r{app/.+\.rb})
    watch(%r{lib/.+\.rb})
    watch(%r{ext/.+\.c})
  end
end

group :focus do
  guard :rspec, :cmd => "#{CLI} --tag focus" do
    watchers
  end
end

scope group: :default

以上是关于ruby DRY Guardfile,具有已定义的组,可在聚焦模式或默认模式下运行。使用范围焦点或范围defau切换到Guard提示符的主要内容,如果未能解决你的问题,请参考以下文章

在 Ruby on Rails 应用程序中尽可能 DRY

如果彼此依赖,如何要求ruby gem中的文件

ruby 具有预定义格式参数的ruby方法

检查常量是不是已在 Ruby 类中定义的正确方法

如何使用 Django 模型字段定义保持 DRY

ruby 检测本地已定义