2

While testing a Sinatra app with Cucumber, Rack::Test was not able to find the cookie that my app created, even though I could clearly see that it was in the Rack::Test::CookieJar object by dumping it with "p".

4

1 回答 1

3

我正在回答我自己的问题,以便与他人分享解决方案:

Rack::Test::CookieJar#[] 只会返回匹配域和路径的 cookie 的值。不幸的是,除非您的应用程序的域是“example.org”,否则您就不走运了。

幸运的是,有一个简单的解决方法:如果您使用 Sinatra 进行测试,请将以下猴子补丁粘贴到 env.rb 文件中最外层(全局)范围内的任何位置:

模块架
  模块测试
    DEFAULT_HOST='本地主机'
  结尾
结尾

而已!

于 2010-03-15T20:59:33.107 回答