2013-08-30 5 views
0

를 실행하지 않습니다 I이 실패보기 사양이 있습니다보기 사양은 컨트롤러 before_action

require 'spec_helper' 

describe "ideas/edit" do 
    before(:each) do 
    @idea = assign(:idea, stub_model(Idea, 
     :phase => 1, 
     :brief => "MyText", 
     :image => "MyString", 
     :active => true, 
     :activity_list => ["Science & Technology"] 
    )) 
    end 

    it "renders the edit idea form" do 
    render 

    # Run the generator again with the --webrat flag if you want to use webrat matchers 
    assert_select "form[action=?][method=?]", idea_path(@idea), "post" do 
     assert_select "textarea#idea_brief[name=?]", "idea[brief]" 
     assert_select "input#idea_industry[name=?]", "idea[industry]" 
    end 
    end 
end 

오류 :

1) ideas/edit renders the edit idea form 
    Failure/Error: render 
    ActionView::Template::Error: 
     undefined method `empty?' for nil:NilClass 
    # ./app/views/ideas/_long_form.html.erb:27:in `block in _app_views_ideas__long_form_html_erb___781758430_98755320' 
    # ./app/views/ideas/_long_form.html.erb:1:in `_app_views_ideas__long_form_html_erb___781758430_98755320' 
    # ./app/views/ideas/edit.html.erb:3:in `_app_views_ideas_edit_html_erb__967817323_98657300' 
    # ./spec/views/ideas/edit.html.erb_spec.rb:15:in `block (2 levels) in <top (required)>' 

이 렌더링 된 양식의 관련 라인입니다. @categories 변수는 컨트롤러에서 초기화되지만, 스펙이 실행될 때 어떤 이유로 nil입니다. 내 컨트롤러에서

<div class="field"> 
    <%= f.label :category_list, "Categories" %> 
    <%= f.select :category_list, @categories, {selected:@idea.category_list}, {:multiple => true, :style => "height:180px;"} %> 
</div> 

나는이 :

before_action :set_categories, only: [:edit, :update] 
... 
def set_categories 
     @categories = [ 
     "Arts & Entertainment", 
     "Science & Technology", 
     "Business & Finance", 
     "Software & Internet", 
     "Retail", 
     "Education", 
     "Energy & Utilities", 
     "Food & Health", 
     "Media & Communications", 
     "Other" 
     ] 
    end 

나는 "단지"제거하려고 문제 해결 제한과 같은 오류가 발생했습니다. (각) 나는 그 이전에 다음 행을 추가하는 경우

흥미롭게도, 사양이 경과 블록 :

@categories = "Other" 

이 사양 컨트롤러에서 before_action를 실행하지 않는 것 같다. 이 예상되는 동작입니까? 나는 무엇을 여기에서 놓쳤 느냐? 나는이 라인의 권리를 추가 http://www.arailsdemo.com/posts/37 "인스턴스 변수와보기 렌더링"에서

을 :

답변

0

이 게시물보기 스펙은 컨트롤러에서와 변수가 사양 설정해야한다는 격리에서 실행하도록 구성되어 있음을 나타냅니다 내 사양에 "렌더링"하기 전

assign :categories, []