18
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RSpecのany_instance deprecation修正方法

Last updated at Posted at 2014-09-07

はじめに

RSpec3でany_instance.stubを含むテスト実行時に、以下のdeprecateメッセージが表示された。
メッセージを表示させない方法が見つけにくかったのでメモしておく。
初学者(自分)は、エラーメッセージで検索できないと対応が難しい。

Using `any_instance` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead.

環境

モジュール バージョン
ruby ruby 2.1.2p95
rails Rails 4.1.1
rspec 3.0.4

修正方法

allow_any_instance_ofを使う。
ClassNameは適当に置き換えてください。

修正前

      # ClassName.any_instance.stub(:save).and_return(false)

修正後

      allow_any_instance_of(ClassName).to receive(:save).and_return(false)

参考

RSpec any_instance deprecation: how to fix it?

18
20
1

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
18
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?