简体   繁体   English

如何为这种令人讨厌的表格编写测试?

[英]How can I write a test for this ajaxious form?

I have this form and in it I have this: 我有这个表格,里面有这个:

<%= f.select(:category_id, categories_for_select) %>
<%= f.select(:subcategory_id, options_for_select(["Choose category"])) %>

Then, when the user change the category the subcategories select box fill itself via ajax. 然后,当用户更改类别时,子类别选择框将通过ajax填充自身。

Both of the category and subcategory are mandatory for my model and included in the validations, so I can't save an instance without a subcategory. 类别和子类别都对我的模型是必需的,并且包含在验证中,因此如果没有子类别,我将无法保存实例。 Anyway, the subcategories are NOT available in the HTML code so Webrat don't see it. 无论如何,这些子类别在HTML代码中不可用,因此Webrat看不到它。

My question is: how can I write a functional test for this?. 我的问题是:如何为此编写功能测试? But also, how can I make this approach working without JavaScript? 但是,如果没有JavaScript,如何使这种方法有效呢?

We use Cucumber to test anything javascript. 我们使用Cucumber测试任何javascript。 Instead of WebRat, we use Capybara. 代替WebRat,我们使用Capybara。 For any of the Javascript-dependent tests, we use Selenium, although Culerity/Celerity looks cool. 对于任何依赖Javascript的测试,我们都使用Selenium,尽管Culerity / Celerity看起来很酷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM