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