使用Rspec测试Rails 4可安装引擎的视图

时间:2013-09-10 16:33:05

标签: ruby-on-rails ruby rspec-rails

我正在开发基于rails4和rspec测试框架的可安装引擎。我通过'r g scaffold post title content'构建了一个简单的应用程序。除了视图测试,一切正常。当我执行rake app:spec:views时,它总是说:

  

“失败/错误:渲染        ::的ActionView MissingTemplate:          缺少模板帖子/ indexwith {:locale => [:en],:formats => [:html,:text,:js,:css,:ics,:csv,:png,:jpeg,:gif,   :bmp,:tiff,:mpeg,:xml,:rss,:atom,:yaml,:multipart_form,   :url_encoded_form,:json,:pdf,:zip],:handlers => [:erb,:builder,   :raw,:ruby]}。搜索范围:            *“/ projects / _plugins / blorgh4m_rspect / spec / dummy / app / views”            *“/ projects / _plugins / blorgh4m_rspect / app / views”“

所以我将“渲染”更改为“渲染模板:”blorgh4m_rspect / posts / show“,错误变为

  

“失败/错误:渲染模板:”blorgh4m_rspect / posts / index“        ::的ActionView ::模板错误:          未定义的方法post_path' for #<#<Class:0x0000000427cb40>:0x00000004ff97f0> # ./app/views/blorgh4m_rspect/posts/index.html.erb:21:in阻止   的 home_elbbub _works_projects__plugins_blorgh_m_rspect_app_views_blorgh_m_rspect_posts_index_html_erb__569958834415291959_42058840'        #。/ app/views/blorgh4m_rspect/posts/index.html.erb:15:in each' # ./app/views/blorgh4m_rspect/posts/index.html.erb:15:in home_elbbub _works_projects__plugins_blorgh_m_rspect_app_views_blorgh_m_rspect_posts_index_html_erb__569958834415291959_42058840'        #./spec/views/blorgh4m_rspect/posts/index.html.erb_spec.rb:20:in“阻止(2级)'”

看起来所有路径路径助手都无效。

有人见过这种情况吗?你有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您必须命名您的路线。 http://guides.rubyonrails.org/engines.html#routes

engine_name.post_path