Ruby on rails RSpec:Can';使用嵌套资源时,请不要将图像转换为字符串

Ruby on rails RSpec:Can';使用嵌套资源时,请不要将图像转换为字符串,ruby-on-rails,ruby,views,rspec,stub,Ruby On Rails,Ruby,Views,Rspec,Stub,我在和RSpec视图测试中遇到问题。我正在使用嵌套资源,并且模型具有一个“属于”关联 以下是我目前掌握的情况: describe "/images/edit.html.erb" do include ImagesHelper before(:each) do @image_pool = stub_model(ImagePool, :new_record => false, :base_path => '/')

我在和RSpec视图测试中遇到问题。我正在使用嵌套资源,并且模型具有一个“属于”关联

以下是我目前掌握的情况:

describe "/images/edit.html.erb" do
  include ImagesHelper

  before(:each) do
    @image_pool = stub_model(ImagePool, :new_record => false,
                             :base_path => '/')
    assigns[:image] = @image =
      stub_model(Image,
                 :new_record? => false,
                 :source_name => "value for source_name",
                 :image_pool => @image_pool)
  end

  it "renders the edit image form" do
    render

    response.should have_tag("form[action=#{image_path(@image)}][method=post]") do
      with_tag('input#image_source_name[name=?]', "image[source_name]")
    end
  end
end
我收到的错误是:

ActionView::TemplateError in '/images/edit.html.erb renders the edit image form'
can't convert Image into String
On line #3 of app/views/images/edit.html.erb

    1: <h1>Editing image</h1>
    2:
    3: <% form_for(@image) do |f| %>
    4:   <%= f.error_messages %>
    5:
    6:   <p>

    app/views/images/edit.html.erb:3
    /opt/dtcm/railstest/lib/ruby/gems/1.9.1/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:27:in `render_with_mock_proxy'
    /opt/dtcm/railstest/lib/ruby/gems/1.9.1/gems/rspec-rails-1.3.2/lib/spec/rails/example/view_example_group.rb:170:in `render'
“/images/edit.html.erb中的
ActionView::TemplateError呈现编辑图像表单”
无法将图像转换为字符串
app/views/images/edit.html.erb的第3行
1:编辑图像
2:
三:
4:   
5:
6:
app/views/images/edit.html.erb:3
/opt/dtcm/railstest/lib/ruby/gems/1.9.1/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action\u view/base.rb:27:“使用模拟代理渲染”
/opt/dtcm/railstest/lib/ruby/gems/1.9.1/gems/rspec-rails-1.3.2/lib/spec/rails/example/view_example_group.rb:170:in'render'
查看发生异常的rails代码并不是很有启发性。有没有关于如何缩小范围的想法


我尝试过的一件事是直接从示例中调用表单,但我遇到了一个不同的错误,抱怨Spec::Rails::example::ViewExampleGroup::Subclass_4:0xblah上缺少定义的“多态路径”。不确定这是否真的意味着什么。

好的。这与Rspec无关,与正确使用嵌套资源和rails帮助程序有关

显然,在视图中处理嵌套资源的正确方法是:

<% form_for [@image_pool, @image] do |f| %>

只是错误消息没有帮助