【问题标题】:rspec title test is failing, I am setting the title?rspec 标题测试失败,我正在设置标题?
【发布时间】:2010-12-02 03:35:33
【问题描述】:

我的 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 "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
     # ./spec/controllers/home_controller_spec.rb:13

我的家庭控制器有:

定义索引() @title = "标题测试" 结束

我的观点(application.html.erb)有:

<title><%= @title %></title> 

运行 rails 服务器显示我的标题确实设置好了,这里有什么问题?

【问题讨论】:

    标签: ruby-on-rails rspec


    【解决方案1】:

    确保在您的控制器规范中将其设置为 render_views。否则,rspec 将无法查看。只需在您的描述控制器块之后添加那段代码。

    更新:你可以在here找到一个例子

    【讨论】:

      【解决方案2】:

      'render_views' 是绝对需要的。我也遇到了类似的情况,我的问题是在执行期望之前我没有检索到页面。换句话说,结构应该是:

      describe... 
      
       it...  # previous expectation
      
       it...
         get 'mypage' 
         response should...
      

      我错误地假设我不需要获取 'mypage' 并且我可以重用之前期望的响应

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-11
        • 1970-01-01
        • 2023-03-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多