Sha256: 094cc1c59ddd27803ac58c0b593147bbc48e2b53a8457cf452af3344c3665c5d

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

# encoding: UTF-8

require "spec"
require "spec_helper"

describe String do
  describe "#bencodr" do
    it "should encode a string" do
      "string".bencode.should == "6:string"
    end

    it "should encode a zero length string" do
      "".bencode.should == "0:"
    end
  end
end

describe Symbol do
  describe "#bencodr" do
    it "should encode a symbol" do
      :symbol.bencode.should == "6:symbol"
    end
  end
end

describe URI::Generic do
  describe "#bencodr" do
    it "should encode a http uri" do
      uri = URI.parse("http://github.com/blatyo/bencodr")
      uri.bencode.should == "32:http://github.com/blatyo/bencodr"
    end

    it "should encode a https uri" do
      uri = URI.parse("https://github.com/blatyo/bencodr")
      uri.bencode.should == "33:https://github.com/blatyo/bencodr"
    end

    it "should encode a ftp uri" do
      uri = URI.parse("ftp://github.com/blatyo/bencodr")
      uri.bencode.should == "31:ftp://github.com/blatyo/bencodr"
    end

    it "should encode a ldap uri" do
      uri = URI.parse("ldap://github.com/blatyo/bencodr")
      uri.bencode.should == "32:ldap://github.com/blatyo/bencodr"
    end

    it "should encode a mailto uri" do
      uri = URI.parse("mailto:sudo@sudoers.su")
      uri.bencode.should == "22:mailto:sudo@sudoers.su"
    end
  end
end

describe BEncodr::String do
  describe "#register" do
    context "once an object has been registered as a BEncode string" do
      before :all do
        BEncodr::String.register Range
      end

      context "an instance of that object" do
        it "should respond to bencodr" do
          (1..2).should respond_to :bencode
        end

        it "should encode to a bencoded string" do
          (1..2).bencode.should == "4:1..2"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bencodr-1.2.0 spec/bencodr/string_spec.rb
bencodr-1.1.0 spec/bencodr/string_spec.rb
bencodr-1.0.1 spec/bencodr/string_spec.rb