Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test (Minitest) that a (Rails) view contains a <td> element with a certain text?

When I simply use

assert_select td, "test"

it seems that it expects the first of the found td-elements to have the value test.

So I tried to first select all of them in an array, and then assume that the array contains the expected value:

assert_select 'td' do |elements|
  assert elements.include?("test")
end

But this also doesn't work for me, as it is always green. I am not really sure which parts of Rails and Ruby are available in the test so this last idea was just a shot in the dark.

like image 653
Flip Avatar asked Dec 21 '25 13:12

Flip


1 Answers

Try this

assert_select 'td', /test/

it seems your td in not contains test only. // will work because it will match rather then comparing exact values.

like image 61
wasipeer Avatar answered Dec 24 '25 01:12

wasipeer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!