【发布时间】:2010-08-09 01:32:14
【问题描述】:
所以我正在使用Cucumber 进行 BDD,并有一个带有从数据库填充的复选框的表单。复选框的标签包含超链接。到目前为止,还不算太奇特(注意,这是HAML 而不是 Erb,但它应该对任何 Rails 人都足够可读):
I would like my donation to support:
%br
- for podcast in @podcasts
= check_box_tag "donation[podcast_ids][]", podcast.id, true
= donation.label "donation[podcast_ids][]", link_to(podcast.name, podcast.url), :value => podcast.id
%br
问题在于,在我的 Cucumber 功能中,我不知道如何找到该复选框来检查它。故事的相关部分是这样的:
Scenario: Happy path
Given I am on the home page
When I fill in "My email address" with "john@example.org"
# Skipped for brevity...
And I check the "Escape Pod" podcast
And I check the "PodCastle" podcast
And I press "I'm ready!"
Then I should see "Thank you!"
And there should be 2 podcast donation records
如果我使用的是纯 webrat_steps.rb 文件,我会收到以下错误:
Could not find field: "Escape Pod" (Webrat::NotFoundError)
我很确定这是因为link_to() 方法,我用它来使“Escape Pod”成为指向实际网站的超链接。但是我无法从我的 Cucumber 步骤轻松访问 link_to,而且我无法找出将 Webrat 指向右侧复选框的任何合理方法,除非在其中包含一大堆超链接代码我的步骤(这使它非常脆弱)。
此时我的 BDD 停滞不前。我不想仅仅因为它很难测试就删除链接。而且感觉它不应该很难测试。 Webrat 只是限制了我可以传递给 checks() 方法的内容。谁能为此提出一个优雅的答案?
【问题讨论】:
标签: ruby-on-rails cucumber webrat