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

> On Oct 21, 2020, at 4:03 AM, Jon Rowe <[email protected]> wrote:
> 
> 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...
> 
> Cheers
> Jon
> ----------------
> [email protected]
> https://jonrowe.co.uk
> 
> On 21 October 2020 at 02:28, Jack Royal-Gordon wrote:
>> 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/ 
>> <http://test.host/>> but was a redirect to <http://localhost/ 
>> <http://localhost/>>
>> 
>> I tried adding "config.action_controller.default_url_options = {protocol: 
>> 'http', host: 'test.host <http://test.host/>’}”
>> and "Rails.application.routes.default_url_options = {protocol: 'http', host: 
>> 'test.host <http://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.
> 
> -- 
> 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 [email protected] 
> <mailto:[email protected]>.
> 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
>  
> <https://groups.google.com/d/msgid/rspec/dejalu-217-9a060c85-5373-4bdf-a695-f9c42933993e%40jonrowe.co.uk?utm_medium=email&utm_source=footer>.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/FA6DD771-8101-4BEB-9DB0-FEE3269C79A2%40pobox.com.

Reply via email to