Invalid domain: ".example.com" in rspec after changing session_store to domain: :all

I changed the session store from

config.session_store :cookie_store, :key => "_mysite_session2"

to

config.session_store :cookie_store, :key => "_mysite_session3", domain: :all

Now, when I run the specs there is an error

     ArgumentError:
       invalid domain: ".example.com"
     # ..ruby.../gems/rack-2.2.4/lib/rack/mock.rb:239:in `new'
     # ..ruby.../gems/rack-2.2.4/lib/rack/mock.rb:239:in `block in parse_cookies_from_header'
     # ..ruby.../gems/rack-2.2.4/lib/rack/mock.rb:236:in `each'
     # ..ruby.../gems/rack-2.2.4/lib/rack/mock.rb:236:in `parse_cookies_from_header'
     # ..ruby.../gems/rack-2.2.4/lib/rack/mock.rb:187:in `initialize'
     # ..ruby.../gems/rack-test-2.0.2/lib/rack/test.rb:360:in `new'
     # ..ruby.../gems/rack-test-2.0.2/lib/rack/test.rb:360:in `process_request'
     # ..ruby.../gems/rack-test-2.0.2/lib/rack/test.rb:165:in `custom_request'
     # ..ruby.../gems/rack-test-2.0.2/lib/rack/test.rb:114:in `get'
     # ..ruby.../gems/capybara-3.38.0/lib/capybara/rack_test/browser.rb:80:in `process'
     # ..ruby.../gems/capybara-3.38.0/lib/capybara/rack_test/browser.rb:55:in `process_and_follow_redirects'
     # ..ruby.../gems/capybara-3.38.0/lib/capybara/rack_test/browser.rb:26:in `visit'
     # ..ruby.../gems/capybara-3.38.0/lib/capybara/rack_test/driver.rb:46:in `visit'
     # ..ruby.../gems/capybara-3.38.0/lib/capybara/session.rb:280:in `visit'
     # ..ruby.../gems/capybara-3.38.0/lib/capybara/dsl.rb:52:in `call'
     # ..ruby.../gems/capybara-3.38.0/lib/capybara/dsl.rb:52:in `visit'

I have cleared the tmp folder. I wonder if anyone has seen this and what it might be. Rails 6 by the way.

Thanks

If you are getting this ArgumentError using Ruby 3.1.3, 3.0.5 or Ruby 2.7.7, upgrade cgi gem version to 0.3.6.

Refer to https://github.com/ruby/cgi/pull/29

5 Likes

Oh, thanks. I was exactly migrating to 2.7.7

Will try

Yes, This was it. Thanks @yahonda

2 Likes

Thank you! you save my day. I added that gem to my project and it works.