Rspec実行時に以下で怒られました。
WARNING: Using `expect { }.not_to raise_error(SpecificErrorClass)` risks false positives, since literally any other error would cause the expectation to pass, including those raised by Ruby (e.g. `NoMethodError`, `NameError` and `ArgumentError`), meaning the code you are intending to test may not even get reached. Instead consider using `expect { }.not_to raise_error` or `expect { }.to raise_error(DifferentSpecificErrorClass)`. This message can be suppressed by setting: `RSpec::Expectations.configuration.on_potential_false_positives = :nothing`.
雑にGoogle翻訳する
警告:
expect {} .not_to raise_error(SpecificErrorClass)を使用すると、誤検知のリスクがあります。これは、Rubyによって発生したエラー(例:NoMethodError、NameError、ArgumentError)を含め、文字通り他のエラーが期待を通過させるためです。つまり、テストしようとしているコードに到達できない可能性があります。代わりに、expect {} .not_to raise_errorまたはexpect {} .to raise_error(DifferentSpecificErrorClass)の使用を検討してください。このメッセージは、RSpec :: Expectations.configuration.on_potential_false_positives =:nothingを設定することで抑制できます。
expect {}.not_to raise_error (SpeificErrorClass) を使うと、該当エラーが起こる前に別エラーが投げられた場合などで通ってしまう誤検知の可能性があるらしい。
そのためエラーが起こらないことのテスト expect {}.not_to raise_error とするか、別のエラーが起こるテスト expect {} .to raise_error (DifferentSpecificErrorClass) にしましょうとのこと。
今回はクラスを指定せず、エラーが起こらないことを確認するテストに書き換えてRspecに大人しくなってもらいました。