我在这里遇到了一些奇怪的事情。我有一个“身份验证器”,它依赖 ND5 来散列我们匹配为密码的某个字符串。我运行测试时的问题是:
NoMethodError: undefined method `md5' for #<CASServer::Authenticators::Billing:0x007fd8e6c906a0>
./models/authenticators/billing.rb:63:in `validate'
./routes/login.rb:166:in `block (2 levels) in <class:Server>'
./routes/login.rb:158:in `each'
./routes/login.rb:158:in `block in <class:Server>'
(eval):2:in `click_button'
./features/step_definitions/when_steps.rb:32:in `/^I enter "(.*)" as username and the generated username password and log in$/'
./features/rubycas.login.feature:14:in `When I enter "username" as username and the generated username password and log in'
所以基本上他不承认 MD5 是 Digest 库的一部分。在 IDE 以及 IRB 控制台中运行测试时会出现此问题:
1.9.3-p125 :001 > require "digest/md5" and Digest::MD5("test")
NoMethodError: undefined method `MD5' for Digest:Module
但是,当我运行以下命令时:
[root@DCUDEV01 /home/morn/rubycas/current]# ruby
require "digest/md5" and Digest::MD5("test")
我没有收到任何错误、转储或异常。Ruby 只是接受它。为了让这些 MD5 工作正常,我缺少什么?