我正在关注 Michael Hartl 的 Ruby on rails 教程。
使用 rspec 重构一个简单的测试失败了,我将首先粘贴有效的内容,然后粘贴有效的内容....
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the h1 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Sample App | Home")
end
end
describe "Help page" do
it "should have the h1 'Help'" do
visit '/static_pages/help'
page.should have_selector('h1', :text => 'Help')
end
it "should have the title 'Help'" do
visit '/static_pages/help'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Sample App | Help")
end
end
end
现在我将粘贴 rspec 中失败的内容
require 'spec_helper'
describe "Static pages" do
let(:base_title) { "Ruby on Rails Tutorial Sample App |" }
describe "Home page" do
it "should have the h1 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
page.should have_selector('title', :text => "#{base_title} Home")
end
end
describe "Help page" do
it "should have the h1 'Help'" do
visit '/static_pages/help'
page.should have_selector('h1', :text => 'Help')
end
it "should have the title 'Help'" do
visit '/static_pages/help'
page.should have_selector('title', :text => "#{base_title} Help")
end
end
end
我也是新手,所以我想问一下可能需要更多信息......变化显然是
let(:base_title) { "Ruby on Rails Tutorial Sample App |" }
谢谢你的帮助 !
失败的错误是......
失败:
1)静态页面主页应该有标题'Home'失败/错误:page.should have_selector('title',:text =>“#base_title} Home”)预期的css“title”和文本“#base_title} Home”返回一些东西 # ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in '
2)静态页面帮助页面应该有标题'Help'失败/错误:page.should have_selector('title',:text =>“#{base_title}Help”)预期的css“title”和文本“Ruby on Rails Tutorial示例应用程序 | 帮助”返回一些东西 # ./spec/requests/static_pages_spec.rb:29:in `block (3 levels) in '