git-trend 1.3.0 → 1.4.1

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.
@@ -1,5 +1,5 @@
1
- # rubocop:disable Style/TrailingWhitespace
2
- include GitTrend
1
+ require "git_trend/scraper"
2
+
3
3
  RSpec.describe GitTrend::CLI do
4
4
  shared_examples "since daily ranking" do |since|
5
5
  it "display daily ranking" do
@@ -20,28 +20,32 @@ RSpec.describe GitTrend::CLI do
20
20
  end
21
21
 
22
22
  describe "#list" do
23
- let(:cli) { CLI.new }
23
+ let(:cli) { described_class.new }
24
24
 
25
25
  describe "with -n option" do
26
26
  context "with 3" do
27
27
  before { stub_request_get("trending") }
28
+
28
29
  let(:number) { 3 }
30
+
29
31
  it "display top 3 daily ranking" do
30
- res = <<-'EOS'.unindent
32
+ res = <<-OUTPUT.unindent
31
33
  |No. Name Lang Star
32
34
  |--- ---------------------------------------- ---------------- ------
33
35
  | 1 linexjlin/GPTs 445
34
36
  | 2 ml-explore/mlx-examples Python 161
35
37
  | 3 PRIS-CV/DemoFusion Jupyter Notebook 169
36
38
 
37
- EOS
39
+ OUTPUT
38
40
  expect { cli.invoke(:list, [], number: number, description: false) }.to output(res).to_stdout
39
41
  end
40
42
  end
41
43
 
42
44
  context "with over 25" do
43
45
  before { stub_request_get("trending") }
46
+
44
47
  let(:number) { 26 }
48
+
45
49
  it "display daily ranking" do
46
50
  expect { cli.invoke(:list, [], number: number, description: false) }.to output(dummy_result_without_description).to_stdout
47
51
  end
@@ -51,10 +55,11 @@ RSpec.describe GitTrend::CLI do
51
55
  describe "with -l option" do
52
56
  context "with ruby" do
53
57
  before { stub_request_get("trending/#{language}") }
58
+
54
59
  let(:language) { "ruby" }
55
60
 
56
61
  it "display daily ranking by language" do
57
- res = <<-'EOS'.unindent
62
+ res = <<-OUTPUT.unindent
58
63
  |No. Name Lang Star
59
64
  |--- ---------------------------------------- ---------- ------
60
65
  | 1 greatghoul/remote-working Ruby 34
@@ -83,20 +88,21 @@ RSpec.describe GitTrend::CLI do
83
88
  | 24 chef/chef Ruby 0
84
89
  | 25 instructure/canvas-lms Ruby 0
85
90
 
86
- EOS
91
+ OUTPUT
87
92
  expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout
88
93
  end
89
94
  end
90
95
 
91
96
  context "with alloy : when trending is nothing" do
92
97
  before { stub_request_get("trending/#{language}") }
98
+
93
99
  let(:language) { "alloy" }
94
100
 
95
101
  it "display the 0cases message" do
96
- res = <<-'EOS'.unindent
102
+ res = <<-OUTPUT.unindent
97
103
  |It looks like we don’t have any trending repositories.
98
104
 
99
- EOS
105
+ OUTPUT
100
106
  expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout
101
107
  end
102
108
  end
@@ -105,51 +111,55 @@ RSpec.describe GitTrend::CLI do
105
111
  describe "with -s option" do
106
112
  context "with no option" do
107
113
  before { stub_request_get("trending?since=") }
108
- include_examples "since daily ranking", ""
114
+
115
+ it_behaves_like "since daily ranking", ""
109
116
  end
110
117
 
111
118
  describe "since daily" do
112
119
  before { stub_request_get("trending?since=daily") }
120
+
113
121
  context "with d" do
114
- include_examples "since daily ranking", "d"
122
+ it_behaves_like "since daily ranking", "d"
115
123
  end
116
124
 
117
125
  context "with day" do
118
- include_examples "since daily ranking", "day"
126
+ it_behaves_like "since daily ranking", "day"
119
127
  end
120
128
 
121
129
  context "with daily" do
