gemirro 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gemirro might be problematic. Click here for more details.

Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/MANIFEST +20 -1
  4. data/Rakefile +1 -1
  5. data/gemirro.gemspec +2 -2
  6. data/lib/gemirro/configuration.rb +9 -0
  7. data/lib/gemirro/gem_version.rb +73 -0
  8. data/lib/gemirro/gem_version_collection.rb +101 -0
  9. data/lib/gemirro/indexer.rb +31 -12
  10. data/lib/gemirro/server.rb +113 -35
  11. data/lib/gemirro/version.rb +1 -1
  12. data/lib/gemirro.rb +2 -0
  13. data/spec/gemirro/cli_spec.rb +1 -1
  14. data/spec/gemirro/configuration_spec.rb +2 -2
  15. data/spec/gemirro/gem_version_collection_spec.rb +54 -0
  16. data/spec/gemirro/gem_version_spec.rb +48 -0
  17. data/spec/gemirro/gems_fetcher_spec.rb +13 -13
  18. data/spec/gemirro/http_spec.rb +2 -2
  19. data/spec/gemirro/indexer_spec.rb +57 -32
  20. data/spec/gemirro/server_spec.rb +149 -0
  21. data/spec/gemirro/source_spec.rb +2 -2
  22. data/spec/gemirro/versions_fetcher_spec.rb +3 -3
  23. data/spec/spec_helper.rb +0 -6
  24. data/template/logs/.gitkeep +1 -0
  25. data/template/public/dist/css/bootstrap.min.css +5 -0
  26. data/template/public/dist/css/gemirro.css +1 -0
  27. data/template/public/dist/fonts/glyphicons-halflings-regular.eot +0 -0
  28. data/template/public/dist/fonts/glyphicons-halflings-regular.svg +288 -0
  29. data/template/public/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  30. data/template/public/dist/fonts/glyphicons-halflings-regular.woff +0 -0
  31. data/template/public/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
  32. data/template/public/dist/js/bootstrap.min.js +7 -0
  33. data/template/public/dist/js/jquery.min.js +4 -0
  34. data/views/gem.erb +58 -0
  35. data/views/index.erb +38 -0
  36. data/views/layout.erb +31 -0
  37. data/views/not_found.erb +4 -0
  38. metadata +56 -64
@@ -47,11 +47,11 @@ module Gemirro
47
47
  it 'should log error when fetch gem failed' do
48
48
  gem = Gem.new('gemirro')
49
49
  version = ::Gem::Version.new('0.0.1')
50
- @source.should_receive(:fetch_gem)
50
+ allow(@source).to receive(:fetch_gem)
51
51
  .once.with('gemirro', version).and_raise(ArgumentError)
52
- @fetcher.logger.should_receive(:error)
52
+ allow(@fetcher.logger).to receive(:error)
53
53
  .once.with(/Failed to retrieve/)
54
- @fetcher.logger.should_receive(:debug)
54
+ allow(@fetcher.logger).to receive(:debug)
55
55
  .once.with(/Adding (.*) to the list of ignored Gems/)
56
56
 
57
57
  expect(@fetcher.fetch_gem(gem, version)).to be_nil
@@ -61,7 +61,7 @@ module Gemirro
61
61
  it 'should fetch gem' do
62
62
  gem = Gem.new('gemirro')
63
63
  version = ::Gem::Version.new('0.0.1')
64
- @source.should_receive(:fetch_gem)
64
+ allow(@source).to receive(:fetch_gem)
65
65
  .once.with('gemirro', version).and_return('gemirro')
66
66
 
67
67
  expect(@fetcher.fetch_gem(gem, version)).to eq('gemirro')
@@ -69,17 +69,17 @@ module Gemirro
69
69
 
70
70
  it 'should retrieve versions for specific gem' do
71
71
  gem = Gem.new('gemirro', '0.0.2')
72
- @versions_file.should_receive(:versions_for)
72
+ allow(@versions_file).to receive(:versions_for)
73
73
  .once.with('gemirro').and_return(['0.0.1', '0.0.2'])
