2011-04-13 6 views
1

본 사이트에서 정식 링크를 만들지 않았는지 테스트하고 RSpec에서 다음과 같은 Webrat 문제를 겪고 있습니다.RSpec이 헤드 태그를 렌더링하지 않습니다.

여기 테스트입니다 :

[...setup stuff...] 
it "should not render a canonical link rel" do 
    assign(:post, @post) 
    render 
    rendered.should have_selector('link', { :rel => 'canonical', :href => post_path(@post, :only_path => false)}) 
end 

그리고 여기 결과 : 당신이 볼 수 있듯이, HTML과 body 태그 사이에 렌더링에는 태그가

Failure/Error: rendered.should have_selector('link', { :rel => 'canonical', :href => post_path(@post, :only_path => false)}) 
    expected following output to contain a <link href='http://test.host/posts/123913-post-name' rel='canonical'/> tag: 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 

    <html><body> 

    <div> 
    [.... lots more stuff that is rendered properly ....] 

없습니다. 그러나, 나는 (서버를 사용하여) 직접 페이지에 액세스 할 때 아무런 문제가 없습니다. 이것은 구성 문제입니까?

답변

1

여기에 대한 대답은 "렌더링"호출에 있습니다. 그냥 "렌더링"대신 템플릿과 레이아웃을 설정해야합니다. 작동 원리는 다음과 같습니다.

it "should render a canonical link rel" do 
    assign(:post, @post) 
    render :template => "posts/show", :layout => "layouts/application" 
    rendered.should have_selector('link', { :rel => 'canonical', :href => post_path(@post, :only_path => false)}) 
end 
관련 문제