Skip to content

Commit 7503082

Browse files
author
kriptoburak
committed
test: match generated Ruby search query
1 parent d3d1aa3 commit 7503082

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

test/x_twitter_scraper/client_test.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class XTwitterScraperTest < Minitest::Test
66
extend Minitest::Serial
77
include WebMock::API
88

9+
TWEET_SEARCH_URL = "http://localhost/x/tweets/search?q=q"
10+
911
def before_all
1012
super
1113
WebMock.enable!
@@ -28,7 +30,7 @@ def after_all
2830
end
2931

3032
def test_client_default_request_default_retry_attempts
31-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 500, body: {})
33+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 500, body: {})
3234

3335
x_twitter_scraper =
3436
XTwitterScraper::Client.new(
@@ -45,7 +47,7 @@ def test_client_default_request_default_retry_attempts
4547
end
4648

4749
def test_client_given_request_default_retry_attempts
48-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 500, body: {})
50+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 500, body: {})
4951

5052
x_twitter_scraper =
5153
XTwitterScraper::Client.new(
@@ -63,7 +65,7 @@ def test_client_given_request_default_retry_attempts
6365
end
6466

6567
def test_client_default_request_given_retry_attempts
66-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 500, body: {})
68+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 500, body: {})
6769

6870
x_twitter_scraper =
6971
XTwitterScraper::Client.new(
@@ -80,7 +82,7 @@ def test_client_default_request_given_retry_attempts
8082
end
8183

8284
def test_client_given_request_given_retry_attempts
83-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 500, body: {})
85+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 500, body: {})
8486

8587
x_twitter_scraper =
8688
XTwitterScraper::Client.new(
@@ -98,7 +100,7 @@ def test_client_given_request_given_retry_attempts
98100
end
99101

100102
def test_client_retry_after_seconds
101-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(
103+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(
102104
status: 500,
103105
headers: {"retry-after" => "1.3"},
104106
body: {}
@@ -123,7 +125,7 @@ def test_client_retry_after_seconds
123125
def test_client_retry_after_date
124126
time_now = Time.now
125127

126-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(
128+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(
127129
status: 500,
128130
headers: {"retry-after" => (time_now + 10).httpdate},
129131
body: {}
@@ -148,7 +150,7 @@ def test_client_retry_after_date
148150
end
149151

150152
def test_client_retry_after_ms
151-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(
153+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(
152154
status: 500,
153155
headers: {"retry-after-ms" => "1300"},
154156
body: {}
@@ -171,7 +173,7 @@ def test_client_retry_after_ms
171173
end
172174

173175
def test_retry_count_header
174-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 500, body: {})
176+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 500, body: {})
175177

176178
x_twitter_scraper =
177179
XTwitterScraper::Client.new(
@@ -190,7 +192,7 @@ def test_retry_count_header
190192
end
191193

192194
def test_omit_retry_count_header
193-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 500, body: {})
195+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 500, body: {})
194196

195197
x_twitter_scraper =
196198
XTwitterScraper::Client.new(
@@ -212,7 +214,7 @@ def test_omit_retry_count_header
212214
end
213215

214216
def test_overwrite_retry_count_header
215-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 500, body: {})
217+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 500, body: {})
216218

217219
x_twitter_scraper =
218220
XTwitterScraper::Client.new(
@@ -232,7 +234,7 @@ def test_overwrite_retry_count_header
232234
end
233235

234236
def test_client_redirect_307
235-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(
237+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(
236238
status: 307,
237239
headers: {"location" => "/redirected"},
238240
body: {}
@@ -266,7 +268,7 @@ def test_client_redirect_307
266268
end
267269

268270
def test_client_redirect_303
269-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(
271+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(
270272
status: 303,
271273
headers: {"location" => "/redirected"},
272274
body: {}
@@ -295,7 +297,7 @@ def test_client_redirect_303
295297
end
296298

297299
def test_client_redirect_auth_keep_same_origin
298-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(
300+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(
299301
status: 307,
300302
headers: {"location" => "/redirected"},
301303
body: {}
@@ -330,7 +332,7 @@ def test_client_redirect_auth_keep_same_origin
330332
end
331333

332334
def test_client_redirect_auth_strip_cross_origin
333-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(
335+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(
334336
status: 307,
335337
headers: {"location" => "https://example.com/redirected"},
336338
body: {}
@@ -361,7 +363,7 @@ def test_client_redirect_auth_strip_cross_origin
361363
end
362364

363365
def test_default_headers
364-
stub_request(:get, "http://localhost/x/tweets/search").to_return_json(status: 200, body: {})
366+
stub_request(:get, TWEET_SEARCH_URL).to_return_json(status: 200, body: {})
365367

366368
x_twitter_scraper =
367369
XTwitterScraper::Client.new(

0 commit comments

Comments
 (0)