问题描述
这是我的目录结构:
/features/ninja.feature
/features/step_definitions/ninja_steps.rb
/src/ninja.rb
当我跑步时
cucumber
在我的项目的根目录中,我得到一个 uninitialized string constant Ninja (NameError)
错误.我已经确定这是由我的 ninja_steps.rb
文件中的这一行引起的:
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
在我的 ninja.rb
文件中:
class Ninja
def initialize (belt_level)
end
end
我是否需要在 ninja_steps.rb 文件的顶部添加某种 require
或什么?我似乎无法弄清楚如何做到这一点,以免它爆炸.
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.
推荐答案
您是否尝试在 ninja_steps 顶部添加包含?类似的东西
Did you try adding an include at the top of the ninja_steps? Something like
require File.expand_path(File.dirname(__FILE__) + "/../../src/ninja")
应该可以解决问题.否则,黄瓜不知道忍者是什么.:)
should do the trick. Otherwise, cucumber has no idea what a Ninja is. :)
这篇关于未初始化的常量(NameError)问题——如何包含一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!