git-trend 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +4 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +101 -0
- data/Rakefile +6 -0
- data/bin/git-trend +7 -0
- data/git-trend.gemspec +31 -0
- data/lib/git_trend.rb +7 -0
- data/lib/git_trend/cli.rb +33 -0
- data/lib/git_trend/project.rb +9 -0
- data/lib/git_trend/rendering.rb +44 -0
- data/lib/git_trend/scraper.rb +59 -0
- data/lib/git_trend/version.rb +3 -0
- data/spec/fixtures/trending +1938 -0
- data/spec/fixtures/trending?l=objective-c++ +1923 -0
- data/spec/fixtures/trending?l=ruby +1975 -0
- data/spec/git_trend/scraper_spec.rb +372 -0
- data/spec/spec_helper.rb +98 -0
- metadata +182 -0
@@ -0,0 +1,372 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include GitTrend
|
4
|
+
RSpec.describe GitTrend::Scraper do
|
5
|
+
|
6
|
+
describe 'proxy settings' do
|
7
|
+
before do
|
8
|
+
allow(ENV).to receive(:[]).with('http_proxy').and_return('http://proxy_user:proxy_pass@192.168.1.99:9999')
|
9
|
+
@scraper = Scraper.new
|
10
|
+
end
|
11
|
+
subject { @scraper.instance_variable_get(:@agent) }
|
12
|
+
its(:proxy_addr) { should eq '192.168.1.99' }
|
13
|
+
its(:proxy_user) { should eq 'proxy_user' }
|
14
|
+
its(:proxy_pass) { should eq 'proxy_pass' }
|
15
|
+
its(:proxy_port) { should eq 9999 }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#get' do
|
19
|
+
after do
|
20
|
+
# reset initialize
|
21
|
+
# warning measure: already initialized constant
|
22
|
+
[3, 40, 6, 5].each_with_index { |n, i| Rendering::DEFAULT_RULED_LINE_SIZE[i] = n }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when a network error occurred' do
|
26
|
+
before do
|
27
|
+
stub_request(:get, Scraper::BASE_URL).
|
28
|
+
to_return(:status => 500, :body => '[]')
|
29
|
+
end
|
30
|
+
let(:language) {nil}
|
31
|
+
it { expect{ @scraper.get(language) }.to raise_error(Exception) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with no option' do
|
35
|
+
before do
|
36
|
+
@scraper = Scraper.new
|
37
|
+
stub_request_get('trending')
|
38
|
+
end
|
39
|
+
let(:language) {nil}
|
40
|
+
|
41
|
+
it 'display daily ranking' do
|
42
|
+
res = <<-'EOS'.unindent
|
43
|
+
|No. Name Star Fork
|
44
|
+
|--- -------------------------------------------------- ------ -----
|
45
|
+
| 1 prat0318/json_resume 264 15
|
46
|
+
| 2 andlabs/ui 185 8
|
47
|
+
| 3 jessepollak/card 174 9
|
48
|
+
| 4 fullstackio/FlappySwift 148 44
|
49
|
+
| 5 grant/swift-cheat-sheet 153 13
|
50
|
+
| 6 Flolagale/mailin 155 3
|
51
|
+
| 7 numbbbbb/the-swift-programming-language-in-chinese 120 31
|
52
|
+
| 8 hippyvm/hippyvm 113 1
|
53
|
+
| 9 neovim/neovim 83 8
|
54
|
+
| 10 hiphopapp/hiphop 77 8
|
55
|
+
| 11 interagent/http-api-design 78 4
|
56
|
+
| 12 austinzheng/swift-2048 69 16
|
57
|
+
| 13 mdznr/What-s-New 72 2
|
58
|
+
| 14 daneden/animate.css 65 6
|
59
|
+
| 15 davidmerfield/randomColor 66 3
|
60
|
+
| 16 dawn/dawn 62 2
|
61
|
+
| 17 greatfire/wiki 54 9
|
62
|
+
| 18 swift-jp/swift-guide 45 9
|
63
|
+
| 19 addyosmani/psi 49 0
|
64
|
+
| 20 mtford90/silk 47 0
|
65
|
+
| 21 agaue/agaue 47 0
|
66
|
+
| 22 mentionapp/mntpulltoreact 46 1
|
67
|
+
| 23 mikepenz/AboutLibraries 45 0
|
68
|
+
| 24 PistonDevelopers/piston-workspace 45 0
|
69
|
+
| 25 maxpow4h/swiftz 43 1
|
70
|
+
EOS
|
71
|
+
expect { @scraper.get(language) }.to output(res).to_stdout
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'with -l option' do
|
76
|
+
context 'with ruby' do
|
77
|
+
before do
|
78
|
+
@scraper = Scraper.new
|
79
|
+
stub_request_get("trending?l=#{language}")
|
80
|
+
end
|
81
|
+
let(:language) {'ruby'}
|
82
|
+
|
83
|
+
it 'display daily ranking by language' do
|
84
|
+
res = <<-'EOS'.unindent
|
85
|
+
|No. Name Star Fork
|
86
|
+
|--- ---------------------------------------- ------ -----
|
87
|
+
| 1 prat0318/json_resume 412 27
|
88
|
+
| 2 dawn/dawn 57 2
|
89
|
+
| 3 Homebrew/homebrew 15 7
|
90
|
+
| 4 etsy/nagios-herald 18 0
|
91
|
+
| 5 jekyll/jekyll 14 4
|
92
|
+
| 6 opf/openproject 11 0
|
93
|
+
| 7 caskroom/homebrew-cask 9 3
|
94
|
+
| 8 rails/rails 6 7
|
95
|
+
| 9 interagent/prmd 9 0
|
96
|
+
| 10 mitchellh/vagrant 8 2
|
97
|
+
| 11 discourse/discourse 7 3
|
98
|
+
| 12 CanCanCommunity/cancancan 7 1
|
99
|
+
| 13 venmo/synx 7 0
|
100
|
+
| 14 laravel/homestead 6 2
|
101
|
+
| 15 alexreisner/geocoder 6 0
|
102
|
+
| 16 visionmedia/commander 5 0
|
103
|
+
| 17 CocoaPods/Specs 0 3
|
104
|
+
| 18 gitlabhq/gitlabhq 0 2
|
105
|
+
| 19 puppetlabs/puppetlabs-apache 0 2
|
106
|
+
| 20 gitlabhq/gitlab-recipes 0 2
|
107
|
+
| 21 Mixd/wp-deploy 0 1
|
108
|
+
| 22 svenfuchs/rails-i18n 0 1
|
109
|
+
| 23 Homebrew/homebrew-php 0 1
|
110
|
+
| 24 sferik/twitter 0 1
|
111
|
+
| 25 rightscale/rightscale_cookbooks 0 1
|
112
|
+
EOS
|
113
|
+
expect { @scraper.get(language) }.to output(res).to_stdout
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'with objective-c++ (including + sign)' do
|
118
|
+
before do
|
119
|
+
@scraper = Scraper.new
|
120
|
+
stub_request_get("trending?l=#{language}")
|
121
|
+
end
|
122
|
+
let(:language) {'objective-c++'}
|
123
|
+
|
124
|
+
it 'display daily ranking by language' do
|
125
|
+
res = <<-'EOS'.unindent
|
126
|
+
|No. Name Star Fork
|
127
|
+
|--- ---------------------------------------- ------ -----
|
128
|
+
| 1 facebook/pop 0 0
|
129
|
+
| 2 johnno1962/Xtrace 0 0
|
130
|
+
| 3 pivotal/cedar 0 0
|
131
|
+
| 4 wetube/bitcloud 0 0
|
132
|
+
| 5 jerols/PopTut 0 0
|
133
|
+
| 6 otaviocc/OCBorghettiView 0 0
|
134
|
+
| 7 droolsjbpm/optaplanner 0 0
|
135
|
+
| 8 otaviocc/NHCalendarActivity 0 0
|
136
|
+
| 9 callmeed/pop-playground 0 0
|
137
|
+
| 10 jxd001/POPdemo 0 0
|
138
|
+
| 11 couchdeveloper/RXPromise 0 0
|
139
|
+
| 12 johnno1962/XprobePlugin 0 0
|
140
|
+
| 13 openpeer/opios 0 0
|
141
|
+
| 14 pivotal/PivotalCoreKit 0 0
|
142
|
+
| 15 rbaumbach/Swizzlean 0 0
|
143
|
+
| 16 andreacremaschi/ShapeKit 0 0
|
144
|
+
| 17 Smartype/iOS_VPNPlugIn 0 0
|
145
|
+
| 18 humblehacker/AutoLayoutDSL 0 0
|
146
|
+
| 19 hoddez/FFTAccelerate 0 0
|
147
|
+
| 20 armadillu/ofxPanZoom 0 0
|
148
|
+
| 21 dodikk/CsvToSqlite 0 0
|
149
|
+
| 22 hbang/TypeStatus 0 0
|
150
|
+
| 23 trentbrooks/ofxCoreMotion 0 0
|
151
|
+
| 24 Yonsm/CeleWare 0 0
|
152
|
+
| 25 ccrma/miniAudicle 0 0
|
153
|
+
EOS
|
154
|
+
expect { @scraper.get(language) }.to output(res).to_stdout
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#list_all_languages' do
|
161
|
+
before do
|
162
|
+
@scraper = Scraper.new
|
163
|
+
stub_request_get('trending')
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'with no option' do
|
167
|
+
it 'display daily ranking' do
|
168
|
+
res = <<-'EOS'.unindent
|
169
|
+
|abap
|
170
|
+
|as3
|
171
|
+
|ada
|
172
|
+
|agda
|
173
|
+
|alloy
|
174
|
+
|antlr
|
175
|
+
|apex
|
176
|
+
|applescript
|
177
|
+
|arc
|
178
|
+
|arduino
|
179
|
+
|aspx-vb
|
180
|
+
|aspectj
|
181
|
+
|nasm
|
182
|
+
|ats
|
183
|
+
|augeas
|
184
|
+
|autohotkey
|
185
|
+
|autoit
|
186
|
+
|awk
|
187
|
+
|blitzbasic
|
188
|
+
|bluespec
|
189
|
+
|boo
|
190
|
+
|brightscript
|
191
|
+
|bro
|
192
|
+
|c
|
193
|
+
|csharp
|
194
|
+
|cpp
|
195
|
+
|ceylon
|
196
|
+
|cirru
|
197
|
+
|clean
|
198
|
+
|clips
|
199
|
+
|clojure
|
200
|
+
|cobol
|
201
|
+
|coffeescript
|
202
|
+
|cfm
|
203
|
+
|common-lisp
|
204
|
+
|coq
|
205
|
+
|crystal
|
206
|
+
|css
|
207
|
+
|cuda
|
208
|
+
|d
|
209
|
+
|dart
|
210
|
+
|dcpu-16-asm
|
211
|
+
|dm
|
212
|
+
|dogescript
|
213
|
+
|dot
|
214
|
+
|dylan
|
215
|
+
|e
|
216
|
+
|ec
|
217
|
+
|eiffel
|
218
|
+
|elixir
|
219
|
+
|elm
|
220
|
+
|emacs-lisp
|
221
|
+
|erlang
|
222
|
+
|fsharp
|
223
|
+
|factor
|
224
|
+
|fancy
|
225
|
+
|fantom
|
226
|
+
|flux
|
227
|
+
|forth
|
228
|
+
|fortran
|
229
|
+
|frege
|
230
|
+
|game-maker-language
|
231
|
+
|gams
|
232
|
+
|gap
|
233
|
+
|glyph
|
234
|
+
|gnuplot
|
235
|
+
|go
|
236
|
+
|gosu
|
237
|
+
|grammatical-framework
|
238
|
+
|groovy
|
239
|
+
|harbour
|
240
|
+
|haskell
|
241
|
+
|haxe
|
242
|
+
|hy
|
243
|
+
|idl
|
244
|
+
|idris
|
245
|
+
|inform-7
|
246
|
+
|io
|
247
|
+
|ioke
|
248
|
+
|j
|
249
|
+
|java
|
250
|
+
|javascript
|
251
|
+
|jsoniq
|
252
|
+
|julia
|
253
|
+
|kotlin
|
254
|
+
|krl
|
255
|
+
|lasso
|
256
|
+
|livescript
|
257
|
+
|logos
|
258
|
+
|logtalk
|
259
|
+
|lua
|
260
|
+
|m
|
261
|
+
|markdown
|
262
|
+
|mathematica
|
263
|
+
|matlab
|
264
|
+
|max/msp
|
265
|
+
|mercury
|
266
|
+
|ruby
|
267
|
+
|monkey
|
268
|
+
|moocode
|
269
|
+
|moonscript
|
270
|
+
|nemerle
|
271
|
+
|nesc
|
272
|
+
|netlogo
|
273
|
+
|nimrod
|
274
|
+
|nu
|
275
|
+
|objective-c
|
276
|
+
|objective-c++
|
277
|
+
|objective-j
|
278
|
+
|ocaml
|
279
|
+
|omgrofl
|
280
|
+
|ooc
|
281
|
+
|opa
|
282
|
+
|openedge-abl
|
283
|
+
|oxygene
|
284
|
+
|pan
|
285
|
+
|parrot
|
286
|
+
|pascal
|
287
|
+
|pawn
|
288
|
+
|perl
|
289
|
+
|perl6
|
290
|
+
|php
|
291
|
+
|pike
|
292
|
+
|pogoscript
|
293
|
+
|powershell
|
294
|
+
|processing
|
295
|
+
|prolog
|
296
|
+
|propeller-spin
|
297
|
+
|puppet
|
298
|
+
|pure-data
|
299
|
+
|purescript
|
300
|
+
|python
|
301
|
+
|r
|
302
|
+
|racket
|
303
|
+
|ragel-in-ruby-host
|
304
|
+
|rdoc
|
305
|
+
|realbasic
|
306
|
+
|rebol
|
307
|
+
|red
|
308
|
+
|robotframework
|
309
|
+
|rouge
|
310
|
+
|ruby
|
311
|
+
|rust
|
312
|
+
|sas
|
313
|
+
|scala
|
314
|
+
|scheme
|
315
|
+
|scilab
|
316
|
+
|self
|
317
|
+
|bash
|
318
|
+
|shellsession
|
319
|
+
|shen
|
320
|
+
|slash
|
321
|
+
|smalltalk
|
322
|
+
|sourcepawn
|
323
|
+
|sql
|
324
|
+
|squirrel
|
325
|
+
|standard-ml
|
326
|
+
|stata
|
327
|
+
|supercollider
|
328
|
+
|swift
|
329
|
+
|systemverilog
|
330
|
+
|tcl
|
331
|
+
|tex
|
332
|
+
|turing
|
333
|
+
|txl
|
334
|
+
|typescript
|
335
|
+
|unrealscript
|
336
|
+
|vala
|
337
|
+
|verilog
|
338
|
+
|vhdl
|
339
|
+
|vim
|
340
|
+
|visual-basic
|
341
|
+
|volt
|
342
|
+
|wisp
|
343
|
+
|xbase
|
344
|
+
|xc
|
345
|
+
|xml
|
346
|
+
|xproc
|
347
|
+
|xquery
|
348
|
+
|xslt
|
349
|
+
|xtend
|
350
|
+
|zephir
|
351
|
+
|zimpl
|
352
|
+
|
|
353
|
+
|183 languages
|
354
|
+
|you can get only selected language list with '-l' option
|
355
|
+
EOS
|
356
|
+
expect { @scraper.list_all_languages }.to output(res).to_stdout
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
private
|
362
|
+
def stub_request_get(stub_file)
|
363
|
+
params = stub_file.match(/trending\?(.+)/).to_a[1]
|
364
|
+
url = "#{Scraper::BASE_URL}"
|
365
|
+
url << "?#{CGI.escape(params)}" if params
|
366
|
+
stub_request(:get, url).
|
367
|
+
to_return(
|
368
|
+
:status => 200,
|
369
|
+
:headers => {content_type: 'text/html'},
|
370
|
+
:body => load_http_stub(stub_file))
|
371
|
+
end
|
372
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require 'rspec/its'
|
18
|
+
require 'webmock/rspec'
|
19
|
+
|
20
|
+
require 'simplecov'
|
21
|
+
require 'git_trend'
|
22
|
+
SimpleCov.start
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.expose_dsl_globally = false
|
26
|
+
config.order = :random
|
27
|
+
# The settings below are suggested to provide a good initial experience
|
28
|
+
# with RSpec, but feel free to customize to your heart's content.
|
29
|
+
=begin
|
30
|
+
# These two settings work together to allow you to limit a spec run
|
31
|
+
# to individual examples or groups you care about by tagging them with
|
32
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
33
|
+
# get run.
|
34
|
+
config.filter_run :focus
|
35
|
+
config.run_all_when_everything_filtered = true
|
36
|
+
|
37
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
38
|
+
# file, and it's useful to allow more verbose output when running an
|
39
|
+
# individual spec file.
|
40
|
+
if config.files_to_run.one?
|
41
|
+
# Use the documentation formatter for detailed output,
|
42
|
+
# unless a formatter has already been configured
|
43
|
+
# (e.g. via a command-line flag).
|
44
|
+
config.default_formatter = 'doc'
|
45
|
+
end
|
46
|
+
|
47
|
+
# Print the 10 slowest examples and example groups at the
|
48
|
+
# end of the spec run, to help surface which specs are running
|
49
|
+
# particularly slow.
|
50
|
+
config.profile_examples = 10
|
51
|
+
|
52
|
+
# Run specs in random order to surface order dependencies. If you find an
|
53
|
+
# order dependency and want to debug it, you can fix the order by providing
|
54
|
+
# the seed, which is printed after each run.
|
55
|
+
# --seed 1234
|
56
|
+
config.order = :random
|
57
|
+
|
58
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
59
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
60
|
+
# test failures related to randomization by passing the same `--seed` value
|
61
|
+
# as the one that triggered the failure.
|
62
|
+
Kernel.srand config.seed
|
63
|
+
|
64
|
+
# rspec-expectations config goes here. You can use an alternate
|
65
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
66
|
+
# assertions if you prefer.
|
67
|
+
config.expect_with :rspec do |expectations|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
71
|
+
expectations.syntax = :expect
|
72
|
+
end
|
73
|
+
|
74
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
75
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
76
|
+
config.mock_with :rspec do |mocks|
|
77
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
78
|
+
# For more details, see:
|
79
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
80
|
+
mocks.syntax = :expect
|
81
|
+
|
82
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
83
|
+
# a real object. This is generally recommended.
|
84
|
+
mocks.verify_partial_doubles = true
|
85
|
+
end
|
86
|
+
=end
|
87
|
+
end
|
88
|
+
|
89
|
+
def load_http_stub(file_name)
|
90
|
+
file_path = File.join(File.dirname(__FILE__), 'fixtures', file_name)
|
91
|
+
File.read(file_path)
|
92
|
+
end
|
93
|
+
|
94
|
+
class String
|
95
|
+
def unindent
|
96
|
+
gsub(/^\s+\|/, '')
|
97
|
+
end
|
98
|
+
end
|