【问题标题】:How to test cookies with Rspec and Capybara in a feature test?如何在功能测试中使用 Rspec 和 Capybara 测试 cookie?
【发布时间】:2015-04-09 06:39:58
【问题描述】:

我现在使用的是 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',所以在spec文件中,我会测试上面访问特殊路径后cookie是否已经保存,但是失败了。 response只在控制器中使用,但是这种情况下如何测试cookie呢?

参考:

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

【问题讨论】:

  • 这似乎是你应该在控制器规范中测试的东西,而不是功能规范。
  • 感谢您的帖子。我想在功能规范中进行 cookie 测试,但 respond 似乎只能用于控制器测试。

标签: ruby-on-rails ruby testing cookies rspec


【解决方案1】:

这颗宝石可以做到:

show_me_the_cookies

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多