我正在研究Michael Hartl的铁路教程书,我遇到了一种奇怪的行为,我似乎无法排除故障。在清单8.4中它说rspec任务应该通过,但是我遇到了失败,错误是:
Failures:
1) Authentication signin page
Failure/Error: before { visit signin_path }
AbstractController::ActionNotFound:
The action 'sign_in' could not be found for StaticPagesController
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
2) Authentication signin page
Failure/Error: before { visit signin_path }
AbstractController::ActionNotFound:
The action 'sign_in' could not be found for StaticPagesController
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
Finished in 0.11364 seconds
2 examples, 2 failures
我不明白为什么它在寻找'sign_in'路径而不是我在路线中的'signin':
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
rspec测试也没有要求'sing_in'...它在测试中使用'signin_path':
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_content('Sign in') }
it { should have_title('Sign in') }
end
end
rails或rspec会自动将signin转录为sign_in吗?还有为什么它在StaticPagesController而不是SessionsController中寻找呢? - 我想这是因为它正在寻找/ sign_in而不是/ signin?所以听起来rspec正在将它改为sign_in?
答案 0 :(得分:0)
root 'static_pages#home'
然而,当我把它改为:
root to: 'static_pages#home'
所有测试现在都通过了。 root用户将static_pages控制器定义为查找路径的默认控制器是有道理的。通过添加'to:',它只匹配static_pages #home的'/'路径。也许我错了,但到目前为止,这就是我的样子。