ruby-on-rails – 如何使用多行字符串示例比较Cucumber步骤中的x
发布时间:2020-12-17 02:59:49 所属栏目:百科 来源:网络整理
导读:Chargify在他们的 docs中有这个Cucumber场景. 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 |
Chargify在他们的
docs中有这个Cucumber场景.
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的方法,也没有简单的剥离字符串比较. 是否有一种优雅(高效)的方式来做到这一点? 更新 这是使用Mark解决方案的黄瓜步骤: 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,然后与
Hash.diff进行比较.比较哈希可以消除无关紧要的空白,从而搞乱比较.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |