Chargify 在他们的项目中有这个 Cucumber 场景docs http://docs.chargify.com/api-customers#api-usage-xml-customers-read.
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 | [email protected] /cdn-cgi/l/email-protection |
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>[email protected] /cdn-cgi/l/email-protection</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 或简单的剥离字符串比较的方法。
有没有一种优雅(且有效)的方法来做到这一点?
Update
这是使用马克解决方案的黄瓜步骤:
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
您可以使用Hash.from_xml http://apidock.com/rails/Hash/from_xml/class然后与哈希值差异 http://apidock.com/rails/Hash/diff。作为散列进行比较可以消除因混乱比较而导致的微不足道的空白。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)