2011-09-15 5 views
15

나는 rspec에서 나의 sinatra app (더 구체적으로 padrino app)의 홈페이지에서 리디렉션을 테스트하려고합니다. redirect_to을 찾았지만 rspec-rails에만있는 것으로 보입니다. 당신은 시네 트라에서 어떻게 시험합니까?rspec을 사용하여 sinatra에서 리디렉션을 테스트하려면 어떻게해야합니까?

it "Homepage should redirect to locations#index" do 
    get "/" 
    last_response.should be_redirect # This works, but I want it to be more specific 
    # last_response.should redirect_to('/locations') # Only works for rspec-rails 
    end 

답변

21

이 (테스트하지)이 시도 :

it "Homepage should redirect to locations#index" do 
    get "/" 
    last_response.should be_redirect # This works, but I want it to be more specific 
    follow_redirect! 
    last_request.url.should == 'http://example.org/locations' 
end 
+0

I 오류 받고 있어요 : 장애/오류 : follow_redirect! Sequel :: DatabaseError : SQLite3 :: SQLException : 해당 테이블이 없습니다. locations . 그래도 데이터베이스 문제라고 생각합니다. 이것에 대해 조사 할 필요가 있습니다 ... – zlog

+0

네,이 작품. 감사! – zlog

+1

'last_request','last_response' 메쏘드가 문서화되어있는 곳을 말해 줄 수 있습니까? 어떻게'url'과 같은 메소드를 호출 할 수 있습니까? 나는 새롭기 때문에 그것을 얻을 수 없었다. –

15

더 직접적으로 당신은 last_response.location을 사용할 수 있습니다

그래서 기본적으로,이 같은 일을하고 싶습니다. 새로운 expect 구문에서

it "Homepage should redirect to locations#index" do 
    get "/" 
    last_response.should be_redirect 
    last_response.location.should include '/locations' 
end 
1

그것은해야한다 :

it "Homepage should redirect to locations#index" do 
    get "/" 
    expect(last_response).to be_redirect # This works, but I want it to be more specific 
    follow_redirect! 
    expect(last_request.url).to eql 'http://example.org/locations' 
end 
관련 문제