Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何编写测试来测试hey定义如下的函数?模块CONSTANT加载到spec_helper中,其变量被冻结且无法更改。
hey
CONSTANT
spec_helper
module CONSTANT X=1 Y=2 self.freeze end def hey if CONSTANT::X == 1 puts "OKOK" else puts "NOT OK" end end
如何编写测试来测试 else 子句?
使用const_set类方法。
const_set
编辑:我刚刚注意到这个freeze命令。我已经更新了我的示例。
freeze
例子:
CONSTANT = CONSTANT.dup CONSTANT.const_set("X",0) # this will create a warning message when it sets the value puts CONSTANT::X # returns 0