2
我在routes.rb
定義的root_path
和我打電話get root_path
在其他測試中,但由於某些原因,在test/controllers/application_controller_test.rb
,我打電話get root_path
時出現此錯誤:沒有路由錯誤抵達時root_path,但只是在我的一些測試
ApplicationControllerTest#test_should_get_index_when_not_logged_in:
ActionController::UrlGenerationError: No route matches {:action=>"/", :controller=>"application"}
test/controllers/application_controller_test.rb:10:in `block in <class:ApplicationControllerTest>'
這裏的routes.rb
Rails.application.routes.draw do
root 'application#index'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :users
resources :account_activations, only: [:edit]
resources :password_resets, only: [:edit, :new, :create, :update]
resources :lessons, only: [:show, :index] do
resources :pre_lesson_surveys, shallow: true,
except: :destroy
end
end
這裏的application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper
def index
render 'admin_home_page' if admin?
render 'user_home_page' if logged_in?
@user = User.new unless logged_in?
end
end
和這裏的tests
test "should get index when not logged in" do
get root_path
assert_response :success
assert_not is_logged_in?
assert_template 'application/index'
end
我敢肯定,我只是在做一些愚蠢的事,但我不能把我的手指上
我已經與測試建立主要不是使用RSpec書面工作。有沒有辦法做到這一點沒有rspec?我已經嘗試將測試更改爲「get」/「',但它不起作用,如果這有助於您嘗試 –
:'get:index'? –
這有效,任何想法爲什麼'得到root_path'或'get「/」'沒有工作,但這是嗎? –