【问题标题】:RakeTask.rspec_opts are ignored when specified in rake在 rake 中指定时忽略 RakeTask.rspec_opts
【发布时间】:2012-04-15 07:14:36
【问题描述】:

我有一个 RakeTask,它在文件 test.rake 中定义为

RSpec::Core::RakeTask.new(:pit) do |spec|
  spec.ruby_opts = "-I lib:spec"
  spec.rspec_opts = "--format html --out output.html --format documentation"
  spec.pattern = 'test.rb'
end

task :pi => [:report, :pit]

当我运行命令时

$ rake -f test.rake pi

测试运行良好。但是,按照文档格式化程序,我没有看到任何输出,也没有生成 output.html

但是,当我运行命令时

$ rspec test.rb --format html --out output.html --format documentation

测试运行良好,输出以文档格式打印,output.html 也正确生成。

当我运行rake 命令时,我也可以正常看到参数,实际命令如下所示:

$ ruby.exe -I lib:spec -S rspec test.rb --format html --out output.html
--format documentation

因此,参数被正确传递,格式选项仍然无效。请你帮我解开这个谜。

【问题讨论】:

  • 你使用了两次--format
  • @ajahongir 如果您想要多个输出副本,您可以多次提供。

标签: rspec rake formatter


【解决方案1】:

我在使用的时候也遇到了同样的问题

spec.rspec_opts "--format documentation --color"

--color 参数未通过。

唯一的解决方案是在 spec_helper.rb 中设置它——而不是在 rake 任务中

RSpec.configure do |config|
  config.color = true
  config.tty = true
  config.formatter = :documentation # :progress, :html, :textmate
end

【讨论】:

    【解决方案2】:

    试试这个:

    spec.rspec_opts = ["--format", "html", "--out", "output.html", "--format", "documentation"]
    

    【讨论】:

      猜你喜欢
      • 2018-08-22
      • 1970-01-01
      • 2011-05-12
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多