开发者

Rack::Test not able to find web app cookie

While testing a Sinatra app with Cucumber, Rack::Test was not able to find the cooki开发者_Go百科e that my app created, even though I could clearly see that it was in the Rack::Test::CookieJar object by dumping it with "p".


I'm answering my own question in order to share the solution with others:

Rack::Test::CookieJar#[] will only return the value of a cookie if it also matches the domain and path. Unfortunately, unless your app's domain is "example.org" you're out of luck.

Fortunately, there's an easy fix: If you're testing with Sinatra, paste the following monkey patch anywhere in your env.rb file in the outermost (global) scope:

module Rack
  module Test
    DEFAULT_HOST='localhost'
  end
end

That's it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