加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 未定义的局部变量或方法`root_path’

发布时间:2020-12-16 19:47:46 所属栏目:百科 来源:网络整理
导读:我的rspec文件中有以下代码块位于/ spec文件夹的根目录中. require 'spec_helper'describe "home" do subject { page } before(:each) { visit root_path } describe "page" do it { should have_title('My Page')} endend 当我运行它,我得到 undefined loca
我的rspec文件中有以下代码块位于/ spec文件夹的根目录中.
require 'spec_helper'

describe "home" do

 subject { page }

 before(:each) { visit root_path }

 describe "page" do
 it { should have_title('My Page')}
 end

end

当我运行它,我得到

undefined local variable or method `root_path'

哪个没有任何意义.当我跟踪rails教程一个类似的设置工作很好.谁能帮忙?

编辑:

我的路线包括

root "static#home"

编辑2:

重新打开此主题.将我的根声明移动到顶部没有修复它.

编辑3:

在我的rspec配置中包含url_helpers的功能.我从来没有这样做过.任何人都可以回答为什么这么做

解决方法

默认情况下,命名路由不可用于规格.将以下代码添加到spec_helper.rb中:
RSpec.configure do |config|
  config.include Rails.application.routes.url_helpers
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读