From 69a96ecc4b08549cf496c26a92ebbd8f405db49f Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Mon, 23 Apr 2012 10:00:29 -0700 Subject: [PATCH] Parse URL query string in tests to deal with hash order differences My rvm 1.8.7 Linux build of Ruby appears to generate query strings in a different order than the test suite expected. --- test/test_stripe.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_stripe.rb b/test/test_stripe.rb index 1ddc84c4..6cd0ae2f 100644 --- a/test/test_stripe.rb +++ b/test/test_stripe.rb @@ -5,6 +5,8 @@ require 'shoulda' require 'mocha' require 'pp' require 'rest-client' +require 'cgi' +require 'uri' class TestStripeRuby < Test::Unit::TestCase include Mocha @@ -160,7 +162,12 @@ class TestStripeRuby < Test::Unit::TestCase end should "setting a nil value for a param should exclude that param from the request" do - @mock.expects(:get).with('https://api.stripe.com/v1/charges?offset=5&sad=false', nil, nil).returns(test_response({ :count => 1, :data => [test_charge] })) + @mock.expects(:get).with do |url, api_key, params| + uri = URI(url) + query = CGI.parse(uri.query) + (url =~ %r{^https://api.stripe.com/v1/charges?} && + query.keys.sort == ['offset', 'sad']) + end.returns(test_response({ :count => 1, :data => [test_charge] })) c = Stripe::Charge.all(:count => nil, :offset => 5, :sad => false) @mock.expects(:post).with('https://api.stripe.com/v1/charges', nil, { :amount => 50, :currency => 'usd', :card => {} }).returns(test_response({ :count => 1, :data => [test_charge] }))