Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Digest::MD5 in Ruby 1.9.3

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?

like image 270
codingbunny Avatar asked Aug 23 '12 10:08

codingbunny


1 Answers

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

Digest::MD5.digest("test")
like image 85
chifung7 Avatar answered Oct 21 '22 01:10

chifung7