[英]How do you fake cookies in capybara?
I am testing an app that would be installed on a sub domain to take advantage of the cookies created by the main app. 我正在测试一个应用程序,该应用程序将安装在子域上,以利用主应用程序创建的cookie。 How ever unless both apps are running on, say:
site.local.com
the app I am testing doesn't have access to a session controller, thus I cannot create cookies in testing via typical sign in methods. 除非两个应用程序都在运行,例如:
site.local.com
但是我正在测试的应用程序无权访问会话控制器,因此我无法通过典型的登录方法在测试中创建Cookie。
So my question is, how do I - in capybara - fake cookies? 所以我的问题是,如何-在水豚中-假饼干? I have tried something like:
我已经尝试过类似的东西:
it "should ... ", type: :request do
sign_in(@user)
...
end
#sign_in definition:
def sign_in(user)
cookies.signed[:auth_token] = user.auth_token
end
How ever the issue is: 问题出在哪里:
Failure/Error: sign_in(@user)
NameError:
undefined local variable or method `cookies' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x000000090cd998>
尝试这个:
page.driver.browser.set_cookie("auth_token=#{user.auth_token}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.