Permalink
Browse files

Add success and failure methods.

  • Loading branch information...
Michael Baker
Michael Baker committed Nov 30, 2011
1 parent 2763040 commit 40f0e1857ee619250051d7d37f48a5c03424a29f
Showing with 16 additions and 8 deletions.
  1. +8 −0 lib/net/ldap/pdu.rb
  2. +8 −8 spec/unit/ldap_spec.rb
View
@@ -128,6 +128,14 @@ def status
result_code == 0 ? :success : :failure
end
+ def success?
+ status == :success
+ end
+
+ def failure?
+ !success?
+ end
+
##
# Return serverSaslCreds, which are only present in BindResponse packets.
#--
View
@@ -7,11 +7,11 @@
flexmock(TCPSocket).
should_receive(:new).and_raise(Errno::ECONNREFUSED)
end
-
+
it "should raise LdapError" do
lambda {
Net::LDAP::Connection.new(
- :server => 'test.mocked.com',
+ :server => 'test.mocked.com',
:port => 636)
}.should raise_error(Net::LDAP::LdapError)
end
@@ -21,11 +21,11 @@
flexmock(TCPSocket).
should_receive(:new).and_raise(SocketError)
end
-
+
it "should raise LdapError" do
lambda {
Net::LDAP::Connection.new(
- :server => 'test.mocked.com',
+ :server => 'test.mocked.com',
:port => 636)
}.should raise_error(Net::LDAP::LdapError)
end
@@ -35,11 +35,11 @@
flexmock(TCPSocket).
should_receive(:new).and_raise(NameError)
end
-
+
it "should rethrow the exception" do
lambda {
Net::LDAP::Connection.new(
- :server => 'test.mocked.com',
+ :server => 'test.mocked.com',
:port => 636)
}.should raise_error(NameError)
end
@@ -61,7 +61,7 @@
@tcp_socket.should_receive(:read_ber).and_return([2, ber])
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]])
- result.status.should == :failure
+ result.should be_failure
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"
end
@@ -71,7 +71,7 @@
@tcp_socket.should_receive(:read_ber).and_return([2, ber])
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]])
- result.status.should == :success
+ result.should be_success
result.error_message.should == ""
end
end

0 comments on commit 40f0e18

Please sign in to comment.