Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select any item from select using Capybara

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.

like image 466
afkbowflexin Avatar asked May 27 '13 13:05

afkbowflexin


1 Answers

Say the <select> element has id "foo". Then the following should work.

option = first('#foo option').text
select option, from: 'foo'
like image 99
gregates Avatar answered Sep 17 '22 18:09

gregates