Chargify имеет этот сценарий огурца в своих документах .
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>
"""
Я пытаюсь следовать их подходу при тестировании API, который мы здесь разрабатываем, вместо того, чтобы проверять теги по одному, как я делал до того, как наткнулся на этот пример.
Пока что не повезло сопоставить вывод ответа с многострочной строкой шага из-за проблем с форматированием.Не удалось найти ни Nokogiri, ни простого сравнения строк.
Существует ли элегантный (и эффективный) способ сделать это?
Обновление
Вот шаг огурца с использованием решения Марка:
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