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

发布于 2024-12-25 19:12:37 字数 1440 浏览 2 评论 0原文

我使用以下命令运行 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

I have no problem running the rspec file using :

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

However each time I try rake to execute spec file, I get the following error

/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

My Rake file :

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天荒地未老 2025-01-01 19:12:37

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

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

根据评论进行编辑:

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

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

You need to require the junit formatter before using it. Add gem 'rspec_junit_formatter' to your Gemfile, bundle install, then run Rspec like this:

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

Source

Edit due to comment:

You can get this to work by adding a custom rake task:

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
肥爪爪 2025-01-01 19:12:37

如果您想要 JUnit 格式化程序,请看一下:https://github.com/natritmeyer/yarjuf对于 RSpec

Take a look at this: https://github.com/natritmeyer/yarjuf if you want a JUnit formatter for RSpec

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文