122
- include_examples "since daily ranking", "daily"
130
+ it_behaves_like "since daily ranking", "daily"
123
131
  end
124
132
  end
125
133
 
126
134
  describe "since weekly" do
127
135
  before { stub_request_get("trending?since=weekly") }
136
+
128
137
  context "with w" do
129
- include_examples "since weekly ranking", "w"
138
+ it_behaves_like "since weekly ranking", "w"
130
139
  end
131
140
 
132
141
  context "with week" do
133
- include_examples "since weekly ranking", "week"
142
+ it_behaves_like "since weekly ranking", "week"
134
143
  end
135
144
 
136
145
  context "with weekly" do
137
- include_examples "since weekly ranking", "weekly"
146
+ it_behaves_like "since weekly ranking", "weekly"
138
147
  end
139
148
  end
140
149
 
141
150
  describe "since monthly" do
142
151
  before { stub_request_get("trending?since=monthly") }
152
+
143
153
  context "with m" do
144
- include_examples "since monthly ranking", "m"
154
+ it_behaves_like "since monthly ranking", "m"
145
155
  end
146
156
 
147
157
  context "with month" do
148
- include_examples "since monthly ranking", "month"
158
+ it_behaves_like "since monthly ranking", "month"
149
159
  end
150
160
 
151
161
  context "with monthly" do
152
- include_examples "since monthly ranking", "monthly"
162
+ it_behaves_like "since monthly ranking", "monthly"
153
163
  end
154
164
  end
155
165
  end
@@ -193,11 +203,12 @@ RSpec.describe GitTrend::CLI do
193
203
  describe "with -l and -s option" do
194
204
  context "with ruby and weekly" do
195
205
  before { stub_request_get("trending/#{language}?since=#{since}") }
206
+
196
207
  let(:language) { "ruby" }
197
208
  let(:since) { "weekly" }
198
209
 
199
210
  it "display weekly ranking by language" do
200
- res = <<-'EOS'.unindent
211
+ res = <<-OUTPUT.unindent
201
212
  |No. Name Lang Star
202
213
  |--- ---------------------------------------- ---------- ------
203
214
  | 1 mastodon/mastodon Ruby 115
@@ -226,7 +237,7 @@ RSpec.describe GitTrend::CLI do
226
237
  | 24 rubocop/rubocop Ruby 10
227
238
  | 25 paper-trail-gem/paper_trail Ruby 3
228
239
 
229
- EOS
240
+ OUTPUT
230
241
  expect { cli.invoke(:list, [], language: language, since: since, description: false) }.to output(res).to_stdout
231
242
  end
232
243
  end
@@ -235,18 +246,20 @@ RSpec.describe GitTrend::CLI do
235
246
 
236
247
  describe "#languages" do
237
248
  before { stub_request_get("trending") }
238
- let(:cli) { CLI.new }
249
+
250
+ let(:cli) { described_class.new }
239
251
 
240
252
  context "with no option" do
241
253
  it "display languages" do
242
- expect { cli.languages }.to output(match("C++").and match("HTML").and match("Ruby")).to_stdout
254
+ expect { cli.languages }.to output(include("C++", "HTML", "Ruby")).to_stdout
243
255
  end
244
256
  end
245
257
  end
246
258
 
247
259
  private
260
+
248
261
  def stub_request_get(stub_url_path, stub_file_name = nil)
249
- url = Scraper::BASE_HOST.dup
262
+ url = GitTrend::Scraper::BASE_HOST.dup
250
263
  url << "/#{stub_url_path}" if stub_url_path
251
264
  uri = URI.parse(url)
252
265
  stub_file = stub_file_name || stub_url_path
@@ -254,11 +267,12 @@ RSpec.describe GitTrend::CLI do
254
267
  .to_return(
255
268
  status: 200,
256
269
  headers: { content_type: "text/html" },
257
- body: load_http_stub(stub_file))
270
+ body: load_http_stub(stub_file)
271
+ )
258
272
  end
259
273
 
260
274
  def dummy_result_without_description
261
- <<-'EOS'.unindent
275
+ <<-OUTPUT.unindent
262
276
  |No. Name Lang Star
