LoginSignup
3
2

More than 5 years have passed since last update.

RSpec で Rails の cookie をモック/スタブする

Posted at
# 取得
allow_any_instance_of(ActionDispatch::Cookies::CookieJar).to receive(:[]).with(cookie_name).and_return(cookie_value)

# 代入
expect_any_instance_of(ActionDispatch::Cookies::CookieJar).to receive(:[]=).with(cookie_name, cookie_value)

ただしallow_any_instance_ofの使用は非推奨なので注意。 cf. rspec/rspec-mocks, rspecでallow-any-instance-ofは使わない方がよい、が身に沁みたので別の方法で試してみる

3
2
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
3
2