I see I can test routes with rspec like this:
get("/").should route_to("welcome#index")
but I have constraints based on the hostname or parts of hostnames and redirects between several ones. How do I specify a hostname when testing?
How do I run the tests with proper configuration? I tried printing root_url and I got:
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
The same error happens on mine whenever I run rspec spec/
The entire error is actually:
Failure/Error: @user = Factory(:user)
ActionView::Template::Error:
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
# ./app/views/devise/mailer/confirmation_instructions.html.erb:5:in `_app_views_devise_mailer_confirmation_instructions_html_erb__980323237__638702928'
# ./spec/models/campaign_spec.rb:21
The following line:
# ./app/views/devise/mailer/confirmation_instructions.html.erb:5:in `_app_views_devise_mailer_confirmation_instructions_html_erb__980323237__638702928'
actually gave me the hint that devise is the one throwing out the error.
Turns out I haven't set
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
in config/environments/test.rb
(only in development.rb)
Adding the config option cleared out the errors on mine. I'm suspecting you're using other gems that requires the same option set.