gemrat 0.3.2 → 0.4.0
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 +4 -4
- data/.gitignore +1 -0
- data/Guardfile +9 -0
- data/README.md +10 -14
- data/gemrat.gemspec +2 -1
- data/lib/gemrat.rb +9 -11
- data/lib/gemrat/arguments.rb +58 -17
- data/lib/gemrat/gem.rb +121 -0
- data/lib/gemrat/gemfile.rb +83 -0
- data/lib/gemrat/messages.rb +10 -3
- data/lib/gemrat/runner.rb +23 -40
- data/lib/gemrat/version.rb +1 -1
- data/spec/gem_spec.rb +42 -0
- data/spec/gemrat_spec.rb +211 -49
- data/spec/resources/rubygems_response_shim_for_thin +45 -0
- data/spec/spec_helper.rb +10 -0
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e20de748b67ae7e24e0253f185ea2456905062cb
|
4
|
+
data.tar.gz: 0c08f1cce68b55d0a9eae1bd09597a3a0bc16eea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fc01ff951da73ce863dd29f79a5306a062b1eef46c41e317571f1bb5e4a992d3dcdadc3502a30e031cf4e083b9c0b15bd41b59ff7b6384ca5e476413fee9f9b
|
7
|
+
data.tar.gz: 439308f085e60b6ecfbf35ad478e8879a391b7a5623c1ca0ed9a2c3b120d62517c69f28a947194fc112c33aabee7e7d6389cdb68a8edd6b0c7989917030c20d9
|
data/.gitignore
CHANGED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -6,16 +6,12 @@ Add the latest version of a gem to your Gemfile from the command line.
|
|
6
6
|
* No need to edit your Gemfile directly
|
7
7
|
* Gemrat bundles automatically
|
8
8
|
|
9
|
-
<br/>
|
10
|
-
|
11
9
|
## Usage
|
12
|
-
Add the latest version of a gem to your Gemfile and bundle
|
10
|
+
Add the latest version of a gem to your Gemfile and bundle
|
13
11
|
<pre>
|
14
12
|
$ gemrat gem_name
|
15
13
|
</pre>
|
16
14
|
|
17
|
-
<br/>
|
18
|
-
|
19
15
|
Add the latest version of sinatra to your Gemfile and bundle
|
20
16
|
<pre>
|
21
17
|
$ gemrat sinatra
|
@@ -24,7 +20,6 @@ $ gemrat sinatra
|
|
24
20
|
#=> Bundling...
|
25
21
|
</pre>
|
26
22
|
|
27
|
-
<br/>
|
28
23
|
Add multiple gems
|
29
24
|
<pre>
|
30
25
|
$ gemrat rspec capybara sidekiq
|
@@ -35,11 +30,7 @@ $ gemrat rspec capybara sidekiq
|
|
35
30
|
#=> Bundling...
|
36
31
|
</pre>
|
37
32
|
|
38
|
-
<br/>
|
39
|
-
|
40
|
-
|
41
33
|
Get help
|
42
|
-
|
43
34
|
<pre>
|
44
35
|
$ gemrat --help OR gemrat -h
|
45
36
|
|
@@ -58,7 +49,6 @@ Options:
|
|
58
49
|
|
59
50
|

