我正在研究ruby.railstutorial.org/ruby-on-rails-tutorial-book.我使用rails 3.2.7,spork,rspec,capybara,launchy和一些警卫:)
我在第3章中有一个非常奇怪的问题:测试:
似乎测试不适用于<head>-Tag中的内容.如果我将<title>-tag放在<body>-tag而不是head-tag中,它可以正常工作.当我把<h1>-tags放在<title>里面 - <head>标签时,它也有效.这很奇怪,不是吗?
请帮帮我搞清楚.
示例来自:ruby.railstutorial.org/chapters/static-pages#code:title_test:
it "should have the right title" do
visit '/static_pages/home'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Sample App | Home")
end
Run Code Online (Sandbox Code Playgroud)
错误消息是:
失败:
1)静态页面主页应该有标题'Home'失败/错误:page.should have_selector('title',:text =>'| Home')Capybara :: ExpectationNotMet:期望找到带有文本的css"title" |主页"但没有比赛.还找到"",它匹配选择器但不是所有过滤器.#./spec/requests/static_pages_spec.rb:15:在'块(3级)中'
那个工作:
it "should have the h1 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
Run Code Online (Sandbox Code Playgroud)
呈现的HTML文件:
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | …Run Code Online (Sandbox Code Playgroud)