我在输出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更新),我该怎么断言呢。
答案 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