未定义的方法“add”在通常有效的黄瓜步骤上

发布于 2024-08-24 15:56:19 字数 1399 浏览 4 评论 0原文

我定义了一个路径:

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'

这很奇怪......为什么在第一种情况下会很好,而在第二种情况下则不然,唯一的区别是在数据库中创建记录的一堆步骤?

[编辑]

这是向数据库添加内容的步骤:

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

I have a path defined:

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

I have scenario that is passing:

  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."

And I have a scenario that is failing:

  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

The step that fails in the second one is "And I am on the admin home page" which passes just fine in the first scenario.

Here's the error I get:

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'

This is very odd... why would it be fine in the first case, and not in the second where the only difference are a bunch of steps that create records in the db?

[edit]

Here's the add stuff to database step:

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

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

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

发布评论

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

评论(1

挥剑断情 2024-08-31 15:56:19

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

Nevermind, I'm just too tired to read my own error message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文