LoginSignup
27
22

More than 5 years have passed since last update.

Rspecで標準出力をテストする

Posted at

captureメソッドは非推奨

標準出力テストはcaptureメソッドを使う例がよく出てくるので、それを使ってみたところ、DEPRECATION WARNINGが出てしまったので、他の方法を調べてみました。

DEPRECATION_WARNING
expect(capture(:stdout){ puts "foo" }).to eq "foo\n"

output("foo\n").to_stdoutでOK

以下のように変更したら、OK!!

rspec
expect { puts "foo" }.to output("foo\n").to_stdout
27
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
22