Ruby on rails rspec标题测试失败,我正在设置标题?
我的rspec标题测试失败,原因是:Ruby on rails rspec标题测试失败,我正在设置标题?,ruby-on-rails,rspec,Ruby On Rails,Rspec,我的rspec标题测试失败,原因是: 1) HomeController Get 'index should have the right title Failure/Error: response.should have_selector("title", expected following output to contain a <title>TitleTest</title> tag: <!DOCTYPE html PUBLIC
1) HomeController Get 'index should have the right title
Failure/Error: response.should have_selector("title",
expected following output to contain a <title>TitleTest</title> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
# ./spec/controllers/home_controller_spec.rb:13
1)HomeController Get“索引应具有正确的标题
失败/错误:response.should_选择器(“title”,
预期以下输出包含TitleTest标记:
#/规格/控制器/主控制器规格rb:13
我的家庭控制器有:
def索引()
@title=“TitleTest”
结束
我的视图(application.html.erb)具有:
运行rails server表明我的标题已设置,这里有什么问题?请确保在控制器规范中,将其设置为
render\u views
。否则,rspec将没有要查看的视图。只需在描述控制器块之后添加该代码
更新:您可以在右侧找到一个示例确保在控制器规范中,将其设置为
render\u views
。否则,rspec将无法查看视图。只需在描述控制器块之后添加该代码位即可
更新:您可以找到一个正确的示例肯定需要“呈现视图”。我也遇到了类似的情况,我的问题是在执行预期之前没有检索页面。换句话说,结构应该是:
describe...
it... # previous expectation
it...
get 'mypage'
response should...
我错误地认为我不需要获取“mypage”,并且我可以重用以前期望的响应“呈现视图”是绝对需要的。我也遇到了类似的情况,我的问题是在执行期望之前我没有检索页面。换句话说,结构应该是:
describe...
it... # previous expectation
it...
get 'mypage'
response should...
我错误地认为我不需要获取“mypage”,并且可以重用以前期望的响应