我正在使用activemerchant和authorize.net跟踪此代码进行黄瓜测试(我知道它已经老了,但它是适合我的那个)
http://www.misuse.org/science/2007/12/13/using-activemerchant-to-process-credit-cards-in-rubyrails/
无论如何,他对重复交易问题的解决方案(当快速经历很多黄瓜情景时)是为对象分配一个随机价格,以便每次都不同。
问题在于它有效地使得测试正确的价格几乎是不可能的。我应该如何重写我的测试或设置Authorize或Activemerchant来绕过这个问题?我正在尝试编写一个测试,如果我更改了某些项目,将检查我的购物车的总价格,而且价格是随机的,这是不可能的。
我目前唯一的定价检查(有效)是我查看ui并检查div .total-price的价格并检查它是否等于加在一起的所有商品的价格。它确实通过了,但如果我改变了价格呢?我当然不知道总价是多少(因为它们都是随机的),我将无法检查新价格(因为它仍然是随机的)
谢谢!
答案 0 :(得分:1)
使用webmock或类似的库来存根authorize.net。
以下是示例:
Given /^authorize\.net will authorize payment$/ do
stub_request(:post, "https://apitest.authorize.net/xml/v1/request.api").
with(:body => /.*createCustomerProfileRequest.*/).
to_return(:body => fixturefile("authorize_net_create_profile_ok_response.xml"))
stub_request(:post, "https://apitest.authorize.net/xml/v1/request.api").
with(:body => /.*createCustomerProfileTransactionRequest.*/).
to_return(:body => fixturefile("authorize_net_authorize_ok_response.xml"))
end