2
我试图在我的黄瓜测试中嘲笑OpenID处理。为了这个目的,我用下面的方法:如何将散列传递给Ruby 1.8.7的class_eval'ed方法?
def set_result_of_openid_authentication(result_type, profile_data = nil)
ActionController::Base.class_eval "
def begin_open_id_authentication(identity_url, options = {})
yield [OpenIdAuthentication::Result.new('#{result_type}'.to_sym), identity_url, #{profile_data}]
end
"
end
# example usage
set_result_of_openid_authentication :successful, 'email' => '[email protected]'
这正常使用Ruby 1.9.2,但使用Ruby 1.8.7,我得到以下编译错误:
(eval):5:in `set_result_of_openid_authentication': compile error
(eval):3: syntax error, unexpected tIVAR, expecting kDO or '{' or '('
...identity_url, [email protected]]
出于某种原因,哈希没有保存......是否有一些解决方法可以使它与红宝石一起工作?
谢谢。