测试RSpec中模块内部的模块
我将此模块放在另一个模块中:测试RSpec中模块内部的模块,rspec,Rspec,我将此模块放在另一个模块中: module ParentModule module ChildModule end end 我希望这能奏效: describe ParentModule do describe ChildModule do it 'does something without crashing' do (1 + 1).should_be 2 end end end 我得到一个错误 stack_overflow_q.rb:7:in `
module ParentModule
module ChildModule
end
end
我希望这能奏效:
describe ParentModule do
describe ChildModule do
it 'does something without crashing' do
(1 + 1).should_be 2
end
end
end
我得到一个错误
stack_overflow_q.rb:7:in `block in <top (required)>': uninitialized constant ChildModule (NameError)
stack\u overflow\u q.rb:7:in'block in':未初始化的常量ChildModule(NameError)
RSpec的descriple
方法未进入其参数的范围ChildModule
仅在ParentModule
的范围内定义,因此当您在内部description
中引用它时,它是未定义的
您可以使用
ParentModule::ChildModule来代替。出于某种原因,我想在发布此问题之前我已经尝试过了,但我没有,这很有效,谢谢!