Charge has this cucumber script in docs .
Scenario: Retrieve a customer via my reference id (as an integer or simple string) Given I have a customer with these attributes | reference | first_name | last_name | email | | 7890 | Joe | Blow | joe@example.com | When I send a GET request to https://[@subdomain].chargify.com/customers/lookup.xml?reference=7890 Then the response status should be "200 OK" And the response should be the xml: """ <?xml version="1.0" encoding="UTF-8"?> <customer> <id type="integer">`auto generated`</id> <first_name>Joe</first_name> <last_name>Blow</last_name> <email> joe@example.com </email> <organization>`your value`</organization> <reference>7890</reference> <created_at type="datetime">`auto generated`</created_at> <updated_at type="datetime">`auto generated`</updated_at> </customer> """
I am trying to follow their approach when testing the API that we are developing here, instead of checking the tags one by one, as I did before I met this example.
So far, it has not been possible to combine the response output with a multi-line step line due to formatting problems. They did not find a way with Nokogiri or with a simple devoid of string comparisons.
Is there an elegant (and efficient) way to do this?
Update
Here's the cucumber pitch using the Mark solution:
Then /^I should see the following output$/ do |xml_output| response = Hash.from_xml(page.body) expected = Hash.from_xml(xml_output) expected.diff(response).should == {} end
source share