thoughtbot/fake_braintree — pull request #73 by mislav (2014-12-07 02:01:06+00:00)
Title: Add `:gateway_port` option to configure the API server port

In parallel testing mode via forked processes, it's not safe to use auto-assignment of ephemeral ports because it can lead to inermittent and hard-to-debug race conditions. For these kinds of test suites, it's necessary to be able to explicitly configure what port to use for spinning up API server.

For this to be configurable at all, it also means that `FakeBraintree.activate!` cannot happen at library load time. I think it's a good thing to make that switch, since `activate!` mutates global state of ENV and Braintree::Configuration and spins up a server thread, and as such is too invasive to be performed automatically. Users have already been bitten by this: https://github.com/thoughtbot/fake_braintree/issues/54#issuecomment-62305551

This of course means breaking backwards compatibility, so you'll have to bump up the major version number, but I think that it's worth it for the long term.

This change also has a happy side-effect, and that is fixing the case when user might have set a fixed `Capybara.server_port` for their browser acceptance tests. If `fake_braintree` hasn't been loaded up to that point, as soon as it loads it would have inherited that port number (which is not meant for its use) and thus collide with acceptance tests.

/cc @chrishunt