mandrews
mandrews

Reputation: 65

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

I want to test for the presence for a specific embedded ruby ('will_paginate' in this case) tag in my html view:

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

I've tried any combination of:

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

Any ideas what trick I'm missing here? Cheers.

Upvotes: 3

Views: 424

Answers (1)

wasipeer
wasipeer

Reputation: 1035

You can use Rails assigns(...) helper as following.

assert_equal assigns(:microposts).length, 5

And if you want to assert UI Element you have to do like this.

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

Note:

Update last assert_select class structure according to your UI.

Upvotes: 3

Related Questions