【问题标题】:How do i use assert_select to check for the absence of certain content?如何使用 assert_select 检查某些内容是否缺失?
【发布时间】:2014-08-06 16:57:55
【问题描述】:

一个示例用例是确保响应 HTML 没有转义 HTML 字符,这可能暗示 html_safe 没有在需要的地方使用

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 assert functional-testing assertions


    【解决方案1】:

    这是一个帮助方法,您可以添加到 test_helper.rb 中的 ActionController::TestCase 类中

    def assert_no_escaped_html
      assert_select "body", { :text => /&lt;.*&gt;/, :count => 0 }, "This page must contain no HTML escaped '<', '>' characters\nContent - #{@response.body}"
    end
    

    在你的功能测试中调用这个断言

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-05
      • 2012-08-22
      • 2011-10-11
      • 2019-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多