5

我被以下问题困住了,这是我第一次使用水豚,你知道我该如何解决这个问题,谢谢

我使用 rails 3.0.0 和以下 gem

gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'

我的 senario 中有以下内容

When I go to the new customer page
And I fill in "Email" with "john@example.com"

在我的 customer_steps.rb 我有

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
  fill_in arg1, :with => arg2
end

在我看来

- form_for @customer do |f|
  = f.label :email, 'Email'
  = f.text_field :email
  = f.submit

当我运行我的场景时,我收到此错误消息

 Scenario: Register new customer                  # features/manage_customers.feature:7
    When I go to the new customer page             # features/step_definitions/customer_steps.rb:1
    And I fill in "Email" with "john@example.com"  # features/step_definitions/customer_steps.rb:5
      cannot fill in, no text field, text area or password field with id, name, or label 'Email' found (Capybara::ElementNotFound)
      ./features/step_definitions/customer_steps.rb:6:in `/^I fill in "([^"]*)" with "([^"]*)"$/'
      features/manage_customers.feature:9:in `And I fill in "Email" with "john@example.com"'
4

2 回答 2

4

我发现我的错误了!!!

When I go to the new customer page

在这一步之前

When /^I go to (.+)$/ do |page_name|
  path_to page_name 
end

我忘记了参观...

When /^I go to (.+)$/ do |page_name|
  visit path_to(page_name) 
end
于 2010-09-05T17:08:10.260 回答
2

改用该字段的 id,应该是这样的

我用“john@example.com”填写“customer_email”

如果@customer 是对象客户模型

于 2010-09-04T22:35:17.207 回答