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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a27216c3e7f57ead579ec183d3f266b06a67450c
4
+ data.tar.gz: 0c90923f014ab3d15d75ccc8e6e6c48320ffddc4
5
+ SHA512:
6
+ metadata.gz: 216bf415b374c5fa3a95b3fc3dc7e15c7ad03a59de69fb83eb3f16ea3e61633b21d01b71370bd580d1e826cbf6b429cd4b8a8c9ca8bd3f7776e11a268ea7c22e
7
+ data.tar.gz: fcebca52be22d67439c6b4897959667e9afaf9890765d2cd06b19cdfca4e8d1d113744c2267835f8ec15afda413bbbafcad64375525ce2a0d78d4e78e8e55c33
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- coding: utf-8 -*-
2
2
  source 'https://rubygems.org/'
3
3
 
4
4
  gemspec
data/MANIFEST CHANGED
@@ -16,6 +16,8 @@ lib/gemirro/cli/server.rb
16
16
  lib/gemirro/cli/update.rb
17
17
  lib/gemirro/configuration.rb
18
18
  lib/gemirro/gem.rb
19
+ lib/gemirro/gem_version.rb
20
+ lib/gemirro/gem_version_collection.rb
19
21
  lib/gemirro/gems_fetcher.rb
20
22
  lib/gemirro/http.rb
21
23
  lib/gemirro/indexer.rb
@@ -29,11 +31,14 @@ lib/gemirro/versions_file.rb
29
31
  spec/gemirro/cli_spec.rb
30
32
  spec/gemirro/configuration_spec.rb
31
33
  spec/gemirro/gem_spec.rb
34
+ spec/gemirro/gem_version_collection_spec.rb
35
+ spec/gemirro/gem_version_spec.rb
32
36
  spec/gemirro/gems_fetcher_spec.rb
33
37
  spec/gemirro/http_spec.rb
34
38
  spec/gemirro/indexer_spec.rb
35
39
  spec/gemirro/mirror_directory_spec.rb
36
40
  spec/gemirro/mirror_file_spec.rb
41
+ spec/gemirro/server_spec.rb
37
42
  spec/gemirro/source_spec.rb
38
43
  spec/gemirro/versions_fetcher_spec.rb
39
44
  spec/gemirro/versions_file_spec.rb
@@ -42,4 +47,18 @@ task/manifest.rake
42
47
  task/rspec.rake
43
48
  task/rubocop.rake
44
49
  template/config.rb
45
- template/public/gems/.gitkeep
50
+ template/logs/.gitkeep
51
+ template/public/dist/css/bootstrap.min.css
52
+ template/public/dist/css/gemirro.css
53
+ template/public/dist/fonts/glyphicons-halflings-regular.eot
54
+ template/public/dist/fonts/glyphicons-halflings-regular.svg
55
+ template/public/dist/fonts/glyphicons-halflings-regular.ttf
56
+ template/public/dist/fonts/glyphicons-halflings-regular.woff
57
+ template/public/dist/fonts/glyphicons-halflings-regular.woff2
58
+ template/public/dist/js/bootstrap.min.js
59
+ template/public/dist/js/jquery.min.js
60
+ template/public/gems/.gitkeep
61
+ views/gem.erb
62
+ views/index.erb
63
+ views/layout.erb
64
+ views/not_found.erb
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Dir['./task/*.rake'].each do |task|
7
7
  import(task)
8
8
  end
9
9
 
10
- task default: [:rubocop, :spec]
10
+ task default: [:spec, :rubocop]
data/gemirro.gemspec CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'rack-test', '~>0.6'
29
29
  s.add_development_dependency 'rspec', '~>3.0'
30
30
  s.add_development_dependency 'simplecov', '~>0.9'
31
- s.add_development_dependency 'rubocop', '~>0.25'
32
- s.add_development_dependency 'fakefs', '~>0.5'
31
+ s.add_development_dependency 'rubocop', '~>0.28'
32
+ s.add_development_dependency 'fakefs', '~>0.6.4'
33
33
  end
