git-trend 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,11 @@
1
- require 'spec_helper'
2
-
3
- include GitTrend
4
1
  RSpec.describe GitTrend::Scraper do
2
+ let(:scraper) { Scraper.new }
5
3
 
6
4
  describe 'settings' do
7
5
  before do
8
6
  allow(ENV).to receive(:[]).with('http_proxy').and_return('http://proxy_user:proxy_pass@192.168.1.99:9999')
9
- @scraper = Scraper.new
10
7
  end
11
- subject { @scraper.instance_variable_get(:@agent) }
8
+ subject { scraper.instance_variable_get(:@agent) }
12
9
  its(:user_agent) { should eq "git-trend #{VERSION}" }
13
10
  its(:proxy_addr) { should eq '192.168.1.99' }
14
11
  its(:proxy_user) { should eq 'proxy_user' }
@@ -17,13 +14,12 @@ RSpec.describe GitTrend::Scraper do
17
14
  end
18
15
 
19
16
  describe '#get' do
20
- before { @scraper = Scraper.new }
21
17
  context 'when a network error occurred' do
22
18
  before do
23
19
  stub_request(:get, Scraper::BASE_URL)
24
20
  .to_return(status: 500, body: '[]')
25
21
  end
26
- it { expect { @scraper.get }.to raise_error(Exception) }
22
+ it { expect { scraper.get }.to raise_error(Exception) }
27
23
  end
28
24
 
29
25
  context 'when a scraping error occurred' do
@@ -31,7 +27,7 @@ RSpec.describe GitTrend::Scraper do
31
27
  stub_request(:get, Scraper::BASE_URL)
32
28
  .to_return(status: 200, headers: { content_type: 'text/html' }, body: '')
33
29
  end
34
- it { expect { @scraper.get }.to raise_error(ScrapeException) }
30
+ it { expect { scraper.get }.to raise_error(ScrapeException) }
35
31
  end
36
32
  end
37
33
  end
@@ -0,0 +1,82 @@
1
+ RSpec.describe GitTrend do
2
+ before do
3
+ stub_request(:get, /.*/)
4
+ .to_return(status: 200, headers: { content_type: 'text/html' }, body: load_http_stub('trending'))
5
+ end
6
+
7
+ 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
12
+ end
13
+ end
14
+
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')
19
+ end
20
+ end
21
+
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)
26
+ end
27
+ end
28
+
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)
33
+ end
34
+ end
35
+
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)
40
+ end
41
+ end
42
+
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)
47
+ end
48
+ end
49
+
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')
54
+ end
55
+ end
56
+
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)
61
+ end
62
+ end
63
+
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)
68
+ end
69
+ end
70
+
71
+ context 'when too many parameters' do
72
+ it { expect { GitTrend.get('ruby', 'weekly', 'many_params') }.to raise_error(Exception) }
73
+ end
74
+
75
+ describe '#languages' do
76
+ it 'Scraper#languages call' do
77
+ expect_any_instance_of(Scraper).to receive(:languages).with(no_args)
78
+ GitTrend.languages
79
+ end
80
+ end
81
+ end
82
+ end
data/spec/spec_helper.rb CHANGED
@@ -38,8 +38,22 @@ require 'git_trend'
38
38
  SimpleCov.start
39
39
 
40
40
  RSpec.configure do |config|
41
+ config.expect_with :rspec do |expectations|
42
+ expectations.syntax = :expect
43
+ end
44
+
45
+ config.mock_with :rspec do |mocks|
46
+ mocks.syntax = :expect
47
+ mocks.verify_partial_doubles = true
48
+ end
49
+
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
41
52
  config.expose_dsl_globally = false
53
+
54
+ config.example_status_persistence_file_path = 'spec/examples.txt'
42
55
  config.order = :random
56
+ Kernel.srand config.seed
43
57
  # The settings below are suggested to provide a good initial experience
44
58
  # with RSpec, but feel free to customize to your heart's content.
45
59
  =begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-trend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rochefort
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -210,7 +210,7 @@ description: CLI-Based tool that show Trending repository on github
210
210
  email:
211
211
  - terasawan@gmail.com
212
212
  executables:
213
- - git-trend
213
+ - git_trend
214
214
  extensions: []
215
215
  extra_rdoc_files: []
216
216
  files:
@@ -223,7 +223,9 @@ files:
223
223
  - LICENSE.txt
224
224
  - README.md
225
225
  - Rakefile
226
- - bin/git-trend
226
+ - bin/console
227
+ - bin/setup
228
+ - exe/git_trend
227
229
  - git-trend.gemspec
228
230
  - lib/git_trend.rb
229
231
  - lib/git_trend/cli.rb
@@ -243,6 +245,7 @@ files:
243
245
  - spec/fixtures/trending_including_multibyte_characters
244
246
  - spec/git_trend/cli_spec.rb
245
247
  - spec/git_trend/scraper_spec.rb
248
+ - spec/git_trend_spec.rb
246
249
  - spec/spec_helper.rb
247
250
  homepage: https://github.com/rochefort/git-trend
248
251
  licenses:
@@ -280,4 +283,5 @@ test_files:
280
283
  - spec/fixtures/trending_including_multibyte_characters
281
284
  - spec/git_trend/cli_spec.rb
282
285
  - spec/git_trend/scraper_spec.rb
286
+ - spec/git_trend_spec.rb
283
287
  - spec/spec_helper.rb