2014-10-31 5 views
0

테스트 프로그램에 thoughtbot 소개를하고 있습니다. 그들이 원하는 것을 테스트하는 방법을 모르겠다.레일 컨트롤러 테스트

다음은 제 테스트입니다.

require "rails_helper" 

describe PeopleController do 
    describe "#create" do 
    context "when person is valid" do 
     it "redirects to #show" do 

     post :create, FactoryGirl.build_stubbed(:person) 

     expect(response).to redirect_to(show_people_path) 
     end 
    end 

    context "when person is invalid" do 
     it "redirects to #new" do 
     pending "create this test" 
     end 
    end 
    end 
end 

물론 공장 소녀를 사용하고 있습니다. 몇 가지 방법을 시도했습니다. 나는이 컨트롤러를 테스트하기 위해 괭이를 정말로 모른다.

어떤 통찰력도 좋을 것입니다.

답변

0

FactoryGirl을 사용하여 '유효하지 않은'사람을 만들고이를 post :create에 매개 변수로 보냅니다.

유효하지 않은 사람 레코드를 만들려면 nested factories을 FactoryGirl에서 사용하지 않으시겠습니까?/

사양/공장 테스트

context "when person is invalid" do 
    it "redirects to #new" do 
    post :create, FactoryGirl.build_stubbed(:invalid_person) 
    expect(response).to redirect_to action: :new 
    end 
end 
+0

감사에서

FactoryGirl.define do factory :person do ... factory :invalid_person do ... email nil ... end end end 

person.rb : 모델의 검증에 따라, 당신은 단순히 뭔가를 할 수 있습니다. 이것은 이제 더 이해가됩니다. 그러나 내 터미널 초기화되지 않은 상수 FactoryGirl 오류 던지고있다 ... hrm .. –

관련 문제