2
votes

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

1
That seems like something you should test for in a controller spec, and not a feature spec.forthowin
Thank you for your post. I want to do a cookies test in a feature spec, but respond seems only can be used in a controller test.s-cho-m

1 Answers

0
votes