作者:昆哥2502852107 | 来源:互联网 | 2023-09-01 07:14
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.
我正在尝试为我正在研究的一个小Rails应用程序编写测试。 Users模型与其他用户具有has_many through关系(两种方式),并且用户与assignments具有has_many关系。在UI端,用户可以选择其他用户来附加新的分配。我想能够测试一下。现在的问题是,我无法弄清楚如何使用Capybara从我不知道文本的项目列表中进行选择。我写了一个rake任务来随机生成我的测试数据库,虽然我可以查看数据库并以这种方式编写我的测试,但它当然会打破第二次重置数据库。
I'm only testing that the number of assignments in the test database changes by 1. I'm using Rspec with Capybara.
我只测试测试数据库中的分配数量变化1.我正在使用Rspec和Capybara。
2 个解决方案