简体   繁体   中英

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

I am using Rails 4.2 now.

My test file looks like:

# 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

In the controller, I set a cookie as: cookies[:my_cookie] = 'some_value' , so in the spec file, I will test if the cookie has been saved after access the special path as above, but failed. The response is only used in the controller, but how to test cookies in this case?

Reference:

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

This gem can do it:

show_me_the_cookies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM