黄瓜特征选择失败

时间:2012-06-13 21:20:21

标签: ruby-on-rails cucumber capybara

无法弄清楚为什么这个功能无法通过...我知道它是通过手动测试工作的,但我不断收到此错误

cannot select option, no option with text 'Don Moen' in select box 'audio_file[artist_id]'
(Capybara::ElementNotFound)
(eval):2:in `select'
./features/step_definitions/web_steps.rb:34:in `/^I select "(.*?)" from "(.*?)"$/'
features/adding_audio.feature:19:in `When I select "Don Moen" from "audio_file[artist_id]"'

场景失败:

Background:
    Given I am on the home page
    And I have an admin account
    And I submit valid login information
    And I am in the admin panel
    And I follow "New Upload"

Scenario: Adding Audio with Existing Artist
    Given the following Artists exist
        |   name     |
        |   Don Moen |
    When I fill in "Title" with "Song Name"
    When I select "Don Moen" from "audio_file[artist_id]"
    And I press "Upload"
    Then I should not see an error message

问题步骤定义:

Given /^the following Artists exist$/ do |table|
  table.hashes.each do |attributes|
    Artist.create :name => attributes[:name]
  end
end

When /^I select "(.*?)" from "(.*?)"$/ do |option, field|
  page.select option, :from => field
end

我知道问题与未保存在数据库中的模型有关,因为如果我在测试控制台中手动添加该艺术家,则该功能会通过。

也许我搞砸了一些db配置?

1 个答案:

答案 0 :(得分:2)

我无法确定您实际访问该页面的位置,但我怀疑您在创建艺术家记录之前就已经开始了,因此下拉列表将为空。

相关问题