ruby-on-rails – Rails:rspec中url helper的主机名错误
发布时间:2020-12-16 23:26:13 所属栏目:百科 来源:网络整理
导读:Url帮助程序(例如root_url)在app控制器和rspec示例中返回不同的主机名. 我已成功地在我的rails应用程序中为url helpers设置域,如下所示: class ApplicationController ActionController::Base def default_url_options {host: "foo.com",only_path: false}
Url帮助程序(例如root_url)在app控制器和rspec示例中返回不同的主机名.
我已成功地在我的rails应用程序中为url helpers设置域,如下所示: class ApplicationController < ActionController::Base def default_url_options {host: "foo.com",only_path: false} end end 例如,root_url在应用程序中输出“http://foo.com/”,但在我的请求规范中输出“http://example.com”.在rails 3.2中全局应用这些url选项的建议方法是什么,以便它们影响我的规范? 解决方法
在功能规格中,主持人!已被弃用.将这些添加到您的rspec_helper.rb:
# Configure Capybara expected host Capybara.app_host = 'http://lvh.me:3000' # Configure actual routes host during test before(:each) do if respond_to?(:default_url_options) default_url_options[:host] = 'http://lvh.me:3000' end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |