2011-04-13 149 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 

而這裏的結果:

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 ....] 

正如你所看到的,沒有HTML和身體標記之間呈現標籤。但是,當我直接訪問該頁面(使用我們的服務器)時,沒有問題。這是一個配置問題?

回答

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