如何在div中与其他childern断言直接文本

时间:2015-09-14 13:13:33

标签: ruby-on-rails ruby-on-rails-4 assert minitest assertions

我在输出HTML中有以下div:

 <div class="panel-body">
     <h5 class="panel-body-heading">Comments</h5>
     Job updated.
 </div>

我有测试代码断言评论标题如下:

assert_select 'div.panel-body'  do
    assert_select 'h5.panel-body-heading' , /#{I18n.t('comments')}/
end

我想验证div是否有文本(Job更新),我该怎么断言呢。

1 个答案:

答案 0 :(得分:1)

您可以使用regexp:

assert_select 'div.panel-body', /Job updated./  do
    assert_select 'h5.panel-body-heading' , /#{I18n.t('comments')}/
end

或者文本是否在某个变量中:

assert_select 'div.panel-body', /#{str_variable}/  do
    assert_select 'h5.panel-body-heading' , /#{I18n.t('comments')}/
end

来源:Rails API guide