Techioz Blog

スキップされた rspec テストを実行し、合格すると失敗します

概要

たくさんのテストがあるとしましょう:

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 がテストを実行し、テストが成功した場合に失敗し、理想的にはテストをスキップしないようにする必要があることを私に通知することです。

出来ますか?

解決策

テストの説明に「保留中: ’保留中の理由」を追加できます。

すべてはここで説明されています 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