ruby-on-railstestingbutton-to

Rails: Can I test for the presence of a button_to?


My site had dozens of instances of "link_to". I decided to change most of them to "button_to" for better appearance. The lines of my test that used to check for the presence of those links are no good anymore.

assert_select "a", :href => user_path(@seminar.teacher), text: "Your Teacher Profile", count: 2

The test doesn't work correctly with

assert_select "button", etc...

Is there a way to adjust the test to find the button_to instances? From my initial searches, it seems like there isn't.

I'm also considering simply cutting those lines from the tests, since I've read in another article that simply testing for the presence of display items isn't a very useful way to use rails tests.

Thanks in advance for any insight!


Solution

  • I would remove those tests that just test for the presence of a link. It would be better to write tests that click those buttons and test what happens after the button is clicked. Users care more about what happens when a button is clicked than the presence of a button on a page.