|
60
51
|
|
61
|
-
<br/>
|
62
52
|
## Installation
|
63
53
|
|
64
54
|
Add this line to your application's Gemfile:
|
@@ -73,12 +63,18 @@ Or install it yourself as:
|
|
73
63
|
|
74
64
|
$ gem install gemrat
|
75
65
|
|
76
|
-
<br/>
|
77
|
-
|
78
66
|
## Development
|
79
67
|
|
80
|
-
Run the test suite with:
|
68
|
+
Run the entire test suite with:
|
81
69
|
|
82
70
|
<pre>
|
83
71
|
$ rake
|
84
72
|
</pre>
|
73
|
+
|
74
|
+
We encourage you to run
|
75
|
+
|
76
|
+
<pre>
|
77
|
+
$ guard
|
78
|
+
</pre>
|
79
|
+
|
80
|
+
in development, because it's awesome!
|
data/gemrat.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'gemrat/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "gemrat"
|
8
8
|
spec.version = Gemrat::VERSION
|
9
|
-
spec.authors = ["Dru Riley", "Hrvoje Simic"]
|
9
|
+
spec.authors = ["Dru Riley", "Hrvoje Simic", "Marko Ivanek"]
|
10
10
|
spec.email = ["dru@drurly.com", "shime.ferovac@gmail.com"]
|
11
11
|
spec.description = "Add the latest version of a gem to your Gemfile from the command line."
|
12
12
|
spec.summary = "Add the latest version of a gem to your Gemfile from the command line."
|
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
26
|
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "guard-rspec"
|
27
28
|
end
|
data/lib/gemrat.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
require "optparse"
|
3
|
+
require "pry"
|
4
|
+
|
1
5
|
require "gemrat/version"
|
2
6
|
require "gemrat/messages"
|
3
7
|
require "gemrat/runner"
|
4
8
|
require "gemrat/arguments"
|
9
|
+
require "gemrat/gem"
|
10
|
+
require "gemrat/gemfile"
|
11
|
+
|
5
12
|
require "colored"
|
13
|
+
require "rbconfig"
|
6
14
|
|
7
15
|
module Gemrat
|
8
16
|
class GemNotFound < StandardError; end
|
9
|
-
class Gem < Struct.new(:name, :valid)
|
10
|
-
alias_method :valid?, :valid
|
11
|
-
|
12
|
-
def initialize(*args)
|
13
|
-
super
|
14
|
-
self.valid = true
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
self.valid = false
|
19
|
-
end
|
20
|
-
end
|
18
|
+
SYSTEM = RbConfig::CONFIG["host_os"]
|
21
19
|
end
|
data/lib/gemrat/arguments.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Gemrat
|
2
2
|
class Arguments
|
3
|
-
|
3
|
+
class PrintHelp < StandardError; end
|
4
|
+
|
5
|
+
ATTRIBUTES = [:gems, :gemfile, :options]
|
4
6
|
|
5
7
|
ATTRIBUTES.each { |arg| attr_accessor arg }
|
6
8
|
|
@@ -8,34 +10,73 @@ module Gemrat
|
|
8
10
|
def initialize(*args)
|
9
11
|
self.arguments = *args
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
extract_options
|
13
|
+
parse_options
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
def gems
|
18
|
+
gem_names.map do |name|
|
19
|
+
gem = Gem.new
|
20
|
+
gem.name = name
|
21
|
+
gem
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
private
|
21
26
|
|
22
27
|
attr_accessor :arguments
|
23
28
|
|
24
|
-
def validate
|
25
|
-
|
29
|
+
def validate(opt_parser)
|
30
|
+
if gem_names.empty? || gem_names.first.nil?
|
31
|
+
puts opt_parser.help
|
32
|
+
raise PrintHelp
|
33
|
+
end
|
26
34
|
end
|
27
35
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
36
|
+
def parse_options
|
37
|
+
self.options = OpenStruct.new
|
38
|
+
|
39
|
+
options.gemfile = "Gemfile"
|
40
|
+
|
41
|
+
opt_parser = OptionParser.new do |opts|
|
42
|
+
opts.banner = Messages::USAGE
|
31
43
|
|
32
|
-
|
33
|
-
|
34
|
-
|
44
|
+
opts.on("-g", "--gemfile GEMFILE", "# Specify the Gemfile to be used, defaults to 'Gemfile'") do |gemfile|
|
45
|
+
options.gemfile = gemfile
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("--no-install", "# Skip executing bundle after adding the gem.") do
|
49
|
+
options.no_install = true
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on("--no-version", "# Do not add a version to the gemfile.") do
|
53
|
+
options.no_version = true
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on_tail("-h", "--help", "# Print these usage instructions.") do
|
57
|
+
puts opts
|
58
|
+
raise PrintHelp
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on("-v", "--version", "# Show current gemrat version.") do
|
62
|
+
puts Gemrat::VERSION
|
63
|
+
raise PrintHelp
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
opt_parser.parse!(arguments)
|
69
|
+
rescue OptionParser::InvalidOption
|
70
|
+
puts opt_parser
|
71
|
+
raise PrintHelp
|
72
|
+
end
|
73
|
+
validate(opt_parser)
|
74
|
+
|
75
|
+
self.gemfile = Gemfile.new(options.gemfile)
|
76
|
+
end
|
35
77
|
|
36
|
-
|
37
|
-
|
38
|
-
# unable to extract options, leave them nil
|
78
|
+
def gem_names
|
79
|
+
arguments.take_while { |arg| arg !~ /^-|^--/}
|
39
80
|
end
|
40
81
|
end
|
41
82
|
end
|
data/lib/gemrat/gem.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
module Gemrat
|
2
|
+
class Gem
|
3
|
+
class NotFound < StandardError; end
|
4
|
+
|
5
|
+
attr_accessor :name, :valid, :action
|
6
|
+
alias_method :valid?, :valid
|
7
|
+
|
8
|
+
ACTIONS = OpenStruct.new({:add => "add", :update => "update",
|
9
|
+
:skip => "skip", :no_version => "no version"})
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
self.valid = true
|
13
|
+
|
14
|
+
add!
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
@output ||= "gem '#{name}', '#{version}'"
|
19
|
+
end
|
20
|
+
|
21
|
+
def invalid!
|
22
|
+
self.valid = false
|
23
|
+
end
|
24
|
+
|
25
|
+
def version
|
26
|
+
if platform_dependent?
|
27
|
+
platform_dependent_version
|
28
|
+
else
|
29
|
+
standard_version
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def update!
|
34
|
+
self.action = ACTIONS.update
|
35
|
+
end
|
36
|
+
|
37
|
+
def update?
|
38
|
+
self.action == ACTIONS.update
|
39
|
+
end
|
40
|
+
|
41
|
+
def skip!
|
42
|
+
self.action = ACTIONS.skip
|
43
|
+
end
|
44
|
+
|
45
|
+
def skip?
|
46
|
+
self.action == ACTIONS.skip
|
47
|
+
end
|
48
|
+
|
49
|
+
def add!
|
50
|
+
self.action = ACTIONS.add
|
51
|
+
end
|
52
|
+
|
53
|
+
def add?
|
54
|
+
self.action == ACTIONS.add
|
55
|
+
end
|
56
|
+
|
57
|
+
def no_version!
|
58
|
+
self.action = ACTIONS.no_version
|
59
|
+
end
|
60
|
+
|
61
|
+
def no_version?
|
62
|
+
self.action == ACTIONS.no_version
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def platform_dependent?
|
68
|
+
versions.count > 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def standard_version
|
72
|
+
normalize_name.gsub(/[^\d\.]/, '')
|
73
|
+
end
|
74
|
+
|
75
|
+
def versions
|
76
|
+
platform_versions = normalize_name.gsub(/'/,"").split(",")[1..-1]
|
77
|
+
|
78
|
+
hash = {:default => platform_versions.shift}
|
79
|
+
|
80
|
+
platform_versions.inject(hash) do |hash, part|
|
81
|
+
hash[part.split(" ")[1..-1]] = part.split(" ").first
|
82
|
+
hash
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def platform_dependent_version
|
87
|
+
version_for_platform = versions.select do |key, value|
|
88
|
+
key.join =~ /#{SYSTEM}/ if key.is_a? Array
|
89
|
+
end.values
|
90
|
+
|
91
|
+
if version_for_platform.empty?
|
92
|
+
versions[:default].strip
|
93
|
+
else
|
94
|
+
version_for_platform.first
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def normalize_name
|
99
|
+
if no_version?
|
100
|
+
normalized = ("gem '" + name + "'")
|
101
|
+
else
|
102
|
+
normalized = ("gem " + find_exact_match).gsub(/[()]/, "'")
|
103
|
+
normalized.gsub(/#{name}/, "'#{name}',")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def find_exact_match
|
108
|
+
find_all.reject do |n|
|
109
|
+
/^#{name} / !~ n
|
110
|
+
end.first || raise(NotFound)
|
111
|
+
end
|
112
|
+
|
113
|
+
def find_all
|
114
|
+
fetch_all.split(/\n/)
|
115
|
+
end
|
116
|
+
|
117
|
+
def fetch_all
|
118
|
+
`gem search -r #{name}`
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Gemrat
|
2
|
+
class Gemfile
|
3
|
+
class DuplicateGemFound < StandardError; end
|
4
|
+
|
5
|
+
attr_accessor :needs_bundle
|
6
|
+
alias_method :needs_bundle?, :needs_bundle
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
self.path = path
|
10
|
+
self.needs_bundle = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def add(gem)
|
14
|
+
file = File.open(path, "a+")
|
15
|
+
|
16
|
+
check(gem, file)
|
17
|
+
|
18
|
+
if gem.add?
|
19
|
+
file.write "\n#{gem}"
|
20
|
+
puts "#{gem} added to your Gemfile.".green
|
21
|
+
|
22
|
+
needs_bundle!
|
23
|
+
elsif gem.update?
|
24
|
+
contents = File.read(path)
|
25
|
+
File.open(path,'w') do |f|
|
26
|
+
f.print contents.gsub(/^.*#{gem.name}.*$/, "#{gem}")
|
27
|
+
|
28
|
+
f.close
|
29
|
+
end
|
30
|
+
puts "Updated '#{gem.name}' to version '#{gem.version}'.".green
|
31
|
+
needs_bundle!
|
32
|
+
elsif gem.no_version?
|
33
|
+
file.write "\ngem '#{gem.name}'"
|
34
|
+
|
35
|
+
puts "gem '#{gem.name}' added to your Gemfile.".green
|
36
|
+
|
37
|
+
needs_bundle!
|
38
|
+
end
|
39
|
+
ensure
|
40
|
+
file.close
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
attr_accessor :path
|
45
|
+
|
46
|
+
def needs_bundle!
|
47
|
+
self.needs_bundle = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def check(gem, file)
|
51
|
+
grep_file = file.grep(/.*#{gem.name}.*#{gem.version}.*/ )
|
52
|
+
raise DuplicateGemFound unless grep_file.empty?
|
53
|
+
current_gem_version = get_current_gem_version(gem, file)
|
54
|
+
|
55
|
+
return unless current_gem_version =~ /\S/
|
56
|
+
|
57
|
+
if current_gem_version < gem.version
|
58
|
+
prompt_gem_replacement(gem, current_gem_version)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def prompt_gem_replacement(gem, gem_version)
|
63
|
+
print (Messages::NEWER_GEM_FOUND % [gem.name, gem.version, gem_version]).chomp + " "
|
64
|
+
case input
|
65
|
+
when /n|no/
|
66
|
+
gem.skip!
|
67
|
+
else
|
68
|
+
gem.update!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_current_gem_version(gem, file)
|
73
|
+
file.rewind
|
74
|
+
gem_version = file.grep(/.*#{gem.name}.*/)
|
75
|
+
gem_version = gem_version.to_s.gsub(/[^\d|.]+/, '')
|
76
|
+
gem_version
|
77
|
+
end
|
78
|
+
|
79
|
+
def input
|
80
|
+
STDIN.gets
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/gemrat/messages.rb
CHANGED
@@ -11,9 +11,6 @@ module Gemrat
|
|
11
11
|
|
12
12
|
Options:
|
13
13
|
|
14
|
-
-g [--gemfile] # Specify the Gemfile to be used. Defaults to 'Gemfile'.
|
15
|
-
-h [--help] # Print these usage instructions.
|
16
|
-
|
17
14
|
USAGE
|
18
15
|
|
19
16
|
GEM_NOT_FOUND = <<-GEM_NOT_FOUND.gsub /^( +)(\w+)/, '\2'
|
@@ -21,5 +18,15 @@ module Gemrat
|
|
21
18
|
Unable to find gem '%s' on Rubygems. Sorry about that.
|
22
19
|
GEM_NOT_FOUND
|
23
20
|
|
21
|
+
DUPLICATE_GEM_FOUND = <<-DUPLICATE_GEM_FOUND.gsub /^( +)(\w+)/, '\2'
|
22
|
+
|
23
|
+
gem '%s' already exists in your Gemfile. Skipping...
|
24
|
+
DUPLICATE_GEM_FOUND
|
25
|
+
|
26
|
+
NEWER_GEM_FOUND = <<-NEWER_GEM_FOUND.gsub /^( +)(\w+)/, '\2'
|
27
|
+
|
28
|
+
Gem '%s' already exists, but there is a newer version of the gem (v %s > v %s).
|
29
|
+
Update version? (Y/n)
|
30
|
+
NEWER_GEM_FOUND
|
24
31
|
end
|
25
32
|
end
|
data/lib/gemrat/runner.rb
CHANGED
@@ -18,75 +18,58 @@ module Gemrat
|
|
18
18
|
|
19
19
|
def run
|
20
20
|
for_each_gem do
|
21
|
-
with_error_handling
|
22
|
-
|
23
|
-
find_exact_match
|
24
|
-
ensure_gem_exists
|
25
|
-
normalize_for_gemfile
|
26
|
-
add_to_gemfile
|
27
|
-
|
28
|
-
end
|
21
|
+
with_error_handling { gemfile.add(gem) }
|
29
22
|
end
|
30
23
|
|
31
|
-
run_bundle unless
|
24
|
+
run_bundle unless skip_bundle?
|
32
25
|
end
|
33
26
|
|
34
27
|
attr_accessor :gem
|
35
28
|
|
36
29
|
private
|
37
|
-
|
38
|
-
attr_accessor :gems, :gemfile, :
|
30
|
+
|
31
|
+
attr_accessor :gems, :gemfile, :no_install, :no_version
|
39
32
|
|
40
33
|
def parse_arguments(*args)
|
41
34
|
Arguments.new(*args).tap do |a|
|
42
|
-
self.gems = a.
|
35
|
+
self.gems = a.gems
|
43
36
|
self.gemfile = a.gemfile
|
37
|
+
self.no_install = a.options.no_install
|
38
|
+
self.no_version = a.options.no_version
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
47
42
|
def with_error_handling
|
48
43
|
yield
|
49
|
-
rescue
|
50
|
-
|
51
|
-
rescue GemNotFound
|
44
|
+
rescue Arguments::PrintHelp
|
45
|
+
rescue Gem::NotFound
|
52
46
|
puts Messages::GEM_NOT_FOUND.red % gem.name
|
53
47
|
gem.invalid!
|
48
|
+
rescue Gemfile::DuplicateGemFound
|
49
|
+
puts Messages::DUPLICATE_GEM_FOUND % gem.name
|
50
|
+
gem.invalid!
|
54
51
|
end
|
55
52
|
|
56
53
|
def for_each_gem
|
57
54
|
gems && gems.each do |gem|
|
55
|
+
set_no_version(gem)
|
58
56
|
self.gem = gem
|
59
57
|
yield
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def find_all(name)
|
68
|
-
fetch_all(name).split(/\n/)
|
69
|
-
end
|
70
|
-
|
71
|
-
def fetch_all(name)
|
72
|
-
`gem search -r #{name}`
|
73
|
-
end
|
74
|
-
|
75
|
-
def ensure_gem_exists
|
76
|
-
raise GemNotFound if exact_match.nil?
|
77
|
-
end
|
78
|
-
|
79
|
-
def normalize_for_gemfile
|
80
|
-
gem_name = exact_match.split.first
|
81
|
-
normalized = ("gem " + exact_match).gsub(/[()]/, "'")
|
82
|
-
self.gem.name = normalized.gsub(/#{gem_name}/, "'#{gem_name}',")
|
61
|
+
def set_no_version(gem)
|
62
|
+
if no_version
|
63
|
+
gem.no_version!
|
64
|
+
end
|
83
65
|
end
|
84
66
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
67
|
+
def skip_bundle?
|
68
|
+
gems.nil? ||
|
69
|
+
gems.empty? ||
|
70
|
+
gems.select(&:valid?).empty? ||
|
71
|
+
!gemfile.needs_bundle? ||
|
72
|
+
no_install
|
90
73
|
end
|
91
74
|
|
92
75
|
def run_bundle
|
data/lib/gemrat/version.rb
CHANGED
data/spec/gem_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Gemrat::Gem do
|
3
|
+
before do
|
4
|
+
class Gemrat::Gem
|
5
|
+
def stubbed_response
|
6
|
+
File.read("./spec/resources/rubygems_response_shim_for_#{name}")
|
7
|
+
rescue Errno::ENOENT
|
8
|
+
""
|
9
|
+
end
|
10
|
+
alias_method :fetch_all, :stubbed_response
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:subject) { Gemrat::Gem.new }
|
15
|
+
|
16
|
+
context "when gem is platform dependent" do
|
17
|
+
before { subject.name = "thin" }
|
18
|
+
|
19
|
+
it { should be_platform_dependent }
|
20
|
+
|
21
|
+
context "for linux" do
|
22
|
+
before do
|
23
|
+
Kernel.silence_warnings { Gemrat.const_set("SYSTEM", "gnu-linux") }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns correct version" do
|
27
|
+
subject.to_s.should == "gem 'thin', '1.5.1'"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "for windows" do
|
32
|
+
before do
|
33
|
+
Kernel.silence_warnings { Gemrat.const_set("SYSTEM", "x86-mingw32") }
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns correct version" do
|
37
|
+
puts subject.to_s
|
38
|
+
subject.to_s.should == "gem 'thin', '1.2.11'"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/gemrat_spec.rb
CHANGED
@@ -6,14 +6,21 @@ describe Gemrat do
|
|
6
6
|
test_gemfile.close
|
7
7
|
|
8
8
|
|
9
|
-
class Gemrat::
|
10
|
-
def stubbed_response
|
11
|
-
File.read("./spec/resources/rubygems_response_shim_for_#{
|
9
|
+
class Gemrat::Gem
|
10
|
+
def stubbed_response
|
11
|
+
File.read("./spec/resources/rubygems_response_shim_for_#{name}")
|
12
12
|
rescue Errno::ENOENT
|
13
13
|
""
|
14
14
|
end
|
15
15
|
alias_method :fetch_all, :stubbed_response
|
16
16
|
end
|
17
|
+
|
18
|
+
class Gemrat::Runner
|
19
|
+
def stub_bundle
|
20
|
+
puts "Bundling...".green
|
21
|
+
end
|
22
|
+
alias_method :run_bundle, :stub_bundle
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
after :each do
|
@@ -35,67 +42,222 @@ describe Gemrat do
|
|
35
42
|
File.delete("TestGemfile")
|
36
43
|
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
context "when valid arguments are given" do
|
46
|
+
context "for one gem" do
|
47
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "-g", "TestGemfile") }}
|
48
|
+
|
49
|
+
it "adds latest gem version to gemfile" do
|
50
|
+
output.should include("'sinatra', '1.4.3' added to your Gemfile")
|
51
|
+
gemfile_contents = File.open('TestGemfile', 'r').read
|
52
|
+
gemfile_contents.should include("gem 'sinatra', '1.4.3'")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "runs bundle install" do
|
56
|
+
output.should include("Bundling")
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the --no-install flag is given" do
|
60
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "-g", "TestGemfile", "--no-install") }}
|
61
|
+
it "adds latest gem version to gemfile" do
|
62
|
+
output.should include("'sinatra', '1.4.3' added to your Gemfile")
|
63
|
+
gemfile_contents = File.open('TestGemfile', 'r').read
|
64
|
+
gemfile_contents.should include("gem 'sinatra', '1.4.3'")
|
50
65
|
end
|
51
66
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
output.should include("'minitest', '5.0.5' added to your Gemfile")
|
57
|
-
output.should include("'rails', '3.2.13' added to your Gemfile")
|
58
|
-
gemfile_contents = File.open('TestGemfile', 'r').read
|
59
|
-
gemfile_contents.should include("\ngem 'sinatra', '1.4.3'")
|
60
|
-
gemfile_contents.should include("\ngem 'minitest', '5.0.5'")
|
61
|
-
gemfile_contents.should include("\ngem 'rails', '3.2.13'\n")
|
62
|
-
output.should include("Bundling")
|
63
|
-
end
|
67
|
+
it "does not run bundle install" do
|
68
|
+
output.should_not include("Bundling")
|
69
|
+
end
|
70
|
+
end
|
64
71
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
context "when the --no-version flag is given" do
|
73
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "-g", "TestGemfile", "--no-version") }}
|
74
|
+
it "adds the gem without the version" do
|
75
|
+
output.should include("'sinatra' added to your Gemfile")
|
76
|
+
gemfile_contents = File.open('TestGemfile', 'r').read
|
77
|
+
gemfile_contents.should =~ /gem 'sinatra'$/
|
78
|
+
end
|
79
|
+
|
80
|
+
it "runs bundle install" do
|
81
|
+
output.should include("Bundling")
|
74
82
|
end
|
75
83
|
end
|
76
84
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
85
|
+
pending "when the --environment or -e flag is given" do
|
86
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "-g", "TestGemfile", "--environment test") }}
|
87
|
+
it "adds the gem to the specifiyed environment" do
|
88
|
+
output.should include "'sinatra' added to test environment in your Gemfile"
|
89
|
+
gemfile_contents = File.open('TestGemfile', 'r').read
|
90
|
+
gemfile_contents.should include("group :test do")
|
91
|
+
gemfile_contents.should include("gem 'sinatra', '1.4.3'")
|
84
92
|
end
|
85
93
|
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "for multiple gems" do
|
97
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "rails", "minitest", "-g", "TestGemfile") } }
|
98
|
+
it "adds latest gem versions to the gemfile" do
|
99
|
+
output.should include("'sinatra', '1.4.3' added to your Gemfile")
|
100
|
+
output.should include("'minitest', '5.0.5' added to your Gemfile")
|
101
|
+
output.should include("'rails', '3.2.13' added to your Gemfile")
|
102
|
+
gemfile_contents = File.open('TestGemfile', 'r').read
|
103
|
+
gemfile_contents.should include("\ngem 'sinatra', '1.4.3'")
|
104
|
+
gemfile_contents.should include("\ngem 'minitest', '5.0.5'")
|
105
|
+
gemfile_contents.should include("\ngem 'rails', '3.2.13'")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "runs bundle install" do
|
109
|
+
output.should include("Bundling")
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when one of the gems is invalid" do
|
113
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "beer_maker_2000", "minitest", "-g", "TestGemfile") } }
|
114
|
+
|
115
|
+
it "adds valid gems to the gemfile" do
|
116
|
+
output.should include("'sinatra', '1.4.3' added to your Gemfile")
|
117
|
+
output.should include("'minitest', '5.0.5' added to your Gemfile")
|
118
|
+
output.should include("#{Gemrat::Messages::GEM_NOT_FOUND % "beer_maker_2000"}")
|
119
|
+
end
|
120
|
+
|
121
|
+
it "runs bundle install" do
|
122
|
+
output.should include("Bundling")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
["when gem name is left out from the arguments", "",
|
129
|
+
"when -h is given in the arguments", "-h",
|
130
|
+
"when --help is given in the arguments", "--help"].each_slice(2) do |ctx, arg|
|
131
|
+
context ctx do
|
132
|
+
it "prints usage" do
|
133
|
+
output = capture_stdout { Gemrat::Runner.run(arg == "" ? nil : arg) }
|
134
|
+
output.should include(Gemrat::Messages::USAGE)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
["when -v is given in the arguments", "-v",
|
140
|
+
"when --version is given in the arginemts", "--version"].each_slice(2) do |ctx, arg|
|
141
|
+
context ctx do
|
142
|
+
it "prints gemrat version" do
|
143
|
+
output = capture_stdout { Gemrat::Runner.run(arg) }
|
144
|
+
output.should include(Gemrat::VERSION)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "when a non-existant flag is given in the arguments" do
|
150
|
+
it "prints out the help message" do
|
151
|
+
output = capture_stdout { Gemrat::Runner.run("--doesnt-exist") }
|
152
|
+
output.should include(Gemrat::Messages::USAGE)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when gem is not found" do
|
157
|
+
before do
|
158
|
+
Gemrat::Runner.stub(:gem) do
|
159
|
+
gem = Gem.new
|
160
|
+
gem.invalid!
|
161
|
+
end
|
162
|
+
@gem_name = "unexistent_gem"
|
163
|
+
end
|
164
|
+
|
165
|
+
let(:output) { capture_stdout { Gemrat::Runner.run(@gem_name) } }
|
166
|
+
|
167
|
+
it "prints a nice error message" do
|
168
|
+
output.should include("#{Gemrat::Messages::GEM_NOT_FOUND % @gem_name}")
|
169
|
+
end
|
170
|
+
|
171
|
+
it "skips bundle install" do
|
172
|
+
output.should_not include("Bundling...")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when gem already exists in a gemfile" do
|
177
|
+
|
178
|
+
context "and the gem is the newest version" do
|
179
|
+
before do
|
180
|
+
test_gemfile = File.open("TestGemfile", "w")
|
181
|
+
test_gemfile << %Q{https://rubygems.org'
|
182
|
+
# Specify your gem's dependencies in gemrat.gemspec
|
183
|
+
gem 'minitest', '5.0.5'}
|
184
|
+
test_gemfile.close
|
185
|
+
end
|
186
|
+
|
187
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("minitest", "-g", "TestGemfile")} }
|
188
|
+
|
189
|
+
it "informs that the gem already exists" do
|
190
|
+
output.should include("gem 'minitest' already exists")
|
191
|
+
end
|
86
192
|
|
87
|
-
|
193
|
+
it "skips bundle install" do
|
194
|
+
output.should_not include("Bundling...")
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "and there is a newer version" do
|
199
|
+
before do
|
200
|
+
test_gemfile = File.open("TestGemfile", "w")
|
201
|
+
test_gemfile << %Q{https://rubygems.org'
|
202
|
+
# Specify your gem's dependencies in gemrat.gemspec
|
203
|
+
gem 'minitest', '5.0.4'}
|
204
|
+
test_gemfile.close
|
205
|
+
end
|
206
|
+
|
207
|
+
context "and the update is rejected" do
|
88
208
|
before do
|
89
|
-
|
90
|
-
@gem_name = "unexistent_gem"
|
209
|
+
Gemrat::Gemfile.any_instance.stub(:input) { "no\n" }
|
91
210
|
end
|
92
211
|
|
93
|
-
|
94
|
-
|
95
|
-
|
212
|
+
let(:output) { capture_stdout { Gemrat::Runner.run("minitest", "-g", "TestGemfile")} }
|
213
|
+
|
214
|
+
it "informs about the new gem version" do
|
215
|
+
output.should include("there is a newer version of the gem")
|
216
|
+
end
|
217
|
+
|
218
|
+
it "doesn't add the new gem version in the gemfile" do
|
219
|
+
File.read("TestGemfile").should_not match(/minitest.+5\.0\.5/)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "leaves the old gem version in the gemfile" do
|
223
|
+
File.read("TestGemfile").should match(/minitest.+5\.0\.4/)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "skips bundle install" do
|
96
227
|
output.should_not include("Bundling...")
|
97
228
|
end
|
98
229
|
end
|
230
|
+
|
231
|
+
["and the update is approved with inputing y", "y\n",
|
232
|
+
"and the update is approved by pressing enter", "\n"].each_slice(2) do |ctx, arg|
|
233
|
+
context ctx do
|
234
|
+
before do
|
235
|
+
Gemrat::Gemfile.any_instance.stub(:input) { arg }
|
236
|
+
end
|
237
|
+
|
238
|
+
let!(:output) { capture_stdout { Gemrat::Runner.run("minitest", "-g", "TestGemfile")} }
|
239
|
+
|
240
|
+
it "asks if you want to add the newer gem" do
|
241
|
+
output.should include("there is a newer version of the gem")
|
242
|
+
end
|
243
|
+
|
244
|
+
it "updates the gem version in the gemfile" do
|
245
|
+
File.read("TestGemfile").should match(/minitest.+5\.0\.5/)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "informs that the gem has been updated to the newest version" do
|
249
|
+
output.should include("Updated 'minitest' to version '5.0.5'")
|
250
|
+
end
|
251
|
+
|
252
|
+
it "doesn't add gem twice in the gemfile" do
|
253
|
+
File.open("TestGemfile").grep(/minitest/).count.should eq(1)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "runs bundle install" do
|
257
|
+
output.should include("Bundling...")
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
99
261
|
end
|
100
262
|
end
|
101
263
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
thin (1.5.1, 1.2.11 x86-mingw32 x86-mswin32, 0.7.1 x86-mswin32-60)
|
2
|
+
thin-async-test (1.0.0)
|
3
|
+
thin-attach_socket (0.1)
|
4
|
+
thin-auth-ntlm (0.0.4)
|
5
|
+
thin-fun_embed (0.0.3)
|
6
|
+
thin-glazed (0.1.0)
|
7
|
+
thin-preforker (0.0.4)
|
8
|
+
thin-rails (1.0.1)
|
9
|
+
thin-service (0.0.1)
|
10
|
+
thin_async (0.1.1)
|
11
|
+
thin_balance (0.2.0)
|
12
|
+
thin_http (0.1.1)
|
13
|
+
thin_models (0.1.4)
|
14
|
+
thin_out_backups (0.0.1)
|
15
|
+
thin_service (0.0.5)
|
16
|
+
Thin_Upstart (1.2.1)
|
17
|
+
Thin_Upstreams (0.3.0)
|
18
|
+
thincloud-auth (0.1.2)
|
19
|
+
thincloud-authentication (0.6.5)
|
20
|
+
thincloud-deployment (1.0.1)
|
21
|
+
thincloud-postmark (0.4.0)
|
22
|
+
thincloud-resque (0.1.4)
|
23
|
+
thincloud-test (1.0.0)
|
24
|
+
thincloud-test-rails (1.0.0)
|
25
|
+
thingiverse (0.0.7)
|
26
|
+
things (0.1.0 x86-darwin-9)
|
27
|
+
things-client (0.2.4)
|
28
|
+
things-fetcher (0.1.3)
|
29
|
+
things-rb (0.4.0)
|
30
|
+
thingtank (0.3.6)
|
31
|
+
thinking-sphinx (3.0.3)
|
32
|
+
thinking-sphinx-099 (1.3.2)
|
33
|
+
thinking-sphinx-allen (1.3.18.4)
|
34
|
+
thinking-sphinx-raspell (1.1.2)
|
35
|
+
thinking-sphinx-rspec-matchers (0.0.2)
|
36
|
+
thinking-sphinx-shoulda-matchers (0.0.2)
|
37
|
+
thinkingtank (0.0.9)
|
38
|
+
thinknear (0.1.2)
|
39
|
+
thinlayer-chef-boundary-annotations-handler (0.1.2)
|
40
|
+
thinner (0.1.4)
|
41
|
+
thinning (0.1.1)
|
42
|
+
thinp_xml (0.0.4)
|
43
|
+
thinreports (0.7.6)
|
44
|
+
thinreports-handler (0.1.2)
|
45
|
+
thinreports-rails (0.1.3)
|
data/spec/spec_helper.rb
CHANGED
@@ -7,3 +7,13 @@ require 'pry'
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
# some (optional) config here
|
9
9
|
end
|
10
|
+
|
11
|
+
module Kernel
|
12
|
+
def silence_warnings
|
13
|
+
original_verbosity = $VERBOSE
|
14
|
+
$VERBOSE = nil
|
15
|
+
result = yield
|
16
|
+
$VERBOSE = original_verbosity
|
17
|
+
return result
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dru Riley
|
8
8
|
- Hrvoje Simic
|
9
|
+
- Marko Ivanek
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
13
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: colored
|
@@ -81,6 +82,20 @@ dependencies:
|
|
81
82
|
- - '>='
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: guard-rspec
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
84
99
|
description: Add the latest version of a gem to your Gemfile from the command line.
|
85
100
|
email:
|
86
101
|
- dru@drurly.com
|
@@ -93,6 +108,7 @@ files:
|
|
93
108
|
- .gitignore
|
94
109
|
- .rspec
|
95
110
|
- Gemfile
|
111
|
+
- Guardfile
|
96
112
|
- LICENSE.txt
|
97
113
|
- README.md
|
98
114
|
- Rakefile
|
@@ -100,13 +116,17 @@ files:
|
|
100
116
|
- gemrat.gemspec
|
101
117
|
- lib/gemrat.rb
|
102
118
|
- lib/gemrat/arguments.rb
|
119
|
+
- lib/gemrat/gem.rb
|
120
|
+
- lib/gemrat/gemfile.rb
|
103
121
|
- lib/gemrat/messages.rb
|
104
122
|
- lib/gemrat/runner.rb
|
105
123
|
- lib/gemrat/version.rb
|
124
|
+
- spec/gem_spec.rb
|
106
125
|
- spec/gemrat_spec.rb
|
107
126
|
- spec/resources/rubygems_response_shim_for_minitest
|
108
127
|
- spec/resources/rubygems_response_shim_for_rails
|
109
128
|
- spec/resources/rubygems_response_shim_for_sinatra
|
129
|
+
- spec/resources/rubygems_response_shim_for_thin
|
110
130
|
- spec/spec_helper.rb
|
111
131
|
homepage: https://github.com/DruRly/gemrat
|
112
132
|
licenses:
|
@@ -133,8 +153,10 @@ signing_key:
|
|
133
153
|
specification_version: 4
|
134
154
|
summary: Add the latest version of a gem to your Gemfile from the command line.
|
135
155
|
test_files:
|
156
|
+
- spec/gem_spec.rb
|
136
157
|
- spec/gemrat_spec.rb
|
137
158
|
- spec/resources/rubygems_response_shim_for_minitest
|
138
159
|
- spec/resources/rubygems_response_shim_for_rails
|
139
160
|
- spec/resources/rubygems_response_shim_for_sinatra
|
161
|
+
- spec/resources/rubygems_response_shim_for_thin
|
140
162
|
- spec/spec_helper.rb
|