rspec路由测试和主机 [英] rspec route testing and hosts

查看:88
本文介绍了rspec路由测试和主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到我可以使用rspec测试路由,如下所示:

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?

如何使用正确的配置运行测试?我尝试打印root_url并得到:

How do I run the tests with proper configuration? I tried printing root_url and I got:

要链接的主机缺失!请提供:host参数,设置 default_url_options [:host],或将:only_path设置为true

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

推荐答案

每当我运行rspec spec/

整个错误实际上是:

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

以下行:

# ./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.

结果我还没设置

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

config/environments/test.rb中(仅在development.rb中)

in config/environments/test.rb (only in development.rb)

添加config选项清除了我的错误. 我怀疑您正在使用其他需要相同选项集的宝石.

Adding the config option cleared out the errors on mine. I'm suspecting you're using other gems that requires the same option set.

这篇关于rspec路由测试和主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