74
74
  expect(@fetcher.versions_for(gem)).to eq([::Gem::Version.new('0.0.2')])
75
75
  end
76
76
 
77
77
  it 'should fetch all gems and log debug if gem is not satisfied' do
78
78
  gem = Gem.new('gemirro', '0.0.1')
79
- gem.requirement.should_receive(:satisfied_by?)
79
+ allow(gem.requirement).to receive(:satisfied_by?)
80
80
  .once.with(nil).and_return(false)
81
81
  @fetcher.source.gems << gem
82
- @fetcher.logger.should_receive(:debug)
82
+ allow(@fetcher.logger).to receive(:debug)
83
83
  .once.with('Skipping gemirro-0.0.1.gem')
84
84
  expect(@fetcher.fetch).to eq([gem])
85
85
  end
@@ -87,16 +87,16 @@ module Gemirro
87
87
  it 'should fetch all gems' do
88
88
  gem = Gem.new('gemirro', '0.0.2')
89
89
  @fetcher.source.gems << gem
90
- @fetcher.should_receive(:versions_for).once.and_return(['0.0.2'])
91
- gem.requirement.should_receive(:satisfied_by?)
90
+ allow(@fetcher).to receive(:versions_for).once.and_return(['0.0.2'])
91
+ allow(gem.requirement).to receive(:satisfied_by?)
92
92
  .once.with('0.0.2').and_return(true)
93
- @fetcher.should_receive(:fetch_gem)
93
+ allow(@fetcher).to receive(:fetch_gem)
94
94
  .once.with(gem, '0.0.2').and_return('gemfile')
95
- @fetcher.configuration.should_receive(:ignore_gem)
95
+ allow(@fetcher.configuration).to receive(:ignore_gem)
96
96
  .once.with('gemirro', '0.0.2')
97
- @fetcher.logger.should_receive(:info)
97
+ allow(@fetcher.logger).to receive(:info)
98
98
  .once.with('Fetching gemirro-0.0.2.gem')
99
- @fetcher.configuration.mirror_directory.should_receive(:add_file)
99
+ allow(@fetcher.configuration.mirror_directory).to receive(:add_file)
100
100
  .once.with('gemirro-0.0.2.gem', 'gemfile')
101
101
  expect(@fetcher.fetch).to eq([gem])
102
102
  end
@@ -14,7 +14,7 @@ module Gemirro
14
14
  uri = 'http://github.com/PierreRambaud'
15
15
  Struct.new('HTTPError', :status, :reason)
16
16
  result = Struct::HTTPError.new(401, 'Unauthorized')
17
- Http.client.should_receive(:get)
17
+ allow(Http.client).to receive(:get)
18
18
  .once.with(uri, follow_redirect: true).and_return(result)
19
19
  expect { Http.get(uri) }
20
20
  .to raise_error HTTPClient::BadResponseError, 'Unauthorized'
@@ -24,7 +24,7 @@ module Gemirro
24
24
  uri = 'http://github.com/PierreRambaud'
25
25
  Struct.new('HTTPResponse', :status, :body)
26
26
  result = Struct::HTTPResponse.new(200, 'body content')
27
- Http.client.should_receive(:get)
27
+ allow(Http.client).to receive(:get)
28
28
  .once.with(uri, follow_redirect: true).and_return(result)
29
29
 
30
30
  response = Http.get(uri)
@@ -11,46 +11,71 @@ module Gemirro
11
11
  describe 'Indexer' do
12
12
  include FakeFS::SpecHelpers
13
13
 
14
- before(:each) do
15
- skip if ::Gem::Version.new(RUBY_VERSION.dup) >= ::Gem::Version
16
- .new('2.0.0')
17
- end
18
-
19
14
  it 'should install indicies' do
20
- dir = MirrorDirectory.new('./')
15
+ dir = MirrorDirectory.new('/tmp')
16
+ dir.add_directory('test')
21
17
  dir.add_directory('gem_generate_index/quick/Marshal.4.8')
