Rails Minitest:测试嵌入式 Ruby 标签存在 html.erb 视图

Rails Minitest: Testing for Embedded Ruby Tag Presence html.erb view

我想测试在我的 html 视图中是否存在特定的嵌入式 ruby(在本例中为 'will_paginate')标签:

<div >
  <% if @user.microposts.any? %>
   ...
    <%= will_paginate @microposts %>
  <% end %>
</div>

我试过以下任意组合:

assert_select "will_paginate"
assert_match "will_paginate", response.body

知道我在这里遗漏了什么技巧吗?干杯。

您可以使用 Rails assigns(...) 助手,如下所示。

assert_equal assigns(:microposts).length, 5

如果你想断言 UI 元素,你必须这样做。

assert_select 'div.panel-body div.pagination-main span', '1-5 of 5'

注:

Update last assert_select class structure according to your UI.