Digest::MD5 in Ruby 1.9.3

codingbunny picture codingbunny · Aug 23, 2012 · Viewed 19.6k times · Source

I'm running into something weird here. I have an "authenticator" that relies on ND5 to hash a certain string we match as password. The problem when I run my tests is this:

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'

So basically he does not recognize the MD5 as part of the Digest library. This problem occurs when running the tests in the IDE, as well as in the IRB console:

1.9.3-p125 :001 > require "digest/md5" and Digest::MD5("test")
NoMethodError: undefined method `MD5' for Digest:Module

However, when I run the following:

[root@DCUDEV01 /home/morn/rubycas/current]# ruby
require "digest/md5" and Digest::MD5("test")

I receive no errors, dumps or exceptions. Ruby just accepts it. What am I missing in order to get this MD5 stuff working?

Answer

chifung7 picture chifung7 · Aug 23, 2012

Digest::MD5 is not a method but a module. Try

Digest::MD5.digest("test")