22
- ::Gem.configuration.should_receive(:really_verbose).once.and_return(true)
18
+ allow(::Gem.configuration).to receive(:really_verbose)
19
+ .once.and_return(true)
23
20
 
24
- indexer = Indexer.new('./')
25
- indexer.should_receive(:say)
26
- .once.with('Downloading index into production dir ./')
27
- indexer.quick_marshal_dir = 'gem_generate_index/quick/Marshal.4.8'
28
- indexer.dest_directory = './'
29
- indexer.directory = 'gem_generate_index'
21
+ indexer = Indexer.new('/tmp/test')
22
+ allow(indexer).to receive(:say)
23
+ .once.with('Downloading index into production dir /tmp/test')
24
+ indexer.quick_marshal_dir = '/tmp/gem_generate_index/quick/Marshal.4.8'
25
+ indexer.dest_directory = '/tmp/test'
26
+ indexer.directory = '/tmp/gem_generate_index'
27
+ indexer.instance_variable_set('@specs_index',
28
+ '/tmp/gem_generate_index/specs.4.8')
30
29
  indexer.files = [
31
- 'gem_generate_index/quick/Marshal.4.8',
32
- 'gem_generate_index/specs.4.8.gz'
30
+ '/tmp/gem_generate_index/quick/Marshal.4.8',
31
+ '/tmp/gem_generate_index/specs.4.8.gz',
32
+ '/tmp/gem_generate_index/something.4.8.gz'
33
33
  ]
34
34
 
35
- FileUtils.should_receive(:mkdir_p).once.with('./quick', verbose: true)
36
- FileUtils.should_receive(:rm_rf)
37
- .once.with('gem_generate_index/specs.4.8.gz')
38
- FileUtils.should_receive(:rm_rf)
39
- .once.with('./quick/Marshal.4.8', verbose: true)
40
- FileUtils.should_receive(:mv)
35
+ allow(FileUtils).to receive(:mkdir_p)
36
+ .once.with('/tmp/test/quick', verbose: true)
37
+ allow(FileUtils).to receive(:rm_rf)
38
+ .once.with('/tmp/gem_generate_index/something.4.8.gz')
39
+ allow(FileUtils).to receive(:rm_rf)
40
+ .once.with('/tmp/gem_generate_index/specs.4.8.gz')
41
+ allow(FileUtils).to receive(:rm_rf)
42
+ .once.with('/tmp/test/quick/Marshal.4.8', verbose: true)
43
+ allow(FileUtils).to receive(:mv)
41
44
  .once
