|
1 | | -require 'spec_helper' |
2 | | -require 'metaid' |
| 1 | +require 'common' |
3 | 2 |
|
4 | | -describe String, "when extended with BER core extensions" do |
5 | | - describe "<- #read_ber! (consuming read_ber method)" do |
6 | | - context "when passed an ldap bind request and some extra data" do |
7 | | - attr_reader :str, :result |
8 | | - before(:each) do |
9 | | - @str = raw_string("0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED") |
10 | | - @result = str.read_ber!(Net::LDAP::AsnSyntax) |
11 | | - end |
12 | | - |
13 | | - it "should correctly parse the ber message" do |
14 | | - result.should == [1, [3, "Administrator", "ad_is_bogus"]] |
15 | | - end |
16 | | - it "should leave unconsumed part of message in place" do |
17 | | - str.should == " UNCONSUMED" |
18 | | - end |
19 | | - |
20 | | - context "if an exception occurs during #read_ber" do |
21 | | - attr_reader :initial_value |
22 | | - before(:each) do |
23 | | - stub_exception_class = Class.new(StandardError) |
| 3 | +class TestBERStringExtension < Test::Unit::TestCase |
| 4 | + def setup |
| 5 | + @bind_request = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED".b |
| 6 | + @result = @bind_request.read_ber!(Net::LDAP::AsnSyntax) |
| 7 | + end |
24 | 8 |
|
25 | | - @initial_value = raw_string("0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus") |
26 | | - @str = initial_value.dup |
| 9 | + def test_parse_ber |
| 10 | + assert_equal [1, [3, "Administrator", "ad_is_bogus"]], @result |
| 11 | + end |
27 | 12 |
|
28 | | - # Defines a string |
29 | | - io = StringIO.new(initial_value) |
30 | | - io.meta_def :read_ber do |syntax| |
31 | | - read |
32 | | - raise stub_exception_class |
33 | | - end |
34 | | - flexmock(StringIO).should_receive(:new).and_return(io) |
| 13 | + def test_unconsumed_message |
| 14 | + assert_equal " UNCONSUMED", @bind_request |
| 15 | + end |
35 | 16 |
|
36 | | - begin |
37 | | - str.read_ber!(Net::LDAP::AsnSyntax) |
38 | | - rescue stub_exception_class |
39 | | - # EMPTY ON PURPOSE |
40 | | - else |
41 | | - raise "The stub code should raise an exception!" |
42 | | - end |
43 | | - end |
| 17 | + def test_exception_does_not_modify_string |
| 18 | + original = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus".b |
| 19 | + duplicate = original.dup |
| 20 | + flexmock(StringIO).any_instance.should_receive(:read_ber).and_raise(Net::BER::BerError) |
| 21 | + duplicate.read_ber!(Net::LDAP::AsnSyntax) rescue Net::BER::BerError |
44 | 22 |
|
45 | | - it "should not modify string" do |
46 | | - str.should == initial_value |
47 | | - end |
48 | | - end |
49 | | - end |
| 23 | + assert_equal original, duplicate |
50 | 24 | end |
51 | 25 | end |
0 commit comments