新手问题 rspec 测试问题,无法找到具名路由

omobh · 2014年12月20日 · 2086 次阅读

在照着 Ruby on Rails 教程做,但是到了 5.3.2 路由一章做不过去了,就是在 routes 中把静态路径改成 match 后,浏览器可以正常访问,但是 rspec 中 visit 改成 root_path 后,就全部访问不到了,测试全错,郁闷 为啥阿~~ 我的文件内容: routes:

SampleApp::Application.routes.draw do root :to => 'static_pages#home' match '/help', to: 'static_pages#help', via: 'get' match '/contact', to: 'static_pages#contact', via: 'get' match '/about', to: 'static_pages#about', via: 'get' end

spec:

require 'spec_helper'

describe "StaticPages" do describe "Home page" do it "should have the content 'Sample App'" do visit root_path expect(page).to have_content('Sample App') end it "should have the title Home" do visit root_path expect(page).to have_title('Ruby on Rails Tutorial Sample App | Home') end end end

Gemfile: source 'https://rubygems.org' gem 'rails', '4.1.8' gem 'bootstrap-sass' gem 'minitest' group :development, :test do gem 'sqlite3' gem 'spork-rails', github: 'railstutorial/spork-rails' gem 'guard-rspec' gem 'guard-spork' gem 'rspec-rails' gem 'childprocess', '0.3.6' end group :test do gem 'selenium-webdriver', '2.35.1' gem 'capybara', '2.2.0' end gem 'sass-rails', '~> 4.0.3' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 2.0' group :doc do gem 'sdoc', '~> 0.4.0', require: false end

Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring

gem 'spring', group: :development

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号