wreq 1.2.2-x86_64-linux → 1.2.3-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,33 +2,33 @@ require "test_helper"
2
2
 
3
3
  class ModuleMethodsTest < Minitest::Test
4
4
  def test_module_get
5
- response = Wreq.get("http://localhost:8080/get")
5
+ response = Wreq.get("#{HTTPBIN_URL}/get")
6
6
  refute_nil response
7
7
  assert_equal 200, response.code
8
8
  end
9
9
 
10
10
  def test_module_post
11
- response = Wreq.post("http://localhost:8080/post",
11
+ response = Wreq.post("#{HTTPBIN_URL}/post",
12
12
  json: {module: "test"})
13
13
  refute_nil response
14
14
  assert_equal 200, response.code
15
15
  end
16
16
 
17
17
  def test_module_put
18
- response = Wreq.put("http://localhost:8080/put",
18
+ response = Wreq.put("#{HTTPBIN_URL}/put",
19
19
  json: {data: "test"})
20
20
  refute_nil response
21
21
  assert_equal 200, response.code
22
22
  end
23
23
 
24
24
  def test_module_delete
25
- response = Wreq.delete("http://localhost:8080/delete")
25
+ response = Wreq.delete("#{HTTPBIN_URL}/delete")
26
26
  refute_nil response
27
27
  assert_equal 200, response.code
28
28
  end
29
29
 
30
30
  def test_module_patch
31
- response = Wreq.patch("http://localhost:8080/patch",
31
+ response = Wreq.patch("#{HTTPBIN_URL}/patch",
32
32
  json: {update: "field"})
33
33
  refute_nil response
34
34
  assert_equal 200, response.code
@@ -37,23 +37,23 @@ class ModuleMethodsTest < Minitest::Test
37
37
  end
38
38
 
39
39
  def test_module_request_method
40
- response = Wreq.request(Wreq::Method::GET, "http://localhost:8080/get")
40
+ response = Wreq.request(Wreq::Method::GET, "#{HTTPBIN_URL}/get")
41
41
  refute_nil response
42
42
  assert_equal 200, response.code
43
43
  end
44
44
 
45
45
  def test_module_methods_with_parameters
46
- response = Wreq.get("http://localhost:8080/get",
46
+ response = Wreq.get("#{HTTPBIN_URL}/get",
47
47
  headers: {"Accept" => "application/json"},
48
48
  query: {"test" => "module"})
49
49
  refute_nil response
50
- assert_equal response.url, "http://localhost:8080/get?test=module"
51
- assert_includes response.text, "http://localhost:8080/get?test=module"
50
+ assert_equal "#{HTTPBIN_URL}/get?test=module", response.url
51
+ assert_equal "module", httpbin_fetch(response.json["args"], "test")
52
52
  assert_equal 200, response.code
53
53
  end
54
54
 
55
55
  def test_module_post_with_json
56
- response = Wreq.post("http://localhost:8080/post",
56
+ response = Wreq.post("#{HTTPBIN_URL}/post",
57
57
  json: {
58
58
  string: "test",
59
59
  number: 123,
@@ -65,7 +65,7 @@ class ModuleMethodsTest < Minitest::Test
65
65
  end
66
66
 
67
67
  def test_module_post_with_form
68
- response = Wreq.post("http://localhost:8080/post",
68
+ response = Wreq.post("#{HTTPBIN_URL}/post",
69
69
  form: {"field1" => "value1", "field2" => "value2"})
70
70
  refute_nil response
71
71
  assert_equal 200, response.code
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class RequestParametersTest < Minitest::Test
4
4
  def test_query_parameters
5
- response = Wreq.get("http://localhost:8080/get",
5
+ response = Wreq.get("#{HTTPBIN_URL}/get",
6
6
  query: {
7
7
  "string" => "value",
8
8
  "number" => "123",
@@ -12,9 +12,9 @@ class RequestParametersTest < Minitest::Test
12
12
 
13
13
  json_data = response.json
14
14
  args = json_data["args"]
15
- assert_equal "value", args["string"]
16
- assert_equal "123", args["number"] # Query params are strings
17
- assert_equal "true", args["boolean"]
15
+ assert_equal "value", httpbin_fetch(args, "string")
16
+ assert_equal "123", httpbin_fetch(args, "number") # Query params are strings
17
+ assert_equal "true", httpbin_fetch(args, "boolean")
18
18
  end
19
19
 
20
20
  def test_headers
@@ -24,15 +24,15 @@ class RequestParametersTest < Minitest::Test
24
24
  "Accept" => "application/json"
25
25
  }
26
26
 
27
- response = Wreq.get("http://localhost:8080/get", headers: custom_headers)
27
+ response = Wreq.get("#{HTTPBIN_URL}/get", headers: custom_headers)
28
28
  assert_equal 200, response.code
29
29
 
30
30
  json_data = response.json
31
31
  request_headers = json_data["headers"]
32
32
 
33
- assert_equal "custom-value", request_headers["X-Custom-Header"]
34
- assert_equal "wreq-ruby-test/1.0", request_headers["User-Agent"]
35
- assert_equal "application/json", request_headers["Accept"]
33
+ assert_equal "custom-value", httpbin_fetch(request_headers, "X-Custom-Header")
34
+ assert_equal "wreq-ruby-test/1.0", httpbin_fetch(request_headers, "User-Agent")
35
+ assert_equal "application/json", httpbin_fetch(request_headers, "Accept")
36
36
  end
37
37
 
38
38
  def test_json_body
@@ -44,7 +44,7 @@ class RequestParametersTest < Minitest::Test
44
44
  "object" => {"nested" => "value"}
45
45
  }
46
46
 
47
- response = Wreq.post("http://localhost:8080/post", json: json_data)
47
+ response = Wreq.post("#{HTTPBIN_URL}/post", json: json_data)
48
48
  assert_equal 200, response.code
49
49
 
50
50
  response_data = response.json
@@ -64,19 +64,19 @@ class RequestParametersTest < Minitest::Test
64
64
  "number" => "123"
65
65
  }
66
66
 
67
- response = Wreq.post("http://localhost:8080/post", form: form_data)
67
+ response = Wreq.post("#{HTTPBIN_URL}/post", form: form_data)
68
68
  assert_equal 200, response.code
69
69
 
70
70
  response_data = response.json
71
71
  sent_form = response_data["form"]
72
72
 
73
- assert_equal "value1", sent_form["field1"]
74
- assert_equal "value2", sent_form["field2"]
75
- assert_equal "123", sent_form["number"]
73
+ assert_equal "value1", httpbin_fetch(sent_form, "field1")
74
+ assert_equal "value2", httpbin_fetch(sent_form, "field2")
75
+ assert_equal "123", httpbin_fetch(sent_form, "number")
76
76
  end
77
77
 
78
78
  def test_combined_parameters
79
- response = Wreq.post("http://localhost:8080/post",
79
+ response = Wreq.post("#{HTTPBIN_URL}/post",
80
80
  query: {"q" => "search"},
81
81
  headers: {"X-Test" => "combined"},
82
82
  json: {"data" => "payload"})
@@ -86,10 +86,10 @@ class RequestParametersTest < Minitest::Test
86
86
  json_data = response.json
87
87
 
88
88
  # Check query parameters
89
- assert_equal "search", json_data["args"]["q"]
89
+ assert_equal "search", httpbin_fetch(json_data["args"], "q")
90
90
 
91
91
  # Check headers
92
- assert_equal "combined", json_data["headers"]["X-Test"]
92
+ assert_equal "combined", httpbin_fetch(json_data["headers"], "X-Test")
93
93
 
94
94
  # Check JSON body
95
95
  assert_equal "payload", json_data["json"]["data"]
@@ -97,7 +97,7 @@ class RequestParametersTest < Minitest::Test
97
97
 
98
98
  def test_empty_parameters
99
99
  # Test with no additional parameters
100
- response = Wreq.get("http://localhost:8080/get")
100
+ response = Wreq.get("#{HTTPBIN_URL}/get")
101
101
  assert_equal 200, response.code
102
102
 
103
103
  json_data = response.json
@@ -113,16 +113,16 @@ class RequestParametersTest < Minitest::Test
113
113
  "url_chars" => "a=b&c=d"
114
114
  }
115
115
 
116
- response = Wreq.get("http://localhost:8080/get", query: special_data)
116
+ response = Wreq.get("#{HTTPBIN_URL}/get", query: special_data)
117
117
  assert_equal 200, response.code
118
118
 
119
119
  json_data = response.json
120
120
  args = json_data["args"]
121
121
 
122
- assert_equal "value with spaces", args["space"]
123
- assert_equal "!@#$%^&*()", args["symbols"]
124
- assert_equal "测试中文", args["unicode"]
125
- assert_equal "a=b&c=d", args["url_chars"]
122
+ assert_equal "value with spaces", httpbin_fetch(args, "space")
123
+ assert_equal "!@#$%^&*()", httpbin_fetch(args, "symbols")
124
+ assert_equal "测试中文", httpbin_fetch(args, "unicode")
125
+ assert_equal "a=b&c=d", httpbin_fetch(args, "url_chars")
126
126
  end
127
127
 
128
128
  def test_nested_json_data
@@ -140,7 +140,7 @@ class RequestParametersTest < Minitest::Test
140
140
  }
141
141
  }
142
142
 
143
- response = Wreq.post("http://localhost:8080/post", json: nested_data)
143
+ response = Wreq.post("#{HTTPBIN_URL}/post", json: nested_data)
144
144
  assert_equal 200, response.code
145
145
 
146
146
  response_data = response.json
@@ -153,11 +153,11 @@ class RequestParametersTest < Minitest::Test
153
153
 
154
154
  def test_method_specific_parameters
155
155
  methods_and_urls = {
156
- get: "http://localhost:8080/get",
157
- post: "http://localhost:8080/post",
158
- put: "http://localhost:8080/put",
159
- patch: "http://localhost:8080/patch",
160
- delete: "http://localhost:8080/delete"
156
+ get: "#{HTTPBIN_URL}/get",
157
+ post: "#{HTTPBIN_URL}/post",
158
+ put: "#{HTTPBIN_URL}/put",
159
+ patch: "#{HTTPBIN_URL}/patch",
160
+ delete: "#{HTTPBIN_URL}/delete"
161
161
  }
162
162
 
163
163
  methods_and_urls.each do |method, url|
@@ -168,8 +168,8 @@ class RequestParametersTest < Minitest::Test
168
168
  assert_equal 200, response.code, "#{method} request failed"
169
169
 
170
170
  json_data = response.json
171
- assert_equal method.to_s, json_data["headers"]["X-Method"]
172
- assert_equal method.to_s, json_data["args"]["method"]
171
+ assert_equal method.to_s, httpbin_fetch(json_data["headers"], "X-Method")
172
+ assert_equal method.to_s, httpbin_fetch(json_data["args"], "method")
173
173
  end
174
174
  end
175
175
  end
data/test/request_test.rb CHANGED
@@ -17,25 +17,25 @@ class WreqHttpbinTest < Minitest::Test
17
17
  end
18
18
 
19
19
  def test_module_get_method
20
- response = Wreq.get("http://localhost:8080/get")
20
+ response = Wreq.get("#{HTTPBIN_URL}/get")
21
21
  assert_equal 200, response.code
22
22
  assert_respond_to response, :text
23
23
  end
24
24
 
25
25
  def test_module_post_with_json
26
26
  data = {name: "wreq-ruby", version: "0.1.0"}
27
- response = Wreq.post("http://localhost:8080/post", json: data)
27
+ response = Wreq.post("#{HTTPBIN_URL}/post", json: data)
28
28
  assert_equal 200, response.code
29
29
  end
30
30
 
31
31
  def test_client_instance_basic
32
- response = @client.get("http://localhost:8080/get")
32
+ response = @client.get("#{HTTPBIN_URL}/get")
33
33
  assert_equal 200, response.code
34
34
  end
35
35
 
36
36
  def test_client_with_custom_headers
37
37
  headers = {"User-Agent" => "wreq-ruby/test", "Accept" => "application/json"}
38
- response = @client.get("http://localhost:8080/headers", headers: headers)
38
+ response = @client.get("#{HTTPBIN_URL}/headers", headers: headers)
39
39
  assert_equal 200, response.code
40
40
  end
41
41
 
@@ -51,14 +51,14 @@ class WreqHttpbinTest < Minitest::Test
51
51
  ]
52
52
 
53
53
  methods.each do |method|
54
- response = @client.request(method, "http://localhost:8080/#{method}")
54
+ response = @client.request(method, "#{HTTPBIN_URL}/anything")
55
55
  assert [200, 405].include?(response.code), "client.#{method} failed with status #{response.code}"
56
56
  end
57
57
  end
58
58
 
59
59
  def test_request_with_query_params
60
60
  params = {"param1" => "value1", "param2" => "value2", "param3" => 123, "param4" => true}
61
- response = Wreq.get("http://localhost:8080/get", query: params)
61
+ response = Wreq.get("#{HTTPBIN_URL}/get", query: params)
62
62
  assert_equal 200, response.code
63
63
  assert_includes response.text, "param1=value1"
64
64
  assert_includes response.text, "param2=value2"
@@ -68,7 +68,7 @@ class WreqHttpbinTest < Minitest::Test
68
68
 
69
69
  def test_post_with_form_data
70
70
  data = {"field1" => "value1", "field2" => "value2", "field3" => 456, "field4" => false}
71
- response = Wreq.post("http://localhost:8080/post", form: data)
71
+ response = Wreq.post("#{HTTPBIN_URL}/post", form: data)
72
72
  assert_equal 200, response.code
73
73
  assert_includes response.text, "field1"
74
74
  assert_includes response.text, "value1"
@@ -83,33 +83,33 @@ class WreqHttpbinTest < Minitest::Test
83
83
  def test_post_with_raw_body
84
84
  body = "This is raw body content"
85
85
  headers = {"Content-Type" => "text/plain"}
86
- response = Wreq.post("http://localhost:8080/post", body: body, headers: headers)
86
+ response = Wreq.post("#{HTTPBIN_URL}/post", body: body, headers: headers)
87
87
  assert_equal 200, response.code
88
88
  assert_includes response.text, body
89
89
  end
90
90
 
91
91
  def test_basic_authentication
92
- response = Wreq.get("http://localhost:8080/basic-auth/user/pass", basic_auth: ["user", "pass"])
92
+ response = Wreq.get("#{HTTPBIN_URL}/basic-auth/user/pass", basic_auth: ["user", "pass"])
93
93
  assert_equal 200, response.code
94
94
  end
95
95
 
96
96
  def test_bearer_authentication
97
- response = Wreq.get("http://localhost:8080/bearer", bearer_auth: "test-token")
97
+ response = Wreq.get("#{HTTPBIN_URL}/bearer", bearer_auth: "test-token")
98
98
  assert_equal 200, response.code
99
99
  end
100
100
 
101
101
  def test_redirect_following
102
- response = Wreq.get("http://localhost:8080/redirect/2", allow_redirects: true)
102
+ response = Wreq.get("#{HTTPBIN_URL}/redirect/2", allow_redirects: true)
103
103
  assert_equal 200, response.code
104
104
  end
105
105
 
106
106
  def test_redirect_blocking
107
- response = Wreq.get("http://localhost:8080/redirect/1", allow_redirects: false)
107
+ response = Wreq.get("#{HTTPBIN_URL}/redirect/1", allow_redirects: false)
108
108
  assert_equal 302, response.code
109
109
  end
110
110
 
111
111
  def test_response_status_methods
112
- response = Wreq.get("http://localhost:8080/status/200")
112
+ response = Wreq.get("#{HTTPBIN_URL}/status/200")
113
113
  assert_equal 200, response.code
114
114
 
115
115
  if response.status.respond_to?(:success?)
@@ -118,7 +118,7 @@ class WreqHttpbinTest < Minitest::Test
118
118
  end
119
119
 
120
120
  def test_404_response
121
- response = Wreq.get("http://localhost:8080/status/404")
121
+ response = Wreq.get("#{HTTPBIN_URL}/status/404")
122
122
  assert_equal 404, response.code
123
123
 
124
124
  if response.status.respond_to?(:client_error?)
@@ -127,7 +127,7 @@ class WreqHttpbinTest < Minitest::Test
127
127
  end
128
128
 
129
129
  def test_json_response_parsing
130
- response = Wreq.get("http://localhost:8080/json")
130
+ response = Wreq.get("#{HTTPBIN_URL}/json")
131
131
  assert_equal 200, response.code
132
132
 
133
133
  if response.respond_to?(:json)
@@ -137,12 +137,12 @@ class WreqHttpbinTest < Minitest::Test
137
137
  end
138
138
 
139
139
  def test_gzip_compression
140
- response = Wreq.get("http://localhost:8080/gzip", gzip: true)
140
+ response = Wreq.get("#{HTTPBIN_URL}/gzip", gzip: true)
141
141
  assert_equal 200, response.code
142
142
  end
143
143
 
144
144
  def test_headers_iteration
145
- response = Wreq.get("http://localhost:8080/get")
145
+ response = Wreq.get("#{HTTPBIN_URL}/get")
146
146
 
147
147
  if response.respond_to?(:each_header)
148
148
  count = 0
@@ -157,7 +157,7 @@ class WreqHttpbinTest < Minitest::Test
157
157
  end
158
158
 
159
159
  def test_response_properties
160
- response = Wreq.get("http://localhost:8080/get")
160
+ response = Wreq.get("#{HTTPBIN_URL}/get")
161
161
 
162
162
  assert_respond_to response, :code
163
163
  assert_respond_to response, :status
@@ -171,12 +171,12 @@ class WreqHttpbinTest < Minitest::Test
171
171
  def test_timeout_functionality
172
172
  # Test that short timeouts properly raise exceptions
173
173
  assert_raises(Wreq::TimeoutError) do
174
- Wreq.get("http://localhost:8080/delay/10", timeout: 1)
174
+ Wreq.get("#{HTTPBIN_URL}/delay/10", timeout: 1)
175
175
  end
176
176
 
177
177
  # Test that reasonable timeouts work normally
178
178
  start_time = Time.now
179
- response = Wreq.get("http://localhost:8080/delay/1", timeout: 5)
179
+ response = Wreq.get("#{HTTPBIN_URL}/delay/1", timeout: 5)
180
180
  elapsed = Time.now - start_time
181
181
 
182
182
  assert_equal 200, response.code
@@ -187,7 +187,7 @@ class WreqHttpbinTest < Minitest::Test
187
187
  start_time = Time.now
188
188
 
189
189
  3.times do |i|
190
- response = Wreq.get("http://localhost:8080/get?request=#{i}")
190
+ response = Wreq.get("#{HTTPBIN_URL}/get?request=#{i}")
191
191
  assert_equal 200, response.code
192
192
  end
193
193
 
@@ -212,7 +212,7 @@ class WreqHttpbinTest < Minitest::Test
212
212
  assert_instance_of Wreq::Client, client
213
213
 
214
214
  # Test that it can make requests
215
- response = client.get("http://localhost:8080/get")
215
+ response = client.get("#{HTTPBIN_URL}/get")
216
216
  assert_equal 200, response.code
217
217
  end
218
218
 
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class ResponseTest < Minitest::Test
4
4
  def setup
5
- @response = Wreq.get("http://localhost:8080/json")
5
+ @response = Wreq.get("#{HTTPBIN_URL}/json")
6
6
  end
7
7
 
8
8
  def test_response_code
@@ -39,7 +39,7 @@ class ResponseTest < Minitest::Test
39
39
  end
40
40
 
41
41
  def test_response_with_non_json_content
42
- response = Wreq.get("http://localhost:8080/html")
42
+ response = Wreq.get("#{HTTPBIN_URL}/html")
43
43
  assert_equal 200, response.code
44
44
  assert_instance_of String, response.text
45
45
  assert response.text.include?("<html>")
@@ -51,19 +51,19 @@ class ResponseTest < Minitest::Test
51
51
  def test_response_status_codes
52
52
  # Test different status codes
53
53
  [200, 404, 500].each do |status|
54
- response = Wreq.get("http://localhost:8080/status/#{status}")
54
+ response = Wreq.get("#{HTTPBIN_URL}/status/#{status}")
55
55
  assert_equal status, response.code
56
56
  end
57
57
  end
58
58
 
59
59
  def test_response_with_query_parameters
60
- response = Wreq.get("http://localhost:8080/get",
60
+ response = Wreq.get("#{HTTPBIN_URL}/get",
61
61
  query: {"param1" => "value1", "param2" => "value2"})
62
62
  assert_equal 200, response.code
63
63
 
64
64
  json_data = response.json
65
65
  args = json_data["args"]
66
- assert_equal "value1", args["param1"]
67
- assert_equal "value2", args["param2"]
66
+ assert_equal "value1", httpbin_fetch(args, "param1")
67
+ assert_equal "value2", httpbin_fetch(args, "param2")
68
68
  end
69
69
  end