ruby – 如何使用Rake运行Rspec的JunitFormatter输出?

前端之家收集整理的这篇文章主要介绍了ruby – 如何使用Rake运行Rspec的JunitFormatter输出?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用以下命令运行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
原文链接:https://www.f2er.com/ruby/264697.html

猜你在找的Ruby相关文章