ruby-ldap/ruby-net-ldap — pull request #116 by jch (2014-10-06 22:22:05+00:00)
Title: Add private Net::LDAP::Connection#write_request

This new method accomplishes two things:

- DRY up existing calls to `#write`
- provide an entry point for test mocking what goes out on the wire

While working on https://github.com/ruby-ldap/ruby-net-ldap/pull/115, I noticed it was difficult to make assertions about what was being written out on the socket because those values were already BER encoded. By adding `#write_request`, it allows us to write assertions like the following:

```ruby
def test_some_operation
mock = Minitest::Mock.new
mock.expect(:write_request, true, [[1.to_ber, "some_operation's data"].to_ber_sequence])
conn = Net::LDAP::Connection.new(:socket => mock)
conn.some_operation(...)
end
```

It's possible to go even more general, but this refactoring is small and does what I want. I also introduced `Minitest::Mock` here. I saw that the project also has flexmock as a dependency, but proposed it with minitest in case that's the direction we want to move towards. If it's preferred, I can also figure out [how to achieve the same mocking with flexmock](https://github.com/jimweirich/flexmock#asserting-spy-methods-are-called-testunit--minitest).

cc @mtodd @schaary