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:
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.