假设我有一堆测试:

spec/code_spec.rb:

require "rails_helper"

RSpec.describe Code do
  xit { Code.evaluate("Twitter.search") }
  xit { Code.evaluate("Slack.send") }
  xit { Code.evaluate("Twitter.send") }
end

我得到了:

~/s/d/code> rspec spec/code_spec.rb

Randomized with seed 54828

Code
  example at ./spec/code_spec.rb:5 (PENDING: Temporarily skipped with xit)
  example at ./spec/code_spec.rb:6 (PENDING: Temporarily skipped with xit)
  example at ./spec/code_spec.rb:4 (PENDING: Temporarily skipped with xit)

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Code 
     # Temporarily skipped with xit
     # ./spec/code_spec.rb:5

  2) Code 
     # Temporarily skipped with xit
     # ./spec/code_spec.rb:6

  3) Code 
     # Temporarily skipped with xit
     # ./spec/code_spec.rb:4


Finished in 0.00251 seconds (files took 3.32 seconds to load)
3 examples, 0 failures, 3 pending

Randomized with seed 54828

我希望RSpec执行测试,如果测试通过则失败,理想情况下会告诉我需要取消跳过它们.

有可能吗?

推荐答案

您可以在测试描述中添加pending: 'pending reason'

一切都在这里描述https://www.joshmcarthur.com/til/2019/05/27/pending-block-examples-with-rspec.html

此测试将由RSpec运行,但不会使整个测试套件失败

it 'adds 1 + 1 and equals 3', pending: true do
  expect(1 + 1).to eq 3
end

但此测试将失败,因为未引发任何错误

it 'adds 1 + 1 and equals 2', pending: true do
  expect(1 + 1).to eq 2
end

Ruby相关问答推荐

如何使用Ruby中的时区函数S标准库?

如何判断 postgres 中使用 ruby​​ 的查询是否失败?

如何过滤散列数组以仅获取另一个数组中的键?

为什么 Rake 不能连续调用多个任务?

你如何称呼 Ruby 中的 &: 运算符?

在一组字符串中找到最长的公共起始子字符串

`expect`测试中的Rspec`eq`与`eql`

Rake 与 Thor 的自动化脚本?

为什么在 ruby​​ / rails / activerecord 中并不总是需要 self ?

从类对象获取类位置

使用 `?`(问号)在 Ruby 中获取 ASCII 字符代码失败

Ruby中的file.open、open和IO.foreach,有什么区别?

为什么 Ruby 没有真正的 StringBuffer 或 StringIO?

我们什么时候在 Rails 中使用 "||=" 运算符?它的意义是什么?

rbenv install --list 不列出 2.1.2 版本

为什么 Ruby 文档中的方法前面有一个井号?

Ruby 中的 each 和 collect 方法有什么不同

如何在 Ruby 中对数组进行分块

如何计算 Ruby 数组中的重复元素

如何使用 Ruby 删除回车?