Sha256: 9fb2345d760c7f2b9cd06c6203c4b70aefd4cfd2874624ae29bb1b2b9615b609

Contents?: true

Size: 1.61 KB

Versions: 21

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'
require 'metaid'

describe String, "when extended with BER core extensions" do
  describe "<- #read_ber! (consuming read_ber method)" do
    context "when passed an ldap bind request and some extra data" do
      attr_reader :str, :result
      before(:each) do
        @str = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED" 
        @result = str.read_ber!(Net::LDAP::AsnSyntax)
      end
      
      it "should correctly parse the ber message" do
        result.should == [1, [3, "Administrator", "ad_is_bogus"]]
      end 
      it "should leave unconsumed part of message in place" do
        str.should == " UNCONSUMED"
      end

      context "if an exception occurs during #read_ber" do
        attr_reader :initial_value
        before(:each) do
          stub_exception_class = Class.new(StandardError)
          
          @initial_value = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus" 
          @str = initial_value.dup 

          # Defines a string
          io = StringIO.new(initial_value)
          io.meta_def :read_ber do |syntax|
            read
            raise stub_exception_class
          end
          flexmock(StringIO).should_receive(:new).and_return(io)
          
          begin
            str.read_ber!(Net::LDAP::AsnSyntax)            
          rescue stub_exception_class
            # EMPTY ON PURPOSE
          else
            raise "The stub code should raise an exception!"
          end
        end
        
        it "should not modify string" do
          str.should == initial_value
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 9 rubygems

Version Path
net-ldap-0.6.1 spec/unit/ber/core_ext/string_spec.rb
net-ldap-0.6.0 spec/unit/ber/core_ext/string_spec.rb
net-ldap-0.5.1 spec/unit/ber/core_ext/string_spec.rb
datacom-net-ldap-0.5.0.datacom spec/unit/ber/core_ext/string_spec.rb
socialcast-net-ldap-0.1.8 spec/unit/ber/core_ext/string_spec.rb
socialcast-net-ldap-0.1.7 spec/unit/ber/core_ext/string_spec.rb
adams-net-ldap-0.4.0 spec/unit/ber/core_ext/string_spec.rb
obis-net-ldap-0.4.0 spec/unit/ber/core_ext/string_spec.rb
net-ldap-1-0.4.0 spec/unit/ber/core_ext/string_spec.rb
socialcast-net-ldap-0.1.6 spec/unit/ber/core_ext/string_spec.rb
socialcast-net-ldap-0.1.5 spec/unit/ber/core_ext/string_spec.rb
net-ldap-0.3.1 spec/unit/ber/core_ext/string_spec.rb
net-ldap-0.3.0 spec/unit/ber/core_ext/string_spec.rb
prathe_net-ldap-0.2.20110317223538 spec/unit/ber/core_ext/string_spec.rb
prathe-net-ldap-0.2.20110317223538 spec/unit/ber/core_ext/string_spec.rb
net-ldap-0.2.2 spec/unit/ber/core_ext/string_spec.rb
net-ldap-0.2.1 spec/unit/ber/core_ext/string_spec.rb
net-ldap-0.2 spec/unit/ber/core_ext/string_spec.rb
scashin133-net-ldap-0.1.4 spec/unit/ber/core_ext/string_spec.rb
scashin133-net-ldap-0.1.3 spec/unit/ber/core_ext/string_spec.rb