Cucumber 和与选择列表的关联

发布于 2024-10-18 04:51:33 字数 810 浏览 3 评论 0原文

我正在使用 Cucumber 进行记录创建的集成测试。我的功能如下所示:

When I go to the create album page      
And I fill in the following:
| Album Title               | Great Album   |
| Record Label              | Decca         |
| Catalog Number            | 778-B127      |
| Number of Discs           | 2             |
| Release Year              | 2002          |
| Internal Catalog Number   | CD 1662       |
And I press "Add Album"     
Then I should see "Great Album was added to the library."

事情是,一个 Album belongs_to 一个 Composer。此关联是在新专辑页面上使用下拉列表创建/选择的,该列表填充了现有作曲家的记录。测试这种关联的最佳方法是什么?我更喜欢在我的 Cucumber 表中执行此操作,但这不可能吗?我是否需要使用工厂(或其他机制)来创建此 Composer,然后将类似内容添加

| Composer                 | Tallis, Thomas|

到我的表中?

I'm doing integration testing of record creation with Cucumber. My feature looks like this:

When I go to the create album page      
And I fill in the following:
| Album Title               | Great Album   |
| Record Label              | Decca         |
| Catalog Number            | 778-B127      |
| Number of Discs           | 2             |
| Release Year              | 2002          |
| Internal Catalog Number   | CD 1662       |
And I press "Add Album"     
Then I should see "Great Album was added to the library."

The thing is, an Album belongs_to a Composer. This association is created/selected on the new album page using a drop-down list that is populated with the records of existing Composers. What's the best way to test this association? I'd prefer to do it in my Cucumber table, but is that not possible? Do I need to use a factory (or other mechanism) to create this Composer and then add something like

| Composer                 | Tallis, Thomas|

to my table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初吻给了烟 2024-10-25 04:51:33

我认为您可以以类似的方式完成您想要的事情,

将这些步骤添加到您的场景

Given composers "Tallis, Thomas" exist
When I go to the create album page
...
And I select "Tallis" from "album_composers"

Given /^composers "([^\']*)" exist$/ do |composers|
  composers.split(", ").each do |composer|
    Composer.find_or_create_by_name(composer)
    # alternatively, using factory_girl 
    # Factory(:composer, :name => composer)
  end
end

i think you could accomplish what you want in a similar fashion

add these steps to your scenario

Given composers "Tallis, Thomas" exist
When I go to the create album page
...
And I select "Tallis" from "album_composers"

the step

Given /^composers "([^\']*)" exist$/ do |composers|
  composers.split(", ").each do |composer|
    Composer.find_or_create_by_name(composer)
    # alternatively, using factory_girl 
    # Factory(:composer, :name => composer)
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文