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.
This commit is contained in:
Evan Broder 2012-04-23 10:00:29 -07:00
parent 00a4be73f9
commit 69a96ecc4b

View File

@ -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] }))