【问题标题】:cucumber step definition not finding class黄瓜步骤定义找不到类
【发布时间】:2012-03-30 18:00:43
【问题描述】:

我有一个黄瓜步骤定义,它没有在对象上拾取。

错误是:

   | 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

【问题讨论】:

  • 请发布And that release has a feature:的步骤定义
  • 我已经完成了,如果您还需要什么,请告诉我。

标签: ruby-on-rails cucumber


【解决方案1】:

你在哪里定义@feature?

错误信息显示该步骤正在调用@feature.issues,但@feature 为nil,这意味着无法获取问题。

【讨论】:

  • 我需要在工厂文件中定义它吗?
  • 不,你只需要正确初始化它。或者:如果你不先给它赋值,为什么你期望@something 与 nil 不同?
  • 你不需要在工厂文件中定义它(虽然这是一个很好的地方,如果你知道如何使用工厂女孩或类似的东西)。看起来您希望该版本自动创建其功能,而这些功能又会创建它们的问题。这不起作用 - 你需要创建功能(或使用工厂)。
  • 所以你说我需要在我的问题步骤定义中声明@release 对象?而不仅仅是功能和问题?
  • 我如何定义@feature 对象?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-10
  • 1970-01-01
  • 1970-01-01
  • 2020-07-12
  • 1970-01-01
相关资源
最近更新 更多