开发者

cucumber and activemerchant duplicate transaction problem

I was following this code for cucumber testing with activemerchant and authorize.net(I know it's old but it's the one that worked for me)

http://www.misuse.org/science/2007/12/13/using-activemerchant-to-process-credit-cards-in-rubyrails/

Anyway, his fix for the duplicate transaction problem(when going through a lot of cucumber scenarios fast) was to assign a random price to the object so that it will be different every time.

The problem with this is that it effectively makes testing for the correct price almost impossible. How should I rewrite my tests or setup Authorize or Activemerchant to bypass this problem? I am trying to write a test that will check if my cart's total price if I change some items and this won't be possible with prices being random.

My only current check for pricing right now(which works) is that I look at the ui and check the price in the div .total-price and check that if it's equal to the price of all the items added together. It does pass, but what if I changed the price? I surely don't know how much the total price is(since they're all random) and I won't be开发者_如何学Go able to check the new price(since it's still random)

Thanks!


Use webmock or similar library to stub authorize.net.

Here is example:

 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
  • Free Bonus - your tests will work faster and will not depend on authorize.net sandbox uptime
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