未初始化常量(NameError)问题 - 如何包含类?
这是我的目录结构:
/features/ninja.feature
/features/step_definitions/ninja_steps.rb
/src/ninja.rb
当我在项目的根目录中运行时
cucumber
,我收到 uninitialized stringconstant Ninja (NameError)
错误。我确定这是由我的 ninja_steps.rb
文件中的这一行引起的:
@ninja = Ninja.new :belt_level => belt_level
在我的 ninja.rb
文件中:
class Ninja
def initialize (belt_level)
end
end
我需要添加某种 require< /code> 在我的 ninja_steps.rb 文件的顶部,或者什么?我似乎不知道如何做到这一点,以免它爆炸。
Here is my directory structure:
/features/ninja.feature
/features/step_definitions/ninja_steps.rb
/src/ninja.rb
When I run
cucumber
in the root of my project, I get an uninitialized string constant Ninja (NameError)
error. I've determined it's caused by this line in my ninja_steps.rb
file:
@ninja = Ninja.new :belt_level => belt_level
In my ninja.rb
file:
class Ninja
def initialize (belt_level)
end
end
Do I need to add some sort of require
at the top of my ninja_steps.rb file, or what? I can't seem to figure out how to do that so that it doesn't bomb out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试在 ninja_steps 的顶部添加包含内容?像这样的东西
应该可以解决问题。不然黄瓜根本不知道什么是忍者。 :)
Did you try adding an include at the top of the ninja_steps? Something like
should do the trick. Otherwise, cucumber has no idea what a Ninja is. :)
要以与 Bill Turner 建议略有不同的方式加载所有这些文件,请从 cucumber/aruba 等项目中获取提示:
https://github.com/cucumber/aruba/blob/master/features/support/env.rb
To load all those files in a slightly different way than Bill Turner suggests, taking a hint from projects like cucumber/aruba:
https://github.com/cucumber/aruba/blob/master/features/support/env.rb