未定义的方法`添加'通常有效的黄瓜步骤

时间:2010-03-12 00:49:27

标签: ruby-on-rails cucumber

我定义了一条路径:

when /the admin home\s?page/
  "/admin/"

我的情景正在传递:

  Scenario: Let admins see the admin homepage
    Given "pojo" is logged in
    And "pojo" is an "admin"
    And I am on the admin home page
    Then I should see "Hi there."

我有一个失败的场景:

  Scenario: Review flagged photo
    Given "pojo" is logged in
    And "pojo" is an "admin"
  ...bunch of steps that create stuff in the database...
    And I am on the admin home page
    Then ... the rest of the steps

第二个失败的步骤是“我在管理主页上”,它在第一个场景中正常通过。

这是我得到的错误:

And I am on the admin home page                 # features/step_definitions/web_steps.rb:18
  undefined method `add' for {}:Hash (NoMethodError)
  ./app/controllers/admin_controller.rb:13:in `index'
  ./app/controllers/admin_controller.rb:11:in `each'
  ./app/controllers/admin_controller.rb:11:in `index'
  /usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
  ./features/step_definitions/web_steps.rb:19:in `/^(?:|I )am on (.+)$/'
  features/admin.feature:52:in `And I am on the admin home page'

这很奇怪......为什么在第一种情况下会好起来,而在第二种情况下,唯一不同的是在db中创建记录的一堆步骤?

[编辑]

以下是数据库步骤的添加内容:

Given /^there is a "([^\"]*)" with the following:$/ do |model, table|
  model.constantize.create!(table.rows_hash)
end

1 个答案:

答案 0 :(得分:0)

没关系,我太累了,无法阅读我自己的错误信息。