Shopify/active_merchant — pull request #490 by moklett (2012-10-27 21:20:59+00:00)
Title: Adds XML assertions and a test helper to capture post data

When testing ActiveMerchant code, it is often helpful to be able to inspect the data you are actually sending to the gateway.

For example, if I'm implementing a new option (via the options hash) on a gateway that should send a new XML element with a particular value in the POST data, I would like to know that setting that option results in adding the new XML, without verifying the exact structure of ALL the XML.

One way you might do this is to use an HTTP mocking/expectation library like WebMock and set expectations on the POSTed data.

Since it's probably best not to add another dependency to a mature library, I'm trying a different tact.

This code provides a way to explicitly capture the data being POSTed by any gateway that uses the common +ssl_post+ method. Once captured, you can perform assertions on the data.

```
amount = 1000
xml = capture_post_data(@gateway) do |gateway|
gateway.purchase(@amount, @visa)
end
assert_xml_element(xml, 'Amount')
assert_xml_element_text(xml, 'Amount', '1000')
```

This code also provides some basic assertions for XML element presence and node text equivalence.