@@ -39,6 +39,15 @@ module Gemirro
39
39
  File.expand_path('../../../template', __FILE__)
40
40
  end
41
41
 
42
+ ##
43
+ # Returns the views path to render templates
44
+ #
45
+ # @return [String]
46
+ #
47
+ def self.views_directory
48
+ File.expand_path('../../../views', __FILE__)
49
+ end
50
+
42
51
  ##
43
52
  # Returns default configuration file path
44
53
  #
@@ -0,0 +1,73 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Gemirro
3
+ ##
4
+ # The Gem class contains data about a Gem such as the name, requirement as
5
+ # well as providing some methods to more easily extract the specific version
6
+ # number.
7
+ #
8
+ # @!attribute [r] name
9
+ # @return [String]
10
+ # @!attribute [r] number
11
+ # @return [Integer]
12
+ # @!attribute [r] platform
13
+ # @return [String]
14
+ #
15
+ class GemVersion
16
+ include Comparable
17
+ attr_reader :name, :number, :platform
18
+
19
+ ##
20
+ # @param [String] name
21
+ # @param [String] number
22
+ # @param [String] platform
23
+ #
24
+ def initialize(name, number, platform)
25
+ @name = name
26
+ @number = number
27
+ @platform = platform
28
+ end
29
+
30
+ ##
31
+ # Is for ruby
32
+ #
33
+ # @return [Boolean]
34
+ #
35
+ def ruby?
36
+ !(@platform =~ /^ruby$/i).nil?
37
+ end
38
+
39
+ ##
40
+ # Retrieve gem version
41
+ #
42
+ # @return [Gem::Version]
43
+ #
44
+ def version
45
+ ::Gem::Version.create(number)
46
+ end
47
+
48
+ ##
49
+ # Compare gem to another
50
+ #
51
+ # @return [Integer]
52
+ #
53
+ def <=>(other)
54
+ sort = other.name <=> @name
55
+ sort = version <=> other.version if sort.zero?
56
+ sort = (other.ruby? && !ruby?) ? 1 : -1 if sort.zero? &&
57
+ ruby? != other.ruby?
58
+ sort = other.platform <=> @platform if sort.zero?
59
+
60
+ sort
61
+ end
62
+
63
+ ##
64
+ # Gemfile name
65
+ #
66
+ # @return [String]
67
+ #
68
+ def gemfile_name
69
+ platform = ruby? ? nil : @platform
70
+ [@name, @number, platform].compact.join('-')
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,101 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Gemirro
3
+ ##
4
+ # The VersionCollection class contains a collection of ::Gem::Version
5
+ #
6
+ # @!attribute [r] gems
7
+ # @return [Array]
8
+ # @!attribute [r] grouped
9
+ # @return [Array]
10
+ #
11
+ class GemVersionCollection
12
+ include Enumerable
13
+
14
+ attr_reader :gems
15
+ attr_reader :grouped
16
+
17
+ ##
18
+ # @param [Array] gems
19
+ #
20
+ def initialize(gems = [])
21
+ @gems = gems.map do |object|
22
+ if object.is_a?(GemVersion)
23
+ object
24
+ else
25
+ GemVersion.new(*object)
26
+ end
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Return oldest version of a gem
32
+ #
33
+ # @return [GemVersion]
34
+ #
35
+ def oldest
36
+ @gems.first
37
+ end
38
+
39
+ ##
40
+ # Return newest version of a gem
41
+ #
42
+ # @return [GemVersion]
43
+ #
44
+ def newest
45
+ @gems.last
46
+ end
47
+
48
+ ##
49
+ # Return size of a gem
50
+ #
51
+ # @return [Integer]
52
+ #
53
+ def size
54
+ @gems.size
55
+ end
56
+
57
+ ##
58
+ # Each method
59
+ #
60
+ def each(&block)
61
+ @gems.each(&block)
62
+ end
63
+
64
+ ##
65
+ # Group gems by name
66
+ #
67
+ # @param [Proc] block
68
+ # @return [Array]
69
+ #
70
+ def by_name(&block)
71
+ if @grouped.nil?
72
+ @grouped = @gems.group_by(&:name).map do |name, collection|
73
+ [name, GemVersionCollection.new(collection)]
74
+ end
75
+ @grouped.sort_by! do |name, _collection|
76
+ name.downcase
77
+ end
78
+ end
79
+
80
+ if block_given?
81
+ @grouped.each(&block)
82
+ else
83
+ @grouped
84
+ end
85
+ end
86
+
87
+ ##
88
+ # Find gem by name
89
+ #
90
+ # @param [String] gemname
91
+ # @return [Array]
92
+ #
93
+ def find_by_name(gemname)
94
+ gem = by_name.select do |name, _collection|
95
+ name == gemname
96
+ end
97
+
98
+ gem.first.last if gem.any?
99
+ end
100
+ end
101
+ end
@@ -13,9 +13,15 @@ module Gemirro
13
13
  # @return [String]