42
- .with('gem_generate_index/quick/Marshal.4.8', './quick/Marshal.4.8',
45
+ .with('/tmp/gem_generate_index/quick/Marshal.4.8',
46
+ '/tmp/test/quick/Marshal.4.8',
43
47
  verbose: true, force: true)
48
+
44
49
  source = Source.new('Rubygems', 'https://rubygems.org')
45
- Gemirro.configuration.should_receive(:source).and_return(source)
50
+ allow(Gemirro.configuration).to receive(:source).and_return(source)
51
+
46
52
  Struct.new('HttpGet', :code, :body)
47
- http_get = Struct::HttpGet.new(200, 'content')
48
- Http.should_receive(:get)
53
+ wio = StringIO.new('w')
54
+ w_gz = Zlib::GzipWriter.new(wio)
55
+ w_gz.write(['content'])
56
+ w_gz.close
57
+ http_get = Struct::HttpGet.new(200, wio.string)
58
+ allow(Marshal).to receive(:load).and_return(['content'])
59
+ allow(Marshal).to receive(:dump).and_return(['content'])
60
+ allow(Zlib::GzipWriter).to receive(:open)
61
+ .once.with('/tmp/test/specs.4.8.gz.orig')
62
+ allow(Zlib::GzipWriter).to receive(:open)
63
+ .once.with('/tmp/test/specs.4.8.gz')
64
+ allow(Http).to receive(:get)
49
65
  .with('https://rubygems.org/specs.4.8.gz').and_return(http_get)
66
+ allow(Http).to receive(:get)
67
+ .with('https://rubygems.org/something.4.8.gz').and_return(http_get)
68
+
69
+ Struct.new('GzipReader', :read)
70
+ gzip_reader = Struct::GzipReader.new(wio.string)
71
+ allow(Zlib::GzipReader).to receive(:open)
72
+ .once
73
+ .with('/tmp/gem_generate_index/specs.4.8.gz')
74
+ .and_return(gzip_reader)
50
75
 
51
76
  files = indexer.install_indicies
52
- expect(files).to eq(['gem_generate_index/specs.4.8.gz'])
53
- expect(MirrorFile.new('specs.4.8.gz').read).to eq('content')
77
+ expect(files).to eq(['/tmp/gem_generate_index/specs.4.8.gz',
78
+ '/tmp/gem_generate_index/something.4.8.gz'])
54
79
  end
55
80
 
56
81
  it 'should exit if there is no new gems' do
@@ -59,12 +84,12 @@ module Gemirro
59
84
  MirrorFile.new('./specs.4.8').write('')
60
85
 
61
86
  indexer = Indexer.new('./')
62
- indexer.should_receive(:make_temp_directories).and_return(true)
87
+ allow(indexer).to receive(:make_temp_directories).and_return(true)
63
88
 
64
89
  expect { indexer.update_gemspecs }.to raise_error SystemExit
65
90
  end
66
91
 
67
- it 'should generate gemspecs files' do
92
+ it 'should update gemspecs files' do
68
93
  dir = MirrorDirectory.new('/')
69
94
  dir.add_directory('gems')
70
95
  dir.add_directory('quick')
@@ -80,10 +105,10 @@ module Gemirro
80
105
  MirrorFile.new("#{indexer.directory}/quick/gemirro-0.1.0.gemspec.rz")
81
106
  .write('test')
82
107
 
83
- indexer.should_receive(:gem_file_list)
108
+ allow(indexer).to receive(:gem_file_list)
84
109
  .and_return(['gems/gemirro-0.1.0.gem'])
85
- indexer.should_receive(:make_temp_directories).once.and_return(true)
86
- indexer.should_receive(:build_marshal_gemspecs).once.and_return([
110
+ allow(indexer).to receive(:make_temp_directories).once.and_return(true)
111
+ allow(indexer).to receive(:build_marshal_gemspecs).once.and_return([
87
112
  "#{indexer.directory}/quick/gemirro-0.1.0.gemspec.rz"])
88
113
 
89
114
  indexer.update_gemspecs
@@ -0,0 +1,149 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rack/test'
3
+ require 'gemirro/mirror_directory'
4
+ require 'gemirro/mirror_file'
5
+ require 'gemirro/gem_version_collection'
6
+
7
+ ENV['RACK_ENV'] = 'test'
8
+
9
+ # Rspec mixin module
10
+ module RSpecMixin
11
+ include Rack::Test::Methods
12
+ def app
13
+ require 'gemirro/server'
14
+ Gemirro::Server
15
+ end
16
+ end
17
+
18
+ RSpec.configure do |c|
19
+ c.include RSpecMixin
20
+ end
21
+
22
+ # Server tests
23
+ module Gemirro
24
+ describe 'Gemirro::Server' do
25
+ include FakeFS::SpecHelpers
26
+
27
+ before(:each) do
28
+ @fake_logger = Logger.new(STDOUT)
29
+ MirrorDirectory.new('/var/www/gemirro').add_directory('gems')
30
+ MirrorDirectory.new('/').add_directory('tmp')
31
+ MirrorFile.new('/var/www/gemirro/test').write('content')
32
+ Gemirro.configuration.destination = '/var/www/gemirro'
33
+ FakeFS::FileSystem.clone(Gemirro::Configuration.views_directory)
34
+ end
35
+
36
+ it 'should display index page' do
37
+ allow(Logger).to receive(:new).twice.and_return(@fake_logger)
38
+ allow(@fake_logger).to receive(:tap).and_return(nil)
39
+ .and_yield(@fake_logger)
40
+
41
+ get '/'
42
+ expect(last_response).to be_ok
43
+ end
44
+
45
+ it 'should return 404' do
46
+ get '/wrong-path'
47
+ expect(last_response.status).to eq(404)
48
+ expect(last_response).to_not be_ok
49
+ end
50
+
51
+ it 'should return 404 when gem does not exist' do
52
+ get '/gem/something'
53
+ expect(last_response.status).to eq(404)
54
+ expect(last_response).to_not be_ok
55
+ end
56
+
57
+ it 'should display gem specifications' do
58
+ marshal_dump = Marshal.dump([['groove-dl',
59
+ ::Gem::Version.create('0.1.0'),
60
+ 'ruby']])
61
+
62
+ MirrorFile.new('/var/www/gemirro/specs.4.8.gz.orig').write(marshal_dump)
63
+ Struct.new('SuccessGzipReader', :read)
64
+ gzip_reader = Struct::SuccessGzipReader.new(marshal_dump)
65
+
66
+ allow(Zlib::GzipReader).to receive(:open)
67
+ .once
68
+ .with('/var/www/gemirro/specs.4.8.gz.orig')
69
+ .and_return(gzip_reader)
70
+
71
+ get '/gem/groove-dl'
72
+ expect(last_response.status).to eq(200)
73
+ expect(last_response).to be_ok
74
+ end
75
+
76
+ it 'should download existing file' do
77
+ get '/test'
78
+ expect(last_response.body).to eq('content')
79
+ expect(last_response).to be_ok
80
+ end
81
+
82
+ it 'should try to download gems.' do
83
+ source = Gemirro::Source.new('test', 'http://rubygems.org')
84
+
85
+ versions_fetcher = Gemirro::VersionsFetcher.new(source)
86
+ allow(versions_fetcher).to receive(:fetch).once.and_return(true)
87
+
88
+ gems_fetcher = Gemirro::VersionsFetcher.new(source)
89
+ allow(gems_fetcher).to receive(:fetch).once.and_return(true)
90
+
91
+ Struct.new('GemIndexer')
92
+ gem_indexer = Struct::GemIndexer.new
93
+ allow(gem_indexer).to receive(:only_origin=).once.and_return(true)
94
+ allow(gem_indexer).to receive(:ui=).once.and_return(true)
95
+ allow(gem_indexer).to receive(:generate_index).once.and_return(true)
96
+
97
+ allow(Gemirro.configuration).to receive(:source).twice.and_return(source)
98
+ allow(Gemirro::GemsFetcher).to receive(:new).once.and_return(gems_fetcher)
99
+ allow(Gemirro::VersionsFetcher).to receive(:new)
100
+ .once.and_return(versions_fetcher)
101
+ allow(Gemirro::Indexer).to receive(:new).once.and_return(gem_indexer)
102
+ allow(::Gem::SilentUI).to receive(:new).once.and_return(true)
103
+
104
+ allow(Gemirro.configuration).to receive(:logger)
105
+ .exactly(3).and_return(@fake_logger)
106
+ allow(@fake_logger).to receive(:info).exactly(3)
107
+
108
+ get '/gems/gemirro-0.0.1.gem'
109
+ expect(last_response).to_not be_ok
110
+ expect(last_response.status).to eq(404)
111
+
112
+ MirrorFile.new('/var/www/gemirro/gems/gemirro-0.0.1.gem').write('content')
113
+ get '/gems/gemirro-0.0.1.gem'
114
+ expect(last_response).to be_ok
115
+ expect(last_response.status).to eq(200)
116
+ expect(last_response.body).to eq('content')
117
+ end
118
+
119
+ it 'should catch exceptions' do
120
+ source = Gemirro::Source.new('test', 'http://rubygems.org')
121
+
122
+ versions_fetcher = Gemirro::VersionsFetcher.new(source)
123
+ allow(versions_fetcher).to receive(:fetch).once.and_return(true)
124
+
125
+ gems_fetcher = Gemirro::VersionsFetcher.new(source)
126
+ allow(gems_fetcher).to receive(:fetch).once.and_raise(
127
+ StandardError, 'Not ok')
128
+
129
+ gem_indexer = Struct::GemIndexer.new
130
+ allow(gem_indexer).to receive(:only_origin=).once.and_return(true)
131
+ allow(gem_indexer).to receive(:ui=).once.and_return(true)
132
+ allow(gem_indexer).to receive(:generate_index).once.and_raise(SystemExit)
133
+
134
+ allow(Gemirro.configuration).to receive(:source).twice.and_return(source)
135
+ allow(Gemirro::GemsFetcher).to receive(:new).once.and_return(gems_fetcher)
136
+ allow(Gemirro::VersionsFetcher).to receive(:new)
137
+ .once.and_return(versions_fetcher)
138
+ allow(Gemirro::Indexer).to receive(:new).once.and_return(gem_indexer)
139
+ allow(::Gem::SilentUI).to receive(:new).once.and_return(true)
140
+
141
+ allow(Gemirro.configuration).to receive(:logger)
142
+ .exactly(4).and_return(@fake_logger)
143
+ allow(@fake_logger).to receive(:info).exactly(3)
144
+ allow(@fake_logger).to receive(:error)
145
+ get '/gems/gemirro-0.0.1.gem'
146
+ expect(last_response).to_not be_ok
147
+ end
148
+ end
149
+ end
@@ -19,7 +19,7 @@ module Gemirro
19
19
  it 'should fetch versions' do
20
20
  Struct.new('FetchVersions', :body)
21
21
  result = Struct::FetchVersions.new(true)
22
- Http.should_receive(:get).once.with(
22
+ allow(Http).to receive(:get).once.with(
23
23
  "https://rubygems.org/#{Configuration.versions_file}"
24
24
  ).and_return(result)
25
25
  expect(@source.fetch_versions).to be_truthy
@@ -28,7 +28,7 @@ module Gemirro
28
28
  it 'should fetch gem' do
29
29
  Struct.new('FetchGem', :body)
30
30
  result = Struct::FetchGem.new(true)
31
- Http.should_receive(:get).once.with(
31
+ allow(Http).to receive(:get).once.with(
32
32
  'https://rubygems.org/gems/gemirro-0.0.1.gem').and_return(result)
33
33
  expect(@source.fetch_gem('gemirro', '0.0.1')).to be_truthy
34
34
  end
@@ -15,10 +15,10 @@ module Gemirro
15
15
  end
16
16
 
17
17
  it 'should fetch versions' do
18
- Gemirro.configuration.logger.should_receive(:info)
18
+ allow(Gemirro.configuration.logger).to receive(:info)
19
19
  .once.with("Updating #{@source.name} (#{@source.host})")
20
- @source.should_receive(:fetch_versions).once.and_return([])
21
- VersionsFile.should_receive(:load).with([])
20
+ allow(@source).to receive(:fetch_versions).once.and_return([])
21
+ allow(VersionsFile).to receive(:load).with([])
22
22
  expect(@fetcher.fetch).to be_nil
23
23
  end
24
24
  end
data/spec/spec_helper.rb CHANGED
@@ -6,12 +6,6 @@ require 'confstruct'
6
6
  require 'logger'
7
7
  require 'fakefs/spec_helpers'
8
8
 
9
- RSpec.configure do |config|
10
- config.mock_with :rspec do |mocks|
11
- mocks.syntax = :should
12
- end
13
- end
14
-
15
9
  SimpleCov.start do
16
10
  add_filter '/spec/'
17
11
  end
@@ -0,0 +1 @@
1
+