在尝试创建登录页面的测试中,我不断遇到同样的两次失败。
这是错误消息: $ bundle exec rspec spec/requests/user_pages_spec.rb FF
失败:
1) 用户页面注册页面Failure/Error: before { visit signup_path } ActionView::Template::Error: undefined method |' for "Ruby on Rails Tutorial Sample App":String
# ./app/helpers/application_helper.rb:9:in
full_title' # ./app/views/layouts/application.html.erb:4:in _app_views_layouts_application_html_erb__2148911516627374684_2168968760'
# ./spec/requests/user_pages_spec.rb:8:in
block (3 levels)在 '
2) 用户页面注册页面Failure/Error: before { visit signup_path } ActionView::Template::Error: undefined method |' for "Ruby on Rails Tutorial Sample App":String
# ./app/helpers/application_helper.rb:9:in
full_title' # ./app/views/layouts/application.html.erb:4:in _app_views_layouts_application_html_erb__2148911516627374684_2168968760'
# ./spec/requests/user_pages_spec.rb:8:in
block (3 levels)在 '
在 0.17668 秒内完成 2 个示例,2 个失败
失败的例子:
rspec ./spec/requests/user_pages_spec.rb:10 # 用户页面注册页面 rspec ./spec/requests/user_pages_spec.rb:11 # 用户页面注册页面
这是文件 user_pages_spec.rb
需要'spec_helper'
描述“用户页面”做
主题{页面}
在 { 访问 signup_path } 之前描述“注册页面”
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
结束结束
这是文件 application_helper.rb:
模块 ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title}" | "#{page_title}"
end
end
end
这是文件 routes.rb SampleApp::Application.routes.draw do get "users/new"
root to: 'static_pages#home'
match '/signup', to: 'users#new'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
我一直坚持这一点,所以任何帮助将不胜感激!
谢谢!