diff --git a/lib/bcrypt.rb b/lib/bcrypt.rb index b07678c..12f50a5 100644 --- a/lib/bcrypt.rb +++ b/lib/bcrypt.rb @@ -11,11 +11,13 @@ # A Ruby library implementing OpenBSD's bcrypt()/crypt_blowfish algorithm for # hashing passwords. module BCrypt + + class Error < StandardError; end module Errors - class InvalidSalt < StandardError; end # The salt parameter provided to bcrypt() is invalid. - class InvalidHash < StandardError; end # The hash parameter provided to bcrypt() is invalid. - class InvalidCost < StandardError; end # The cost parameter provided to bcrypt() is invalid. - class InvalidSecret < StandardError; end # The secret parameter provided to bcrypt() is invalid. + class InvalidSalt < BCrypt::Error; end # The salt parameter provided to bcrypt() is invalid. + class InvalidHash < BCrypt::Error; end # The hash parameter provided to bcrypt() is invalid. + class InvalidCost < BCrypt::Error; end # The cost parameter provided to bcrypt() is invalid. + class InvalidSecret < BCrypt::Error; end # The secret parameter provided to bcrypt() is invalid. end # A Ruby wrapper for the bcrypt() C extension calls and the Java calls. diff --git a/spec/bcrypt/error_spec.rb b/spec/bcrypt/error_spec.rb new file mode 100644 index 0000000..d36d6bc --- /dev/null +++ b/spec/bcrypt/error_spec.rb @@ -0,0 +1,37 @@ +require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) + +describe "Errors" do + + shared_examples "descends from StandardError" do + it "can be rescued as a StandardError" do + described_class.should < StandardError + end + end + + shared_examples "descends from BCrypt::Error" do + it "can be rescued as a BCrypt::Error" do + described_class.should < BCrypt::Error + end + end + + describe BCrypt::Error do + include_examples "descends from StandardError" + end + + describe BCrypt::Errors::InvalidCost do + include_examples "descends from BCrypt::Error" + end + + describe BCrypt::Errors::InvalidHash do + include_examples "descends from BCrypt::Error" + end + + describe BCrypt::Errors::InvalidSalt do + include_examples "descends from BCrypt::Error" + end + + describe BCrypt::Errors::InvalidSecret do + include_examples "descends from BCrypt::Error" + end + +end