メモです。
例:テストでUser
の何かのメソッドを無効化したいとき
app/model/user.rb
class User < ActiveRecord::Base
def some_method
#テストでは実行したくない処理
end
end
allow_any_instance_of
と.to receive
を使います。
spec/model/user_spec.rb
before do
allow_any_instance_of(User)
.to receive(:some_method)
end
.any_instance
や.stub
でも実現できますが、それだと警告(deprecation warning)が出るので、こちらの方が良さそうです。
参考