【问题标题】:How do I configure a guardfile to monitor the app/helpers directory in a Ruby/Rails environment如何配置保护文件以监视 Ruby/Rails 环境中的 app/helpers 目录
【发布时间】:2015-09-02 20:05:10
【问题描述】:

使用guard 2.12.8,我试图让guard 关注app/helpers 目录中的文件。

我尝试了几件事,其中最近的是

  guard :rspec, cmd: "bundle exec rspec" do
  require "guard/rspec/dsl"
  dsl = Guard::RSpec::Dsl.new(self)

  # RSpec files
  rspec = dsl.rspec
  watch(rspec.spec_helper) { rspec.spec_dir }
  watch(rspec.spec_support) { rspec.spec_dir }
  watch(rspec.spec_files)
  watch(%r{^(app/helpers)/.*})

我已阅读 Guard 的文档,但尚未找到 Guard::RSpec::Dsl 的特定文档。示例,但实际上没有“这就是它的工作原理”的东西。指针会很有帮助。

【问题讨论】:

    标签: ruby-on-rails rspec guard


    【解决方案1】:

    Guard::RSpec::Dsl 只是为了清理 Guardfile 中的正则表达式汤,仅此而已:

    https://github.com/guard/guard-rspec/blob/master/lib/guard/rspec/dsl.rb#L52

    如果这是你的整个 Guardfile,那么你就错过了 Rails 部分:

    https://github.com/guard/guard-rspec/blob/master/lib/guard/rspec/templates/Guardfile

    已经有处理应用文件的规则:

    https://github.com/guard/guard-rspec/blob/master/lib/guard/rspec/dsl.rb#L50

    此外,guard-rspec 不会根据更改的帮助文件知道要运行哪些规范/功能 - 因此您必须决定是运行单元测试、功能测试还是所有测试。

    以下是“应用程序文件”(模块、帮助程序、关注点)和规范文件之间映射的代码:

    https://github.com/guard/guard-rspec/blob/master/lib/guard/rspec/dsl.rb#L13

    (请注意规范名称和路径如何基于从修改文件中捕获的正则表达式)

    所以鉴于应用程序文件已经被观看:

    https://github.com/guard/guard-rspec/blob/master/lib/guard/rspec/dsl.rb#L50

    如果您有app/helpers/foo_helper.rb,则正则表达式将捕获helpers/foo_helper,这意味着必须存在名为spec/helpers/foo_helper_spec.rb 的文件。

    如果不存在匹配的名称,您将需要自定义规则。

    我想可以添加一些对助手的支持,但很难猜测要运行哪些规范/功能(控制器已经很混乱了)。

    我没有关于人们对此问题(以及他们的项目布局是什么)的反馈,所以我很难猜测如何改进/记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      • 2012-04-03
      • 2014-03-18
      • 2019-07-28
      相关资源
      最近更新 更多