Sha256: 2e3e9915edccac314738e18e221fc0ff7610f00566d9cd1e9665791519cb0bc4

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

# encoding: UTF-8
require "spec_helper"
require 'tempfile'

describe File do
  before :all do
    BEncodr.include!
  end

  let(:file)   { Tempfile.new('test.bencodr') }
  let(:object) { "string" }

  describe ".bencode" do
    it "should encode object to file" do
      File.bencode(file.path, object)
      file.rewind
      file.read.should == "6:string"
    end
  end

  describe "#bencode" do
    it "should encode object to file" do
      file.bencode(object)
      file.rewind
      file.read.should == "6:string"
    end
  end

  context "decode" do
    let(:sample_path) { 'spec/samples/bencodr.torrent' }

    before do
      file.bencode(object)
      file.rewind
    end

    describe ".bdecode" do
      it "should decode object from file" do
        File.bdecode(file.path).should == object
      end

      it "should decode sample file without error" do
        expect{ File.bdecode(sample_path) }.to_not raise_error
      end
    end

    describe "#bdecode" do
      it "should decode object from file" do
        file.bdecode.should == object
      end

      it "should decode sample file without error" do
        f = File.open(sample_path, 'rb')
        expect{ f.bdecode }.to_not raise_error
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bencodr-3.0.2 spec/bencodr/io_spec.rb
bencodr-3.0.1 spec/bencodr/io_spec.rb