簡體   English   中英

如何在功能測試中使用Rspec和Capybara測試cookie?

[英]How to test cookies with Rspec and Capybara in a feature test?

我現在正在使用Rails 4.2。

我的測試文件如下所示:

# spec/features/my_spec.rb
require 'spec_helper'
feature 'MyFeature', type: :feature do
  describe 'MyPage' do
    it 'Saved the cookie' do
      visit my_path
      expect(response.cookies[:my_cookie]).to eq('some_value')
    end
  end
end

在控制器中,我將cookie設置為: cookies[:my_cookie] = 'some_value' ,因此在規范文件中,我將測試訪問上述特殊路徑后是否已保存cookie,但失敗了。 response僅在控制器中使用,但是在這種情況下如何測試cookie?

參考:

https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/cookies

這個寶石可以做到:

show_me_the_cookies

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM