2012-08-23 14 views
8

Wpadam tu w coś dziwnego. Mam "authentator", który polega na ND5 do mieszania pewnego łańcucha pasuje jako hasło. Problem podczas uruchamiania moich testów jest taka:Digest :: MD5 w Rubim 1.9.3

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' 

Więc w zasadzie on nie rozpoznaje MD5 jako część biblioteki Digest. Ten problem występuje, gdy uruchomione testy w IDE, a także w konsoli IRB:

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

Jednak, kiedy należy wykonać:

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

otrzymuję żadnych błędów, wysypisk lub wyjątki . Ruby po prostu to akceptuje. Czego mi brakuje, aby działać z MD5?

Odpowiedz

33

Digest :: MD5 nie jest metodą, ale modułem. Wypróbuj

Digest::MD5.digest("test") 
+0

dzięki pracował ...... jestem takim idiotą, że nie widząc to: S –

+1

mógłbyś podać link do dokumentacji metody, proszę? – Kostas

+18

Digest :: MD5.hexdigest jest również całkiem niezły – reconbot

0

Znalazłem to mylące, nie wygląda na to, że .digest jest poprawne. Nie mogę powiedzieć, że to źle ...

Komentarz @reconbot ma rację, IMO, ale widziałem komentarz dopiero po powrocie, aby poprawić tę kontrolę jakości, myślę, że komentarz nie jest wystarczająco widoczny.

http://ruby-doc.org/stdlib-2.4.0/libdoc/digest/rdoc/Digest/MD5.html

Poniżej znajduje się przykład użycia dla md5 hasing za korzystanie Gibbon, w MailChimp gem.

md5_hashed_email_address = Digest::MD5.hexdigest("[email protected]")