未定义的方法“add”在通常有效的黄瓜步骤上
我定义了一个路径:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我只是太累了,无法阅读自己的错误消息。
Nevermind, I'm just too tired to read my own error message.