我的模型的黄瓜(LoadError)

时间:2012-01-23 22:46:36

标签: ruby-on-rails-3 cucumber

我确信这是基本的,因为我是一个新的Rails用户,并且想要正确使用Cucumber。我花了整个周末阅读实用书,并有一个我想创建并使用它的小项目。我故意尽可能广泛地设置我的第一个功能,这样它就不会太脆弱,因为它太多地取决于它在轨道上的工作方式。我在github上使用DanielKehoe的启动器创建了一个新的rails应用程序。我想我让用户想通了。但是,当我尝试使用Cucumber来创建我的第一个参考单位表时,我会想到黄瓜会让我创建一个参考单位模型,但是我花了整个上午的时间试图让它使用书,Railscasts和stackoverflow将我推到了我现在的位置。我继续为参考单元生成了一个模型,控制器有一个新动作和一个空视图。但它现在无法弄清楚我有一个带有(LoadError)的Reference Unit模型。奇怪,因为它在应用程序中。

这是我目前的功能:

Feature: I want to have Reference Units that I can refer to so they can be used elsewhere. That way 
they can be updated in one place. I want to create and edit these Units.

Background:
Given I am logged in as the following user:
| name | "Testy McUserton" |
| password | "please" |
| email | "testy@userton.com" |

Scenario: Adding Reference Units
When I go to the new Reference Units page
And I fill in the following:
| commodity | "corn" |
| language | "en" |
| wholesale unit | "xton" |
| retail unit | "xliter" |
| receipt unit | "dollar" |
Then it should create a new Reference Unit

这是我的步骤定义:

Given /^I am logged in as the following user:$/ do |table|
  sign_up valid_user
end

When /^I go to the new Reference Units page$/ do 
  visit new_reference_unit_path
end

When /^I fill in the following:$/ do |table|
    @reference_unit = Reference_unit.create!(table.rows_hash)
end

Then /^it should create a new Reference Unit$/ do
  pending # express the regexp above with the code you wish you had
end

new_reference_unit_path在我的feature / support / paths.rb中:

when /the new Reference Units page/
  '/reference_units/new'

在3.1.3中运行以下内容为红色:

Scenario: Adding Reference Units              # features/user_can_create_units.feature:10
When I go to the new Reference Units page   # features/step_definitions/user_create_unit_reference.rb:6
  Expected /Users/sam/apps/keriakoo/app/models/reference_unit.rb to define Reference_unit (LoadError)
  ./app/controllers/reference_units_controller.rb:4:in `new'
  ./features/step_definitions/user_create_unit_reference.rb:7:in `/^I go to the new Reference Units page$/'
  features/user_can_create_units.feature:11:in `When I go to the new Reference Units page'

正如我上面提到的那样。 reference_unit.rb文件位于正确的位置。当然,我没有添加任何方法或属性,期待黄瓜在正确的时间引导我。我确定它很简单,但我尝试了各种单词和大写的组合来摆脱松散的东西,山姆

1 个答案:

答案 0 :(得分:0)

好吧,我想我找到了线索。四处搜寻,我在黄瓜上使用了--backtrace选项,它指向了一个关键词“const”的依赖。好的,它不喜欢文本中的内容。环顾两个单词模型的信息,我可以说我的模型是正确的:ReferenceUnit。但是查看我的错误输出,它正在寻找Reference_unit。因此,对于笑声,我将该步骤的正则表达式更改为“当/ /我转到新的参考单位页面$”时,错误就消失了。所以第一行的语法很重要,而不是我怀疑的'freestylin'。