I'm trying to write a test for a little Rails app I'm working on. The Users model has a has_many through relationship (both ways) with other users and users have a has_many relationship with assignments. On the UI end of things, users can choose another user to attach new assignments to. I'd like to be able to test this. The problem right now, is that I can't figure out how to use Capybara to select from a list of items that I don't know the text to. I wrote a rake task to generate my test database randomly, and while I could look in the database and write my test that way, it would of course break the second I reset the database.
I'm only testing that the number of assignments in the test database changes by 1. I'm using Rspec with Capybara.
Say the <select>
element has id "foo". Then the following should work.
option = first('#foo option').text
select option, from: 'foo'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With