263
277
  |--- ------------------------------------------ ---------------- ------
264
278
  | 1 linexjlin/GPTs 445
@@ -287,11 +301,11 @@ RSpec.describe GitTrend::CLI do
287
301
  | 24 ytdl-org/youtube-dl Python 24
288
302
  | 25 dunglas/frankenphp Go 53
289
303
 
290
- EOS
304
+ OUTPUT
291
305
  end
292
306
 
293
307
  def dummy_result_no_options
294
- <<-'EOS'.unindent
308
+ <<-OUTPUT.unindent
295
309
  |No. Name Lang Star Description
296
310
  |--- ------------------------------------------ ---------------- ------ ---------------------------------------------------------------------
297
311
  | 1 linexjlin/GPTs 445 leaked prompts of GPTs
@@ -320,11 +334,11 @@ RSpec.describe GitTrend::CLI do
320
334
  | 24 ytdl-org/youtube-dl Python 24 Command-line program to download videos from YouTube.com and other...
321
335
  | 25 dunglas/frankenphp Go 53 The modern PHP app server
322
336
 
323
- EOS
337
+ OUTPUT
324
338
  end
325
339
 
326
340
  def dummy_weekly_result
327
- <<-'EOS'.unindent
341
+ <<-OUTPUT.unindent
328
342
  |No. Name Lang Star
329
343
  |--- ------------------------------------------ ---------------- ------
330
344
  | 1 LC044/WeChatMsg Python 10719
@@ -353,11 +367,11 @@ RSpec.describe GitTrend::CLI do
353
367
  | 24 coolsnowwolf/lede C 132
354
368
  | 25 QwenLM/Qwen Python 377
355
369
 
356
- EOS
370
+ OUTPUT
357
371
  end
358
372
 
359
373
  def dummy_monthly_result
360
- <<-'EOS'.unindent
374
+ <<-OUTPUT.unindent
361
375
  |No. Name Lang Star
362
376
  |--- ---------------------------------------- ---------------- ------
363
377
  | 1 SawyerHood/draw-a-ui TypeScript 11761
@@ -386,6 +400,6 @@ RSpec.describe GitTrend::CLI do
386
400
  | 24 SillyTavern/SillyTavern JavaScript 1566
387
401
  | 25 1Panel-dev/1Panel Go 1950
388
402
 
389
- EOS
403
+ OUTPUT
390
404
  end
391
405
  end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.shared_examples_for "without_options" do |examples|
4
+ examples.each do |example|
5
+ input = example[:inputs]
6
+ it "#{example[:object].inspect}.mb_truncate(#{input}) should return #{example[:expected].inspect}" do
7
+ expect(example[:object].send(:mb_truncate, input)).to eq example[:expected]
8
+ end
9
+ end
10
+ end
11
+
12
+ RSpec.describe String do
13
+ describe "#mb_truncate" do
14
+ context "ascii strings" do
15
+ examples = [
16
+ { object: "abc", inputs: 2, expected: "..." },
17
+ { object: "abc", inputs: 3, expected: "abc" },
18
+ { object: "abcde", inputs: 3, expected: "..." },
19
+ { object: "abcde", inputs: 4, expected: "a..." },
20
+ { object: "abcde", inputs: 5, expected: "abcde" },
21
+ ]
22
+ it_behaves_like "without_options", examples
23
+ end
24
+
25
+ context "multi-bytes strings" do
26
+ examples = [
27
+ { object: "あいう", inputs: 2, expected: "..." },
28
+ { object: "あいう", inputs: 3, expected: "..." },
29
+ { object: "あいう", inputs: 4, expected: "..." },
30
+ { object: "あいう", inputs: 5, expected: "あ..." },
31
+ { object: "あいう", inputs: 6, expected: "あいう" },
32
+ ]
33
+ it_behaves_like "without_options", examples
34
+ end
35
+ end
36
+ end
@@ -1,17 +1,21 @@
1
- include GitTrend
1
+ include GitTrend # rubocop:disable Style/MixinUsage
2
+
2
3
  RSpec.describe GitTrend::Scraper do
3
4
  let(:scraper) { Scraper.new }
