Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 RSpec不呈现Head标记_Ruby On Rails 3_View_Rspec - Fatal编程技术网

Ruby on rails 3 RSpec不呈现Head标记

Ruby on rails 3 RSpec不呈现Head标记,ruby-on-rails-3,view,rspec,Ruby On Rails 3,View,Rspec,我正在做一些关于在我们的网站上创建规范链接的测试,并且在RSpec中遇到了下面的Webrat问题 以下是测试: [...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,

我正在做一些关于在我们的网站上创建规范链接的测试,并且在RSpec中遇到了下面的Webrat问题

以下是测试:

[...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 ....]
Failure/Error:rendered.have_选择器('link',{:rel=>'canonical',:href=>post_路径(@post,:only_路径=>false)})
预期以下输出包含标记:
[…更多正确渲染的内容….]

如您所见,html和body标记之间没有呈现标记。但是,当我直接(使用我们的服务器)访问页面时,没有问题。这是配置问题吗?

这里的答案是“渲染”调用。我需要设置模板和布局,而不是仅仅说“渲染”。以下是有效的方法:

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

这里的答案是“渲染”调用。我需要设置模板和布局,而不是仅仅说“渲染”。以下是有效的方法:

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