我的rspec测试不会通过:Michael Hartl的rails教程

|| 我在第五章的末尾进行练习。我应该测试链接是否转到正确的页面。这是我的测试代码。
require \'spec_helper\'

describe \"LayoutLinks\" do

    it \"should have the right links on the layout\" do
        visit root_path
        click_link \"About\"
        response.should have_selector(\'title\', :content => \"About\")
        click_link \"Home\"
        response.should have_selector(\'title\', :content => \"Home\")
        click_link \"Help\"
        response.should have_selector(\'title\', :content => \"Help\")
        click_link \"Contact\"
        response.should have_selector(\'title\', :content => \"Contact\")
        click_link \"Sign up now!\"
        response.should have_selector(\'title\', :content => \"Sign up\")
        end
        end
除了最后的测试,一切都通过了。它说找不到文本为“立即注册!”的链接。我知道页面上确实有一个“立即注册!”链接。我以为它在源代码中的呈现方式可能有所不同,但是当我查看源代码时,它看起来很正常(即1)。据我了解,应该单击链接,然后测试标题是否与:content符号匹配。我误会了吗? 这是我得到的错误:
Failures:

  1) LayoutLinks should have the right links on the layout
     Failure/Error: click_link \"Sign up now!\"
     Webrat::NotFoundError:
       Could not find link with text or title or id \"Sign up now!\"
    
已邀请:
我相信问题在于,“并非立即注册!”链接实际上不在所有页面上,并且此测试实际上在页面上进行导航。 至少在我之前浏览过的本教程的版本中,该链接仅在主页上。 如果您在最后一个
click_link
之前添加一个
visit root_path
,它可能会起作用。 更好的测试是让该程序签入专门与主页相关的独立测试。     
另外,标题文字为“ 5”。大写\'U \'。 该行需要是:
response.should have_selector(\'title\', :content => \"Sign Up\")
如果在此页面之前访问的页面是
\"Home\"
,则不需要回答answer3ѭ的建议。     
测试不起作用的原因是因为您需要运行:
$ rake db:test:prepare  
至少,这就是为什么我的测试没有通过的原因。 我在这个论坛上找到了解决方案     

要回复问题请先登录注册