运行跳过的 rspec 测试,如果通过则失败

问题描述 投票:0回答:1

假设我有很多测试:

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 执行测试,如果通过则失败,理想情况下告诉我需要取消跳过它们。

可以吗?

ruby-on-rails ruby testing rspec
1个回答
0
投票

您可以添加

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
© www.soinside.com 2019 - 2024. All rights reserved.