4
5
 
5
6
  describe "settings" do
7
+ subject { scraper.instance_variable_get(:@agent) }
8
+
6
9
  before do
7
10
  allow(ENV).to receive(:[]).with("http_proxy").and_return("http://#{proxy_user}:#{proxy_pass}@#{proxy_addr}:#{proxy_port}")
8
11
  end
12
+
9
13
  let(:proxy_addr) { "192.168.1.99" }
10
14
  let(:proxy_port) { 9999 }
11
15
  let(:proxy_user) { "proxy_user" }
12
16
  let(:proxy_pass) { "proxy_pass" }
13
- subject { scraper.instance_variable_get(:@agent) }
14
- it "should use proxy settings of ENV" do
17
+
18
+ it "uses proxy settings of ENV" do
15
19
  aggregate_failures do
16
20
  expect(subject.proxy_addr).to eq proxy_addr
17
21
  expect(subject.proxy_user).to eq proxy_user
@@ -28,6 +32,7 @@ RSpec.describe GitTrend::Scraper do
28
32
  stub_request(:get, Scraper::BASE_URL)
29
33
  .to_return(status: 500, body: "[]")
30
34
  end
35
+
31
36
  it { expect { scraper.get }.to raise_error(Exception) }
32
37
  end
33
38
  end
@@ -1,81 +1,98 @@
1
1
  RSpec.describe GitTrend do
2
+ include described_class
3
+
4
+ let(:scraper_mock) { instance_double(Scraper) }
5
+
2
6
  before do
7
+ allow(Scraper).to receive(:new).and_return(scraper_mock)
3
8
  stub_request(:get, /.*/)
4
9
  .to_return(status: 200, headers: { content_type: "text/html" }, body: load_http_stub("trending"))
5
10
  end
6
11
 
7
12
  describe "#get" do
8
- context "without options" do
9
- it "Scraper#get call without options" do
10
- expect_any_instance_of(Scraper).to receive(:get).with(no_args)
11
- GitTrend.get
13
+ context "normal" do
14
+ before do
15
+ allow(scraper_mock).to receive(:get)
12
16
  end
13
- end
14
17
 
15
- context "parameter is 'ruby'" do
16
- it "Scraper#get call with 'ruby'" do
17
- expect_any_instance_of(Scraper).to receive(:get).with("ruby")
18
- GitTrend.get("ruby")
18
+ context "without options" do
19
+ it "Scraper#get call without options" do
20
+ described_class.get
21
+ expect(scraper_mock).to have_received(:get).with(no_args)
22
+ end
19
23
  end
20
- end
21
24
 
22
- context "parameter is :ruby" do
23
- it "Scraper#get call with :ruby" do
24
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby)
25
- GitTrend.get(:ruby)
25
+ context "parameter is 'ruby'" do
26
+ it "Scraper#get call with 'ruby'" do
27
+ described_class.get("ruby")
28
+ expect(scraper_mock).to have_received(:get).with("ruby")
29
+ end
26
30
  end
27
- end
28
31
 
29
- context "parameter is since: :weekly" do
30
- it "Scraper#get call with [nil, :weekly]" do
31
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :weekly)
32
- GitTrend.get(since: :weekly)
32
+ context "parameter is :ruby" do
33
+ it "Scraper#get call with :ruby" do
34
+ described_class.get(:ruby)
35
+ expect(scraper_mock).to have_received(:get).with(:ruby)
36
+ end
33
37
  end
34
- end
35
38
 
36
- context "parameter is since: :week" do
37
- it "Scraper#get call with [nil, :week]" do
38
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :week)
39
- GitTrend.get(since: :week)
39
+ context "parameter is since: :weekly" do
40
+ it "Scraper#get call with [nil, :weekly]" do
41
+ described_class.get(since: :weekly)
42
+ expect(scraper_mock).to have_received(:get).with(nil, :weekly)
43
+ end
40
44
  end
41
- end
42
45
 
