Matching redirects

17 views
Skip to first unread message

Jack Royal-Gordon

unread,
Oct 20, 2020, 9:28:42 PM10/20/20
to rs...@googlegroups.com
This is a stupid one. When I moved my app using RSpec 3.9 from Ruby 2.0/Rails 4.2 to Ruby 2.2/Rails 4.2, some of my tests died with a very stupid error of the form:

Expected response to be a redirect to <http://test.host/> but was a redirect to <http://localhost/>

I tried adding "config.action_controller.default_url_options = {protocol: 'http', host: 'test.host’}
and "Rails.application.routes.default_url_options = {protocol: 'http', host: 'test.host’}”
with no change in behavior.

My test looks like: expect(response).to redirect_to(app_path.root_path)

where app_path has the following definition in spec_helper.rb:
  def app_path
    Rails.application.routes.url_helpers
  end

Note, by the way that I’m using #root_path and yet I’m getting a host in the URL; not sure why that is.

Jon Rowe

unread,
Oct 21, 2020, 7:04:06 AM10/21/20
to rs...@googlegroups.com
Hi Jack

Can you compare the versions of Gems between the two? Something like capybara or rack test might have changed which might have changed the default host used to emulate the browser behaviour...

Jack Royal-Gordon

unread,
Oct 21, 2020, 12:05:29 PM10/21/20
to rs...@googlegroups.com
While preparing to respond to your question, Jon, I went to re-check all my assumptions, including verifying that #default_url_options was not defined, only to find that it was defined and was the source of the localhost. Apparently, the spec file does not execute in the context of the controller, so that definition would have not been there for it. Mystery solved!

Thanks for your quick response.

Jack

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/dejalu-217-9a060c85-5373-4bdf-a695-f9c42933993e%40jonrowe.co.uk.

Reply all
Reply to author
Forward
0 new messages