English 中文(简体)
铁路:在使用RSpec测试时“放开部分”
原标题:Rails: "missing partial" when calling render in RSpec test

I m trying to test for the presence of a form. I m new to Rails.

My 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

这一观点本身是新的。

<%= form_for(@message) do |f| %>
  <%= f.label :msg %> <br />
  <%= f.text_area :msg %>
  <%= f.submit "Submit" %>
<% end %>

当我操作<代码>spec时,它未能做到:

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)> 

谁知道问题是什么?

感谢!

最佳回答

不要提出任何理由。 审判:

require  spec_helper 

describe "messages/new.html.erb" do
  it "should render the form" do
    render
    rendered.should contain( blablabla ) 
  end
end
问题回答

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.

我发现这一点,首先将这一行文改为:

render :template => "messages/new.html.erb"

这使实际错误得以显现。 就我而言,我没有确定必要的变量,我对此作了更正。

一旦你正确确定派任,幽灵就会发生得当。

接着,你可以回头来:

render "messages/new.html.erb"

甚至

render

两者都将奏效。 失踪模板问题应当消失。 至少我这样做了:

我遇到了一个类似的问题,并惊讶地获悉,Rspec从描述的论据中得出了一些令人印象深刻的推断。 例如:

require  spec_helper 

describe "bills/payments/edit.html.erb" do
  it "Renders payment form" do
    assign(:payment, stub_model(Payment))
    render
  end
end

由于一些革命控制员/观众姓名,这一检验最初是:

describe "bills/payment/edit.html.erb" do

这真是说明所有情况,即使我设定了以下简称,它也无法找到一个参考部分。 在描述说明中确定道路是完全的。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签