Skip to content

Commit 40f0e18

Browse files
author
Michael Baker
committed
Add success and failure methods.
1 parent 2763040 commit 40f0e18

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/net/ldap/pdu.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ def status
128128
result_code == 0 ? :success : :failure
129129
end
130130

131+
def success?
132+
status == :success
133+
end
134+
135+
def failure?
136+
!success?
137+
end
138+
131139
##
132140
# Return serverSaslCreds, which are only present in BindResponse packets.
133141
#--

spec/unit/ldap_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
flexmock(TCPSocket).
88
should_receive(:new).and_raise(Errno::ECONNREFUSED)
99
end
10-
10+
1111
it "should raise LdapError" do
1212
lambda {
1313
Net::LDAP::Connection.new(
14-
:server => 'test.mocked.com',
14+
:server => 'test.mocked.com',
1515
:port => 636)
1616
}.should raise_error(Net::LDAP::LdapError)
1717
end
@@ -21,11 +21,11 @@
2121
flexmock(TCPSocket).
2222
should_receive(:new).and_raise(SocketError)
2323
end
24-
24+
2525
it "should raise LdapError" do
2626
lambda {
2727
Net::LDAP::Connection.new(
28-
:server => 'test.mocked.com',
28+
:server => 'test.mocked.com',
2929
:port => 636)
3030
}.should raise_error(Net::LDAP::LdapError)
3131
end
@@ -35,11 +35,11 @@
3535
flexmock(TCPSocket).
3636
should_receive(:new).and_raise(NameError)
3737
end
38-
38+
3939
it "should rethrow the exception" do
4040
lambda {
4141
Net::LDAP::Connection.new(
42-
:server => 'test.mocked.com',
42+
:server => 'test.mocked.com',
4343
:port => 636)
4444
}.should raise_error(NameError)
4545
end
@@ -61,7 +61,7 @@
6161
@tcp_socket.should_receive(:read_ber).and_return([2, ber])
6262

6363
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "[email protected]"]])
64-
result.status.should == :failure
64+
result.should be_failure
6565
result.error_message.should == "The provided password value was rejected by a password validator: The provided password did not contain enough characters from the character set 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. The minimum number of characters from that set that must be present in user passwords is 1"
6666
end
6767

@@ -71,7 +71,7 @@
7171
@tcp_socket.should_receive(:read_ber).and_return([2, ber])
7272

7373
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "[email protected]"]])
74-
result.status.should == :success
74+
result.should be_success
7575
result.error_message.should == ""
7676
end
7777
end

0 commit comments

Comments
 (0)