14
14
  # @!attribute [r] dest_directory
15
15
  # @return [String]
16
+ # @!attribute [r] only_origin
17
+ # @return [Boolean]
16
18
  #
17
19
  class Indexer < ::Gem::Indexer
18
- attr_accessor :files, :quick_marshal_dir, :directory, :dest_directory
20
+ attr_accessor(:files,
21
+ :quick_marshal_dir,
22
+ :directory,
23
+ :dest_directory,
24
+ :only_origin)
19
25
 
20
26
  ##
21
27
  # Generate indicies on the destination directory
@@ -41,25 +47,31 @@ module Gemirro
41
47
  files.each do |path|
42
48
  file = path.sub(/^#{Regexp.escape @directory}\/?/, '')
43
49
  dst_name = File.join @dest_directory, file
44
- # next if File.exist?(dst_name) &&
45
- # (File.mtime(dst_name) >= Time.now - 360)
46
-
47
- resp = Http.get("#{Gemirro.configuration.source.host}/#{file}")
48
- next unless resp.code == 200
49
- source_content = resp.body
50
50
 
51
51
  if ["#{@specs_index}.gz",
52
52
  "#{@latest_specs_index}.gz",
53
53
  "#{@prerelease_specs_index}.gz"].include?(path)
54
- source_content = Marshal.load(
55
- Zlib::GzipReader.new(StringIO.new(source_content)).read)
54
+
56
55
  content = Marshal.load(Zlib::GzipReader.open(path).read)
57
- new_content = source_content.concat(content).uniq
56
+ Zlib::GzipWriter.open("#{dst_name}.orig") do |io|
57
+ io.write(Marshal.dump(content))
58
+ end
58
59
 
59
- Zlib::GzipWriter.open(dst_name) do |io|
60
- io.write(Marshal.dump(new_content))
60
+ unless @only_origin
61
+ source_content = download_from_source(file)
62
+ next if source_content.nil?
63
+ source_content = Marshal.load(Zlib::GzipReader
64
+ .new(StringIO
65
+ .new(source_content)).read)
66
+ new_content = source_content.concat(content).uniq
67
+
68
+ Zlib::GzipWriter.open(dst_name) do |io|
69
+ io.write(Marshal.dump(new_content))
70
+ end
61
71
  end
62
72
  else
73
+ source_content = download_from_source(file)
74
+ next if source_content.nil?
63
75
  MirrorFile.new(dst_name).write(source_content)
64
76
  end
65
77
 
@@ -67,6 +79,13 @@ module Gemirro
67
79
  end
68
80
  end
69
81
 
82
+ def download_from_source(file)
83
+ source_host = Gemirro.configuration.source.host
84
+ resp = Http.get("#{source_host}/#{File.basename(file)}")
85
+ return unless resp.code == 200
86
+ resp.body
87
+ end
88
+
70
89
  def update_gemspecs
71
90
  make_temp_directories
72
91
 
@@ -35,15 +35,52 @@ module Gemirro
35
35
  config = Gemirro.configuration
36
36
  config.server.host = 'localhost' if config.server.host.nil?
37
37
  config.server.port = '2000' if config.server.port.nil?
38
+
39
+ set :views, Gemirro::Configuration.views_directory
38
40
  set :port, config.server.port
39
41
  set :bind, config.server.host
40
- set :destination, config.destination.gsub(/\/$/, '')
42
+ set :public_folder, config.destination.gsub(/\/$/, '')
41
43
  set :environment, config.environment
44
+ set :dump_errors, true
45
+ set :raise_errors, true
42
46
 
43
47
  enable :logging
44
48
  use Rack::CommonLogger, access_logger
45
49
  end
46
50
 
51
+ ##
52
+ # Set template for not found action
53
+ #
54
+ # @return [nil]
55
+ #
56
+ not_found do
57
+ erb(:not_found)
58
+ end
59
+
60
+ ##
61
+ # Display information about one gem
62
+ #
63
+ # @return [nil]
64
+ #
65
+ get('/gem/:gemname') do
66
+ gems = gems_collection
67
+ @gem = gems.find_by_name(params[:gemname])
68
+ return not_found if @gem.nil?
69
+
70
+ erb(:gem)
71
+ end
72
+
73
+ ##
74
+ # Display home page containing the list of gems already
75
+ # downloaded on the server
76
+ #
77
+ # @return [nil]
78
+ #
79
+ get('/') do
80
+ @gems = gems_collection
81
+ erb(:index)
82
+ end
83
+
47
84
  ##
48
85
  # Try to get all request and download files
49
86
  # if files aren't found.
@@ -51,18 +88,14 @@ module Gemirro
51
88
  # @return [nil]
52
89
  #
53
90
  get('*') do |path|
54
- resource = "#{settings.destination}#{path}"
91
+ resource = "#{settings.public_folder}#{path}"
55
92
 
56
- # Try to download gem if file doesn't exists
57
- fetch_gem(resource) unless File.exist?(resource)
93
+ # Try to download gem
94
+ fetch_gem(resource)
58
95
  # If not found again, return a 404
59
96
  return not_found unless File.exist?(resource)
60
97
 
61
- if File.directory?(resource)
62
- display_directory(resource)
63
- else
64
- send_file resource
65
- end
98
+ send_file(resource)
66
99
  end
67
100
 
68
101
  ##
@@ -91,40 +124,23 @@ module Gemirro
91
124
  logger.error(e.message)
92
125
  end
93
126
 
94
- update_gemspecs
127
+ update_indexes
95
128
  end
96
129
 
97
130
  ##
98
- # Update gemspecs files
131
+ # Update indexes files
99
132
  #
100
133
  # @return [Indexer]
101
134
  #
102
- def update_gemspecs
103
- indexer = Indexer.new(settings.destination)
135
+ def update_indexes
136
+ indexer = Gemirro::Indexer.new(configuration.destination)
137
+ indexer.only_origin = true
104
138
  indexer.ui = ::Gem::SilentUI.new
105
139
 
106
- logger.info('Updating gemspecs files...')
107
- indexer.update_gemspecs
108
- logger.info('Done')
109
- end
110
-
111
- ##
112
- # Display directory on the current sesion
113
- #
114
- # @param [String] resource
115
- # @return [Array]
116
- #
117
- def display_directory(resource)
118
- base_dir = Dir.new(resource)
119
- base_dir.entries.sort.map do |f|
120
- dir_sign = ''
121
- resource_path = resource.gsub(/\/$/, '') + '/' + f
122
- dir_sign = '/' if File.directory?(resource_path)
123
- resource_path = resource_path.gsub(/^public\//, '')
124
- resource_path = resource_path.gsub(settings.destination, '')
125
- "<a href=\"#{resource_path}\">#{f}#{dir_sign}</a><br>" \
126
- unless ['.', '..'].include?(File.basename(resource_path))
127
- end.compact
140
+ configuration.logger.info('Generating indexes')
141
+ indexer.generate_index
142
+ rescue SystemExit => e
143
+ configuration.logger.info(e.message)
128
144
  end
129
145
 
130
146
  ##
@@ -157,5 +173,67 @@ module Gemirro
157
173
  def logger
158
174
  configuration.logger
159
175
  end
176
+
177
+ ##
178
+ # Generate Gems collection from Marshal dump
179
+ #
180
+ # @return [Gemirro::GemVersionCollection]
181
+ #
182
+ def gems_collection
183
+ gems = specs_files_paths.map do |specs_file_path|
184
+ if File.exist?(specs_file_path)
185
+ Marshal.load(Zlib::GzipReader.open(specs_file_path).read)
186
+ else
187
+ []
188
+ end
189
+ end.inject(:|)
190
+
191
+ GemVersionCollection.new(gems)
192
+ end
193
+
194
+ ##
195
+ # Return specs fils paths
196
+ #
197
+ # @return [Array]
198
+ #
199
+ def specs_files_paths
200
+ marshal_version = Gemirro::Configuration.marshal_version
201
+ specs_file_types.map do |specs_file_type|
202
+ File.join(settings.public_folder,
203
+ [specs_file_type, marshal_version, 'gz.orig'].join('.'))
204
+ end
205
+ end
206
+
207
+ ##
208
+ # Return specs fils types
209
+ #
210
+ # @return [Array]
211
+ #
212
+ def specs_file_types
213
+ [:specs, :prerelease_specs]
214
+ end
215
+
216
+ helpers do
217
+ ##
218
+ # Return gem specification from gemname and version
219
+ #
220
+ # @param [String] gemname
221
+ # @param [String] version
222
+ # @return [::Gem::Specification]
223
+ #
224
+ def spec_for(gemname, version, platform = 'ruby')
225
+ filename = [gemname, version]
226
+ filename.push(platform) if platform != 'ruby'
227
+ spec_file = File.join(settings.public_folder,
228
+ 'quick',
229
+ Gemirro::Configuration.marshal_identifier,
230
+ "#{filename.join('-')}.gemspec.rz")
231
+
232
+ File.open(spec_file, 'r') do |uz_file|
233
+ uz_file.binmode
234
+ Marshal.load(::Gem.inflate(uz_file.read))
235
+ end if File.exist?(spec_file)
236
+ end
237
+ end
160
238
  end
161
239
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Gemirro Version
3
3
  module Gemirro
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/gemirro.rb CHANGED
@@ -18,6 +18,8 @@ end
18
18
  require 'gemirro/version'
19
19
  require 'gemirro/configuration'
20
20
  require 'gemirro/gem'
21
+ require 'gemirro/gem_version'
22
+ require 'gemirro/gem_version_collection'
21
23
  require 'gemirro/http'
22
24
  require 'gemirro/indexer'
23
25
  require 'gemirro/source'
@@ -35,7 +35,7 @@ module Gemirro
35
35
  end
36
36
 
37
37
  it 'should raise SystemExit if file does not exists' do
38
- CLI.should_receive(:abort)
38
+ allow(CLI).to receive(:abort)
39
39
  .with('The configuration file /config.rb does not exist')
40
40
  .and_raise SystemExit
41
41
  expect { CLI.load_configuration('config.rb') }.to raise_error SystemExit
@@ -57,13 +57,13 @@ module Gemirro
57
57
  end
58
58
 
59
59
  it 'return mirror directory' do
60
- @config.should_receive(:gems_directory).once.and_return('/tmp')
60
+ allow(@config).to receive(:gems_directory).once.and_return('/tmp')
61
61
  expect(@config.mirror_directory).to be_a(MirrorDirectory)
62
62
  expect(@config.mirror_directory.path).to eq('/tmp')
63
63
  end
64
64
 
65
65
  it 'should return gems directory' do
66
- @config.should_receive(:destination).once.and_return('/tmp')
66
+ allow(@config).to receive(:destination).once.and_return('/tmp')
67
67
  expect(@config.gems_directory).to eq('/tmp/gems')
68
68
  end
69
69
 
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'gemirro/gem_version_collection'
4
+ require 'gemirro/gem_version'
5
+
6
+ # Gem tests
7
+ module Gemirro
8
+ describe 'GemVersionCollection' do
9
+ it 'should be initialized' do
10
+ collection = GemVersionCollection.new([['subzero',
11
+ '0.0.1',
12
+ 'ruby'],
13
+ GemVersion.new('alumina',
14
+ '0.0.1',
15
+ 'ruby')])
16
+ expect(collection.gems.first).to be_a(GemVersion)
17
+ expect(collection.gems.last).to be_a(GemVersion)
18
+ expect(collection.oldest).to be(collection.gems.first)
19
+ expect(collection.newest).to be(collection.gems.last)
20
+ expect(collection.size).to eq(2)
21
+ end
22
+
23
+ it 'should group and sort gems' do
24
+ collection = GemVersionCollection.new([['subzero',
25
+ '0.0.1',
26
+ 'ruby'],
27
+ GemVersion.new('alumina',
28
+ '0.0.1',
29
+ 'ruby')])
30
+ expect(collection.by_name.first[0]).to eq('alumina')
31
+ values = %w(alumina subzero)
32
+ collection.by_name do |name, _version|
33
+ expect(name).to eq(values.shift)
34
+ end
35
+ end
36
+
37
+ it 'should find gem by name' do
38
+ collection = GemVersionCollection.new([['subzero',
39
+ '0.0.1',
40
+ 'ruby'],
41
+ GemVersion.new('alumina',
42
+ '0.0.1',
43
+ 'ruby'),
44
+ GemVersion.new('alumina',
45
+ '0.0.2',
46
+ 'ruby')])
47
+ expect(collection.find_by_name('something')).to be_nil
48
+ expect(collection.find_by_name('alumina').newest.name)
49
+ .to eq('alumina')
50
+ expect(collection.find_by_name('alumina').newest.version.to_s)
51
+ .to eq('0.0.2')
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'gemirro/gem_version'
4
+
5
+ # Gem tests
6
+ module Gemirro
7
+ describe 'GemVersion' do
8
+ it 'should be initialized' do
9
+ gem = GemVersion.new('gemirro',
10
+ '0.0.1',
11
+ 'ruby')
12
+ expect(gem.name).to eq('gemirro')
13
+ expect(gem.number).to eq('0.0.1')
14
+ expect(gem.platform).to eq('ruby')
15
+ expect(gem.ruby?).to be_truthy
16
+ expect(gem.version).to be_a(::Gem::Version)
17
+ expect(gem.gemfile_name).to eq('gemirro-0.0.1')
18
+ end
19
+
20
+ it 'should be initialized with other platform' do
21
+ gem = GemVersion.new('gemirro',
22
+ '0.0.1',
23
+ 'jruby')
24
+ expect(gem.name).to eq('gemirro')
25
+ expect(gem.number).to eq('0.0.1')
26
+ expect(gem.platform).to eq('jruby')
27
+ expect(gem.ruby?).to be_falsy
28
+ expect(gem.version).to be_a(::Gem::Version)
29
+ expect(gem.gemfile_name).to eq('gemirro-0.0.1-jruby')
30
+ end
31
+
32
+ it 'should compare with an other gem' do
33
+ first_gem = GemVersion.new('gemirro',
34
+ '0.0.1',
35
+ 'ruby')
36
+ second_gem = GemVersion.new('gemirro',
37
+ '0.0.2',
38
+ 'ruby')
39
+ third_gem = GemVersion.new('gemirro',
40
+ '0.0.1',
41
+ 'ruby')
42
+ expect(first_gem < second_gem).to eq(true)
43
+ expect(second_gem < first_gem).to eq(false)
44
+ expect(first_gem == third_gem).to eq(true)
45
+ expect(first_gem != second_gem).to eq(true)
46
+ end
47
+ end
48
+ end