导轨:“部分缺失”当调用“render”时;在 RSpec 测试中
我正在尝试测试表单是否存在。我是 Rails 新手。
我的 new.html.erb_spec.rb 文件的内容是:
require 'spec_helper'
describe "messages/new.html.erb" do
it "should render the form" do
render '/messages/new.html.erb'
reponse.should have_form_putting_to(@message)
with_submit_button
end
end
视图本身 new.html.erb 具有代码:
<%= form_for(@message) do |f| %>
<%= f.label :msg %> <br />
<%= f.text_area :msg %>
<%= f.submit "Submit" %>
<% end %>
当我运行 rspec 时,它会失败,如下所示:
1) messages/new.html.erb should render the form
Failure/Error: render '/messages/new.html.erb'
Missing partial /messages/new.html with {:handlers=>[:erb, :rjs,:builder,:rhtml, :rxml], :formats=>[:html,:text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]} in view paths "/Users/tristanmartin/whisperme/app/views"
# ./spec/views/messages/new.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'
有谁知道问题是什么?
谢谢!
I'm trying to test for the presence of a form. I'm new to Rails.
My new.html.erb_spec.rb
file's contents are:
require 'spec_helper'
describe "messages/new.html.erb" do
it "should render the form" do
render '/messages/new.html.erb'
reponse.should have_form_putting_to(@message)
with_submit_button
end
end
The view itself, new.html.erb, has the code:
<%= form_for(@message) do |f| %>
<%= f.label :msg %> <br />
<%= f.text_area :msg %>
<%= f.submit "Submit" %>
<% end %>
When I run rspec
, it fails as so:
1) messages/new.html.erb should render the form
Failure/Error: render '/messages/new.html.erb'
Missing partial /messages/new.html with {:handlers=>[:erb, :rjs,:builder,:rhtml, :rxml], :formats=>[:html,:text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]} in view paths "/Users/tristanmartin/whisperme/app/views"
# ./spec/views/messages/new.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'
Does anyone know what the problem is?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要对“渲染”给出任何参数。尝试以下操作
don't give any argument to 'render'. try the following
我遇到了同样的问题,如果您还没有找到解决方案,我将描述我为解决此问题所做的事情。
我认为问题是 rspec 在这里报告了一个误导性错误。真正的错误是别的东西。
我通过首先将该行更改为:
这使得实际错误浮出水面。就我而言,我没有设置所需的变量,我对此进行了更正。
一旦正确设置了分配,规范就可以正常运行。
然后你可以回到其中一个:
或者甚至
两者都可以。缺少模板的问题应该消失了。至少对我来说是这样。 :)
I experienced the same issue and I'll describe what I did to solve this, in case you haven't found the solution yet.
I think the problem is rspec reports an misleading error here. The real error is something else.
I found this out by first changing the line to:
This allowed the actual error to surface. In my case, I was not setting up required variable(s), which I corrected.
Once you have set the assigns correctly, spec ran properly.
Then you may go back to either:
or even just
both will work. Missing template issue should be disappeared. At least it did for me. :)
我遇到了类似的问题,并惊讶地发现 Rspec 从描述参数中做出了一些令人印象深刻的推论。例如:
由于一些进化的控制器/视图名称,这个测试最初有:
这真的把一切搞乱了,即使我在渲染后设置了:模板,它也无法找到引用的部分。修复描述语句中的路径就解决了这一切。
I ran into a similar issue, and was surprised to learn that Rspec does some impressive inference from the describe argument. For example:
Due to some evolutionary controller / view names, this test originally had:
that really messed everything up, and even if I set the :template after render, it was unable to find a referenced partial. Fixing up the path in the describe statement fixed it all.