Guard-rspec和Ember不能很好地配合使用

6

Rails 4.2.7 guard-rspec 4.7.3

自从我安装了ember-cli-rails,就会阻止guard-spec运行并触发数百个错误。 以下是其中一个错误:

Directory: /home/sylvain/dev/placedemarche/marketadmin/tmp/broccoli_merge_trees-output_path-rlX3b4rm.tmp/marketadmin/tests/unit

    is already being watched through: /home/sylvain/dev/placedemarche/marketadmin/tmp/broccoli_persistent_filterbabel__babel_marketadmin-output_path-Nv8C3Z67.tmp/marketadmin/tests/unit

    MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
    ** ERROR: directory is already being watched! **

我在guardfile中尝试了多种方法,甚至删除了所有的watch:

guard 'rspec',:cli => "--drb --format progress",all_after_pass: false do
  # ignore /marketadmin/ 
  # watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_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)$})                 { |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" }
  # # Capybara request specs
  # watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }
end

我尝试了多个版本的ignore,但仍然失败。
问题基本上在于,Ember用于生成预览应用程序的tmp文件夹会让guard变得混乱。而且似乎guard ignore并不能真正使guard避免扫描该文件夹。
我该如何使guard文件忽略Ember文件夹,以便我可以恢复rspec-guard?
编辑
我已经按照以下方式编辑了guardfile:
guard 'rspec',:cli => "--drb --format progress",all_after_pass: false do
  ignore(%r{^marketadmin/(.+)}) 
end

它仍然失败并显示以下错误(有很多错误,我不得不将终端内存设置为30,000行,20,000不够):
18:24:39 - INFO - Guard::RSpec is running
18:24:39 - DEBUG - Hook :start_end executed for Guard::RSpec
D, [2017-08-24T18:25:00.166155 #20128] DEBUG -- : Waiting for processing to start...
18:25:00 - INFO - Guard is now watching at '/home/sylvain/dev/placedemarche'
18:25:00 - DEBUG - Start interactor
        ** ERROR: directory is already being watched! **

        Directory: /home/sylvain/dev/placedemarche/marketadmin/tmp/funnel-input_base_path-WVhWKrYs.tmp

        is already being watched through: /home/sylvain/dev/placedemarche/marketadmin/node_modules/qunit-notifications

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
        ** ERROR: directory is already being watched! **

        Directory: /home/sylvain/dev/placedemarche/marketadmin/tmp/funnel-input_base_path-ULeE6XMF.tmp

        is already being watched through: /home/sylvain/dev/placedemarche/marketadmin/app

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors

我很惊讶地发现在Ember-cli或者ember build中无法更改文件监视的glob,除非我弄错了。 - BookOfGreg
文件监视器 glob 是什么?问题出在包含 Rails 项目的 Guard 规范中。 - Syl
你可以要求 watch 忽略 /.*/ 以查看是否可以屏蔽一切内容吗? - BookOfGreg
2个回答

3

正如我在IRC频道中所写的那样,你试图避免哪个子文件夹?

如果我在Guardfile的语句顶部添加ignore(%r{frontend/(.+)}),或者在你的情况下是ignore(%r{marketadmin/(.+)}),它会成功地忽略前端应用程序中发生的任何事情。

我的Guardfile看起来像:

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

  # Feel free to open issues for suggestions and improvements

  ignore(%r{frontend/(.+)})
  # RSpec files
  rspec = dsl.rspec
  watch(rspec.spec_helper) { rspec.spec_dir }
...

我对Ember没有经验,而你正在使用的Broccoli可能是配置问题所在?

一个有用的命令可能是:

LISTEN_GEM_DEBUGGING=2 bundle exec guard -d

希望以上内容有所帮助。 更新:检查了你看到的错误,并在安装broccolli-funnel后在我的模拟设置中开始看到这些错误。broccolli-funnel会创建符号链接,而guard使用的监听程序似乎存在问题,但很遗憾今天我没有时间深入分析...也许你可以尝试将ember设置在rails目录之外。

它仍然存在文件夹问题。问题已编辑。 - Syl

0

Guard 现在有一种方法可以指定需要监视的目录。如果您只指定需要的顶级目录,将 marketadmin 或您的 ember-cli 子目录名称从列表中剔除,则它将被忽略:

  directories %w[app config lib spec features]

根据您的应用程序设置,您可能需要其他目录,但关键是要排除marketadmin

https://github.com/guard/guard/wiki/Guardfile-DSL---Configuring-Guard#directories


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接