ruby - 如何使用 Rake 为 Rspec 运行 JunitFormatter 输出?

标签 ruby rspec rake

我可以使用以下方式运行 rspec 文件:

rspec -f JUnitFormatter -o junit.xml spec_test.rb

但是每次我尝试 rake 执行 spec 文件时,我都会收到以下错误

/formatters/junit_formatter.rb:28:in `require': no such file to load --     rspec/core/formatters/base_formatter (LoadError)
from ./formatters/junit_formatter.rb:28
from /usr/lib/ruby/1.8/spec/runner/option_parser.rb:151:in `require'
from /usr/lib/ruby/1.8/spec/runner/option_parser.rb:151:in `invoke_requires'
from /usr/lib/ruby/1.8/spec/runner/option_parser.rb:150:in `each'
from /usr/lib/ruby/1.8/spec/runner/option_parser.rb:150:in `invoke_requires'
from /usr/lib/ruby/1.8/spec/runner/option_parser.rb:105:in `initialize'
from /usr/lib/ruby/1.8/optparse.rb:1267:in `call'
from /usr/lib/ruby/1.8/optparse.rb:1267:in `parse_in_order' 
from /usr/lib/ruby/1.8/optparse.rb:1254:in `catch'
from /usr/lib/ruby/1.8/optparse.rb:1254:in `parse_in_order'
from /usr/lib/ruby/1.8/optparse.rb:1248:in `order!'
from /usr/lib/ruby/1.8/spec/runner/option_parser.rb:134:in `order!'
from /usr/lib/ruby/1.8/spec/runner.rb:51:in `options'
from /usr/lib/ruby/1.8/spec/runner/command_line.rb:6:in `run'
from /usr/bin/spec:3

我的 Rake 文件:

require 'rubygems'
require 'spec/rake/spectask'

Spec::Rake::SpecTask.new(:spec) do |t|
  t.spec_files = FileList['spec_*.rb']
  t.spec_opts = ['--options .rspec','--format JUnitFormatter' '--output junit.xml']
end

最佳答案

您需要在使用前要求 junit 格式化程序。将 gem 'rspec_junit_formatter' 添加到您的 Gemfile,捆绑安装,然后像这样运行 Rspec:

rspec -r rspec_junit_formatter --format RspecJunitFormatter -o junit.xml

Source

根据评论进行编辑:

您可以通过添加自定义 rake 任务来使其工作:

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
  t.fail_on_error = false
  t.rspec_opts = "--no-drb -r rspec_junit_formatter --format RspecJunitFormatter -o junit.xml"
end

关于ruby - 如何使用 Rake 为 Rspec 运行 JunitFormatter 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8785358/

相关文章:

ruby-on-rails - 如何测试是否在使用 RSpec 从 Rails 中的数据库中提取的特定对象上调用了方法?

ruby-on-rails-3 - 我如何在 rails rspec 中测试 cookie 的过期时间

msbuild - 如何使用 Albacore 的 msbuild 任务构建 .NET Web 应用程序项目?

ruby - 你如何激活或设置默认的佣金?

ruby - 如何解决 factory_girl wrong number of arguments 错误

ruby-on-rails - Ruby SSL 握手未收到服务器 Hello 返回 - 使用代理 Net::HTTP

ruby-on-rails - 回形针/Rspec 测试 : Is there a faster way to test paperclip validates_attachment_content_type?

ruby-on-rails - 为什么 Rake 任务中的这个 Ruby 脚本不能选择 Rails 环境?

ruby-on-rails - 在 Rails 中设置两个模型之间的一对一和一对多关系

ruby - 我可以在子目录/子模块中引用 gemfile 吗?