开发者

Understanding RSpec Failure

I'm getting these failures when running rspec spec/. The spec that is failing is was auto-generated with the scaffolding. I'm trying to understand RSpec but I don't know where to begin looking for the cause other than it feels like some method is missing?!? Yet, app appears to be working fine. Nothing about these failures appears in test.log. Is there another place I should be looking for hints to track this down?

$ rspec spec/
.....................F.F.

Failures:

  1) clowns/edit.html.haml renders the edit clown form
     Failure/Error: render
     undefined method `to_sym' for nil:NilClass
     # ./app/views/clowns/_form.html.haml:4:in `block in _app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
     # ./app/views/clowns/_form.html.haml:1:in `_app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
     # ./app/views/clowns/edit.html.haml:3:in `_app_views_clowns_edit_html_haml___574620942879655923_2176081980_599706797287605391'
     # ./spec/views/clowns/edit.html.haml_spec.rb:13:in `bl开发者_运维知识库ock (2 levels) in <top (required)>'

  2) clowns/new.html.haml renders new clown form
     Failure/Error: render
     undefined method `to_sym' for nil:NilClass
     # ./app/views/clowns/_form.html.haml:4:in `block in _app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
     # ./app/views/clowns/_form.html.haml:1:in `_app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
     # ./app/views/clowns/new.html.haml:3:in `_app_views_clowns_new_html_haml__1085372210838170129_2159651900_599706797287605391'
     # ./spec/views/clowns/new.html.haml_spec.rb:12:in `block (2 levels) in <top (required)>'

Finished in 1.03 seconds
27 examples, 2 failures, 2 pending

And here is the spec that apparently fails (edit.html.haml_spec.rb). It was auto-generated by rails g scaffold Clown name:string balloons:integer:

#spec/views/clowns/edit.html.haml_spec.rb
require 'spec_helper'

describe "clowns/edit.html.haml" do
  before(:each) do
    @clown = assign(:clown, stub_model(Clown,
      :name => "MyString",
      :balloons => 1
    ))
  end

  it "renders the edit clown form" do
    render

    # Run the generator again with the --webrat-matchers flag if you want to use webrat matchers
    assert_select "form", :action => clown_path(@clown), :method => "post" do
      assert_select "input#clown_name", :name => "clown[name]"
      assert_select "input#clown_balloons", :name => "clown[balloons]"
    end
  end
end


Are you also using simple_form (or perhaps even formtastic)? I get the same error when I convert the scaffold forms from standards forms to simple_form forms (form_for(@user) => simple_form_for(@user)).

It still works, as you say, so I'm not sure it's worth worrying about. I think you'd be better off just letting Cucumber worry about it. Sarah Mei says view specs are a waste of time. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