【问题标题】:Rspec 2 - --format html using guardRspec 2 - --format html 使用守卫
【发布时间】:2012-08-13 15:48:27
【问题描述】:

在我的 rails 项目中,我的 .rspec 文件如下:

--color
--format progress
--format html --out tmp/spec_outputs/spec_results.html

当我运行“rake spec”时,输出与预期一致:我在 stdout 中看到了进度输出,并且在给定目录中创建了 html 文件。

但是,当我尝试使用“bundle exec guard”自动化我的测试时,html 也会发送到 stdout,并且不会创建/更新 html 文件。注意:如果我只是在没有“bundle exec”的情况下运行“guard”,我也会遇到同样的问题。

下面是我的保护文件:

guard 'cucumber', cli: "-p wip" do
  watch(%r{^features/.+\.feature$})
  watch(%r{^features/support/.+$})          { 'features' }
  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end


guard 'rspec', :version => 2 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)$})                 { |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" }

  # 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-on-rails rake rspec2 guard


    【解决方案1】:

    guard 运行的rspec 命令不尊重您的.rspec 文件。您可以使用:cli 选项将--format 参数传递给rspec:

    guard 'rspec', :cli => "--color --format progress --format html --out tmp/spec_outputs/spec_results.html" do
      # ...
    end
    

    欲了解更多信息,请查看guard-rspec 文档guard/guard-rspec

    【讨论】:

    • 谢谢。你很准。我昨天尝试传递一个 :cli 选项,但它没有用。它一定没有正确指定它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    • 2013-03-31
    • 2015-12-30
    • 2013-04-11
    • 1970-01-01
    相关资源
    最近更新 更多