1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
Shindo.tests('Excon query string variants') do
with_rackup('query_string.ru') do
connection = Excon.new('http://127.0.0.1:9292')
tests(":query => {:foo => 'bar'}") do
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar'})
query_string = response.body[7..-1] # query string sent
tests("query string sent").returns('foo=bar') do
query_string
end
end
tests(":query => {:foo => nil}") do
response = connection.request(:method => :get, :path => '/query', :query => {:foo => nil})
query_string = response.body[7..-1] # query string sent
tests("query string sent").returns('foo') do
query_string
end
end
tests(":query => {:foo => 'bar', :me => nil}") do
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar', :me => nil})
query_string = response.body[7..-1] # query string sent
test("query string sent includes 'foo=bar'") do
query_string.split('&').include?('foo=bar')
end
test("query string sent includes 'me'") do
query_string.split('&').include?('me')
end
end
tests(":query => {:foo => 'bar', :me => 'too'}") do
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar', :me => 'too'})
query_string = response.body[7..-1] # query string sent
test("query string sent includes 'foo=bar'") do
query_string.split('&').include?('foo=bar')
end
test("query string sent includes 'me=too'") do
query_string.split('&').include?('me=too')
end
end
# You can use an atom or a string for the hash keys, what is shown here is emulating
# the Rails and PHP style of serializing a query array with a square brackets suffix.
tests(":query => {'foo[]' => ['bar', 'baz'], :me => 'too'}") do
response = connection.request(:method => :get, :path => '/query', :query => {'foo[]' => ['bar', 'baz'], :me => 'too'})
query_string = response.body[7..-1] # query string sent
test("query string sent includes 'foo%5B%5D=bar'") do
query_string.split('&').include?('foo%5B%5D=bar')
end
test("query string sent includes 'foo%5B%5D=baz'") do
query_string.split('&').include?('foo%5B%5D=baz')
end
test("query string sent includes 'me=too'") do
query_string.split('&').include?('me=too')
end
end
tests(":query => {'foo%=#' => 'bar%=#'}") do
response = connection.request(:method => :get, :path => '/query', :query => {'foo%=#' => 'bar%=#'})
query_string = response.body[7..-1] # query string sent
tests("query string sent").returns('foo%25%3D%23=bar%25%3D%23') do
query_string
end
end
tests(":query => {'foo%=#' => nil}") do
response = connection.request(:method => :get, :path => '/query', :query => {'foo%=#' => nil})
query_string = response.body[7..-1] # query string sent
tests("query string sent").returns('foo%25%3D%23') do
query_string
end
end
end
end
|