我有:
module A
H = { c: @user }
def b
H.fetch(:c).should_not be_nil
end
end
World(A)
@user
在Cucumber步骤中定义。当我调用它时,我收到一个错误,因为@user是nil。
注意:如果我将代码更改为@user.should_not be_nil
,我将不会获得例外。
如何让World中的模块内的Cucumber实例变量可用?
答案 0 :(得分:0)
这有用吗?
module A
H = { c: :@user }
def b
send(H.fetch(:c)).should_not be_nil
end
end
World(A)
答案 1 :(得分:0)
以下是Matt Wynne在Cucumber邮件列表中收到的回复:
此代码没有意义
H = { c: @user }
此行将在定义模块时运行。您要使用的@user实例变量尚不存在 - 它只存在于运行时。