43
- context "parameter is since: :w" do
44
- it "Scraper#get call with [nil, :w]" do
45
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :w)
46
- GitTrend.get(since: :w)
46
+ context "parameter is since: :week" do
47
+ it "Scraper#get call with [nil, :week]" do
48
+ described_class.get(since: :week)
49
+ expect(scraper_mock).to have_received(:get).with(nil, :week)
50
+ end
47
51
  end
48
- end
49
52
 
50
- context "parameters are 'ruby', 'weekly'" do
51
- it "Scraper#get call with ['ruby', 'weekly']" do
52
- expect_any_instance_of(Scraper).to receive(:get).with("ruby", "weekly")
53
- GitTrend.get("ruby", "weekly")
53
+ context "parameter is since: :w" do
54
+ it "Scraper#get call with [nil, :w]" do
55
+ described_class.get(since: :w)
56
+ expect(scraper_mock).to have_received(:get).with(nil, :w)
57
+ end
54
58
  end
55
- end
56
59
 
57
- context "parameters are :ruby, :weekly" do
58
- it "Scraper#get call with [:ruby, :weekly]" do
59
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby, :weekly)
60
- GitTrend.get(:ruby, :weekly)
60
+ context "parameters are 'ruby', 'weekly'" do
61
+ it "Scraper#get call with ['ruby', 'weekly']" do
62
+ described_class.get("ruby", "weekly")
63
+ expect(scraper_mock).to have_received(:get).with("ruby", "weekly")
64
+ end
65
+ end
66
+
67
+ context "parameters are :ruby, :weekly" do
68
+ it "Scraper#get call with [:ruby, :weekly]" do
69
+ described_class.get(:ruby, :weekly)
70
+ expect(scraper_mock).to have_received(:get).with(:ruby, :weekly)
71
+ end
61
72
  end
62
- end
63
73
 
64
- context "parameters are language: :ruby, since: :weekly" do
65
- it "Scraper#get call with [:ruby, :weekly]" do
66
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby, :weekly)
67
- GitTrend.get(language: :ruby, since: :weekly)
74
+ context "parameters are language: :ruby, since: :weekly" do
75
+ it "Scraper#get call with [:ruby, :weekly]" do
76
+ described_class.get(language: :ruby, since: :weekly)
77
+ expect(scraper_mock).to have_received(:get).with(:ruby, :weekly)
78
+ end
68
79
  end
69
80
  end
70
81
 
71
- context "when too many parameters" do
72
- it { expect { GitTrend.get("ruby", "weekly", "many_params") }.to raise_error(Exception) }
82
+ context "abnormal" do
83
+ context "when too many parameters" do
84
+ it { expect { described_class.get("ruby", "weekly", "many_params") }.to raise_error(Exception) }
85
+ end
73
86
  end
74
87
 
75
88
  describe "#languages" do
89
+ before do
90
+ allow(scraper_mock).to receive(:languages)
91
+ end
92
+
76
93
  it "Scraper#languages call" do
77
- expect_any_instance_of(Scraper).to receive(:languages).with(no_args)
78
- GitTrend.languages
94
+ described_class.languages
95
+ expect(scraper_mock).to have_received(:languages).with(no_args)
79
96
  end
80
97
  end
81
98
  end
data/spec/spec_helper.rb CHANGED
@@ -14,25 +14,14 @@
14
14
  # users commonly want.
15
15
  #
16
16
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
- # require "coveralls"
18
- # Coveralls.wear!
19
-
20
17
  require "simplecov"
21
- require "webmock/rspec"
22
- require "git_trend"
23
-
24
- # require "codeclimate-test-reporter"
25
- dir = File.join(ENV["CIRCLE_ARTIFACTS"] || "coverage")
26
- SimpleCov.coverage_dir(dir)
27
18
  SimpleCov.start do
28
19
  add_filter "/spec/"
29
-
30
- formatter SimpleCov::Formatter::MultiFormatter.new([
31
- SimpleCov::Formatter::HTMLFormatter,
32
- # Coveralls::SimpleCov::Formatter
33
- ])
34
20
  end
35
21
 
22
+ require "webmock/rspec"
23
+ require "git_trend"
24
+
36
25
  RSpec.configure do |config|
37
26
  config.expect_with :rspec do |expectations|
38
27
  expectations.syntax = :expect