Ruby on rails 如何使用多行字符串示例比较Cucumber步骤中的xml输出?
Chargifi在他们的书中有这样一个黄瓜场景Ruby on rails 如何使用多行字符串示例比较Cucumber步骤中的xml输出?,ruby-on-rails,ruby,xml,api,cucumber,Ruby On Rails,Ruby,Xml,Api,Cucumber,Chargifi在他们的书中有这样一个黄瓜场景 您可以使用,然后与进行比较。以散列形式进行比较可以消除不重要的空白,避免混淆比较。如果您不想依赖ActiveSupport(例如,如果您在Rails之外),您可以尝试使用。它允许您将上述期望写入以下内容: response=page.body response.response应等同于(xml输出) 对于在非Rails项目上尝试此方法的任何人,请注意,您需要“主动\u支持/core\u ext/hash/conversions”和“主动\u支持/c
您可以使用,然后与进行比较。以散列形式进行比较可以消除不重要的空白,避免混淆比较。如果您不想依赖ActiveSupport(例如,如果您在Rails之外),您可以尝试使用。它允许您将上述期望写入以下内容:
response=page.body
response.response应等同于(xml输出)
对于在非Rails项目上尝试此方法的任何人,请注意,您需要“主动\u支持/core\u ext/hash/conversions”和“主动\u支持/core\u ext/hash/diff”也要注意,如果您有一个具有深嵌套的哈希,那么这种方法似乎无法完全遍历它来检查所有差异。请注意原因。
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>
"""
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