我有一个黄瓜步骤定义没有拾取对象。
错误是:
| title | description |
| First Issue | This is a first issue. |
undefined method `issues' for nil:NilClass (NoMethodError)
./features/step_definitions/issue_steps.rb:3:in `block (2 levels) in <top (required)>'
特点:
Background:
Given there is a release called "First Release"
And that release has a feature:
| title | description |
| Make it shiny! | Gradients! Starbursts! Oh my! |
And that feature has a issue:
| title | description |
| First Issue | This is a first issue. |
And I am on the homepage
路线:
resources :releases do
resources :features
end
resources :features do
resources :issues
end
步骤定义:
Given /^that feature has a issue:$/ do |table|
table.hashes.each do |attributes|
@feature.issues.create!(attributes)
end
end
步骤定义:功能
Given /^that release has a feature:$/ do |table|
table.hashes.each do |attributes|
@release.features.create!(attributes)
end
end
答案 0 :(得分:1)
你在哪里定义@feature?
错误消息显示该步骤正在调用@ feature.issues,但@feature为nil,这意味着无法解决问题。