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]]
出於某種原因,哈希沒有保存......是否有一些解決方法可以使它與紅寶石一起工作?
謝謝。