Created
March 14, 2010 06:46
-
-
Save jjulian/331808 to your computer and use it in GitHub Desktop.
A spec for the base58.rb code at http://carsonified.com/blog/dev/conversational-and-short-urls-on-rails/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Base58 do | |
it "should handle creating encoded strings over 2 characters long" do | |
(1..100000).each do |i| | |
i.should encode_and_decode_to(i) | |
end | |
end | |
end | |
class EncodeDecodeCorrectly | |
def initialize(i) | |
@encoded = Base58.encode(i) | |
end | |
def matches?(target) | |
@target = target | |
# puts @encoded | |
return Base58.decode(@encoded) == target | |
end | |
def failure_message | |
"expected #{@target} to encode and decode correctly: encoded is #{@encoded}" | |
end | |
def negative_failure_message | |
"expected #{@target} to not encode and decode correctly: encoded is #{@encoded}" | |
end | |
end | |
def encode_and_decode_to(i) | |
EncodeDecodeCorrectly.new(i) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment