rspecでエラーテストが失敗する
解決
export { subject } に変更
context "test" do subject { raise RuntimeError } it { expect { subject }.to raise_error(RuntimeError) } end 事象
Failure/Error: raise RuntimeError が発生する。
context "test" do subject { raise RuntimeError } it { is_expected.to raise_error(RuntimeError) } end RSpec の is_expected で raise_error を検知したかった - Secret Garden(Instrumental)
RSpec/ImplicitSubject エラー
Class: RuboCop::Cop::RSpec::ImplicitSubject — Documentation for rubocop-rspec (1.38.1) により、 is_expected の使用は禁止されていたので下記の記法はできなくなった。
subject には、 procを渡す必要がある。
subject { -> { raise RuntimeError } } この場合、 is_expected.to eq "return value" の比較はできなくなるので、比較系とエラー系でsubjectを分ける必要がある。
This post is licensed under CC BY 4.0 by the author.