- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
如果您认为这是 2 年前提出的重复问题,我首先表示歉意。但我尝试了来自 stackoverflow 的各种答案或在 stackoverflow 之外用谷歌搜索,但它对我不起作用。
我的问题与现有问题几乎相同:未初始化常量 (NameError) 问题 - 如何包含类? Uninitialized constant (NameError) problem - how to include a class?
我的目录结构是:
myacc/features/account_bill.feature
myacc/features/step_definitions/account_bill_steps.rb
myacc/features/support/env.rb
myacc/lib/domain_layer.rb
在 env.rb 中:我放入了各种解决方案
require File.join(File.dirname(__FILE__),'..', '..', 'lib', 'domain_layer')
require File.expand_path(File.dirname(__FILE__) + "/../../lib/domain_layer")
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
$: << File.dirname(__FILE__)+'/../../lib/'
require 'domain_layer'
在我的 domain_layer.rb 中,我写道:
module Domain_Layer
class Account
attr_accessor :accountid, :service_address, :full_name, :telephone, :email
def initialize(accountid)
@accountid = accountid
end
end #class
class MyAccount_Web < Account
def account_number(id)
return @accountid = id
end
end #class
end #module
在步骤定义文件中,我写道:
Given(/^the account (\d+) has one to five previous bills$/) do |accountid|
@web_account = MyAccount_Web.new(accountid)
end
当我在项目“myacc”的根目录中运行命令行时:
cucumber -verbose
我失败了:
C:\myacc01>cucumber -verbose
Code:
* features/support/env.rb
* features/step_definitions/account_bill_steps.rb
Features:
* features/account_bill.feature
* features/account_bill_1.feature
Parsing feature files took 0m0.027s
...
Given the account 03147102942 has one to five previous bills
uninitialized constant MyAccount_Web (NameError)
从 Cucumber 的输出中,我可以看到 Cucumber 只是没有遍历 env.rb 中声明的文件夹,忽略了 lib 目录中的所有 .rb 文件,忽略了 lib 目录中所需的 domain_layer.rb。
我试图将所有 .rb 文件复制到 step_definitions 文件夹中,但仍然不起作用:
myacc/features/account_bill.feature
myacc/features/step_definitions/account_bill_steps.rb
myacc/features/step_definitions/domain_layer.rb
myacc/features/support/env.rb
myacc/lib/domain_layer.rb
结果:
C:\myacc01>cucumber -verbose
Code:
* features/support/env.rb
* features/step_definitions/account_bill_steps.rb
* features/step_definitions/customer_account_bill.rb
* features/step_definitions/domain_layer.rb
* features/step_definitions/web_service_layer.rb
Features:
* features/account_bill.feature
* features/account_bill_1.feature
Parsing feature files took 0m0.028s
...
Scenario: The account has one to five previous months bills
Given the account 03147102942 has one to five previous bills
uninitialized constant MyAccount_Web (NameError)
我的环境是ruby 1.8.7,cucumber 1.2.1。我假设我对网上的所有查询结果都做了我应该做的,是这个版本/环境问题,还是我的代码有误?
谢谢
最佳答案
如果您的类是在模块中定义的,您必须像这样访问它:
Domain_Layer::MyAccount_Web
同时删除类和模块名称中的下划线(这是命名约定)。
之后,清理你的env.rb
。简单的 require "domain_layer"
应该足够了,因为 lib 文件夹会自动添加到加载路径。
关于ruby - cucumber 中未初始化的常量 (NameError) - 如何将类包含到 _steps.rb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20057863/
下面是activeresource.rb的全部内容: require 'active_resource' 谁能解释一下这其中的逻辑? 为什么不简单地让 activeresource.rb 包含 act
Neo4j.rb 中是否有针对 Rails 6 的开发?在一个新的 Rails 6(rc1) 项目中,如果我创建几个脚手架然后运行“rake neo4j:migrate:all”,我会收到一个错误,当
对此很陌生,所以我一直在尝试解决这个问题,但无法找到答案。 gem update --system 安装 rb-appscript 时出现以下错误。 gem install rb-appscript
我正在为涉及选中/取消选中框的场景编写步骤定义。在步骤定义中,我尝试使用 web_steps.rb 中的现有步骤。但是我收到错误:未定义的步骤:“我检查'评级'”。我必须做些什么才能让我的 myfea
为什么 Controller 命名为“users_controller.rb”而模型不命名为“user_model.rb”? 为什么有“application_controller.rb”但在view
我对 Ruby on Rails 完全陌生,正在运行以下命令$rails生成设备用户 我期望生成文件 _devise_create_users.rb 。但是它会生成文件 _add_devise_to_
我的 Rails 应用程序(在 Heroku 上运行)有一个暂存和生产环境。目前,我必须在每个文件中分别定义 staging.rb 和 production.rb 中的很多内容,例如: # Cod
我是 Rails 新手,并且对 ASP.net 有很好的了解。在 ASP.net Web 应用程序中,我有一个 web.config 来完成所有设置,但在 Rails 中,有几个配置文件,我现在想知道
预先感谢您的帮助。 我正在尝试在 env.rb 中创建变量 File_path =("#{File.dirname(__FILE__)}/../../features/TestData/Testdat
按照这里的例子: http://rspec.info 但是它失败了: kernel_require.rb:45:in `require': cannot load such file -- bowli
我在使用 Ruby 时遇到了一个我无法解释的奇怪问题。我有以下脚本,它抓取剪贴板中当前的任何代码,通过语法高亮器运行它,然后将新版本放回剪贴板: #!/usr/bin/ruby1.9.1 requir
假设我想通过表单将此代码嵌入到单独的 ruby.rb 文件中: print "Hello, Please enter a value:" var = gets.to_i if var == 1
我正在从“MongoDB in Action”一书中学习 Mongodb 和 ruby 我已经安装好 Mongodb 并设法在其上执行了许多命令。 我可能没有正确安装 ruby。 我正在使用 Ub
更多新手问题。 我知道,如果我在我的应用程序帮助程序中定义了一个方法,那么整个应用程序代码都可以使用它。 在我的应用程序助手中,我有: def primary_user_is_admin if c
尝试将此代码块授予 capistrano 的版本 3 但无济于事。一切都变了。任何人都可以帮助我在正确的轨道上进行转换吗? 旧版本 2 deploy.rb: #require 'new_relic/r
我正在第二次学习 Rails 教程。当我输入这个 rails generate integration_test static_pages 我得到 spec/rails_helper.rb 和 spe
请问这个env.rb错误是什么意思? root# rake db:migrate WARNING: Cucumber-rails required outside of env.rb. The re
我已经看到这个问题出现在许多不同的情况下,并希望获得在 StackOverflow 上修复/调试它的最佳实践。 今天早上我想到了一个现实世界的例子: expected announcement.rb
这是我在 StackOverflow 上的第一个问题,请耐心等待...... 当我在Listing 8.6中使用authentication_pages_spec.rb时我的测试通过了。然后我在'sp
有谁知道在 JRuby 中是如何处理 tempfile.rb 的。它在 Ruby 中,但不在 JRuby 中。 有人有任何想法吗? 干杯 埃夫 最佳答案 您仍然可以“要求'tempfile'”并且它会
我是一名优秀的程序员,十分优秀!