gemrat 0.4.1 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 216961a16064cfeb7bfa46e9ce9b54405a441c95
4
- data.tar.gz: 1f2c880ce9f37dc74fe800bea04d42ee9e72a447
3
+ metadata.gz: 8e2af8b711a88c22469a2f7fe4107132b71bb807
4
+ data.tar.gz: 71a4550605b41a74807f30929a3f98d1a126b5b5
5
5
  SHA512:
6
- metadata.gz: ec21cc4ad4f28d5d8ba95122552e9c8fb2d4a9381f7cc8dd93d20ae2ed72d2a70d923b4ffd31262f1fbbc8eb1a44f957252f79afa95864123fd7aad72c6d2b4c
7
- data.tar.gz: bd683873802d13ca0511b14900ea3495d6865be95e9998762acafc70816c535cccf7f17d54d09be11e84c5f68747461d1388f98da81a633e7679ef76ef6767d6
6
+ metadata.gz: 8ebf6870e8a129a7fb6a1906cf793e778bfbe8f6ab589f6b18ff3881e63848d5b88df63950845e17b06fcf105b2e85ac49c0c15976c4afd2eaaa3f862586721d
7
+ data.tar.gz: bc07ef9354a291fea02078a386366b3db7a918bf6342d4466b95efb951634d3c01e6f0e7be6225f74b3be3a67e2ad3ab293e87c97c679caa53c24987c081b6df
data/README.md CHANGED
@@ -32,7 +32,7 @@ $ gemrat rspec capybara sidekiq
32
32
 
33
33
  Get help
34
34
  <pre>
35
- $ gemrat --help OR gemrat -h
35
+ $ gemrat
36
36
 
37
37
  Gemrat
38
38
 
@@ -42,8 +42,11 @@ Usage: gemrat [GEM_NAME] [OPTIONS]
42
42
 
43
43
  Options:
44
44
 
45
- -g [--gemfile] # Specify the Gemfile to be used. Defaults to 'Gemfile'.
46
- -h [--help] # Print these usage instructions.
45
+ -g, --gemfile GEMFILE # Specify the Gemfile to be used, defaults to 'Gemfile'
46
+ --no-install # Skip executing bundle after adding the gem.
47
+ --no-version # Do not add a version to the gemfile.
48
+ -v, --version # Show current gemrat version.
49
+ -h, --help # Print these usage instructions.
47
50
  </pre>
48
51
  <br/>
49
52
 
@@ -53,6 +53,14 @@ module Gemrat
53
53
  options.no_version = true
54
54
  end
55
55
 
56
+ opts.on("-p", "--pessimistic", "# Add gem with a pessimistic operator (~>)") do
57
+ options.version_constraint = "pessimistic"
58
+ end
59
+
60
+ opts.on("-o", "--optimistic", "# Add gem with an optimistic operator (>=)") do
61
+ options.version_constraint = "optimistic"
62
+ end
63
+
56
64
  opts.on_tail("-h", "--help", "# Print these usage instructions.") do
57
65
  puts opts
58
66
  raise PrintHelp
@@ -1,12 +1,13 @@
1
1
  module Gemrat
2
2
  class Gem
3
3
  class NotFound < StandardError; end
4
+ class InvalidFlags < StandardError; end
4
5
 
5
- attr_accessor :name, :valid, :action
6
+ attr_accessor :name, :valid, :action, :version_constraint, :no_version
6
7
  alias_method :valid?, :valid
7
8
 
8
9
  ACTIONS = OpenStruct.new({:add => "add", :update => "update",
9
- :skip => "skip", :no_version => "no version"})
10
+ :skip => "skip"})
10
11
 
11
12
  def initialize
12
13
  self.valid = true
@@ -15,7 +16,7 @@ module Gemrat
15
16
  end
16
17
 
17
18
  def to_s
18
- @output ||= "gem '#{name}', '#{version}'"
19
+ @output ||= get_output
19
20
  end
20
21
 
21
22
  def invalid!
@@ -45,7 +46,7 @@ module Gemrat
45
46
  def skip?
46
47
  self.action == ACTIONS.skip
47
48
  end
48
-
49
+
49
50
  def add!
50
51
  self.action = ACTIONS.add
51
52
  end
@@ -54,16 +55,42 @@ module Gemrat
54
55
  self.action == ACTIONS.add
55
56
  end
56
57
 
57
- def no_version!
58
- self.action = ACTIONS.no_version
58
+ def no_version?
59
+ no_version
59
60
  end
60
61
 
61
- def no_version?
62
- self.action == ACTIONS.no_version
62
+ def no_version!
63
+ self.no_version = true
63
64
  end
64
65
 
65
66
  private
66
67
 
68
+ def get_output
69
+ if self.no_version? && self.version_constraint
70
+ raise InvalidFlags
71
+ end
72
+ if self.no_version?
73
+ return with_no_version
74
+ elsif self.version_constraint
75
+ return with_version_constraint
76
+ else
77
+ return "gem '#{name}', '#{version}'"
78
+ end
79
+ end
80
+
81
+ def with_no_version
82
+ "gem '#{name}'"
83
+ end
84
+
85
+ def with_version_constraint
86
+ case self.version_constraint
87
+ when "optimistic"
88
+ "gem '#{name}', '>= #{version}'"
89
+ when "pessimistic"
90
+ "gem '#{name}', '~> #{version}'"
91
+ end
92
+ end
93
+
67
94
  def platform_dependent?
68
95
  versions.count > 1
69
96
  end
@@ -28,12 +28,6 @@ module Gemrat
28
28
  f.close
29
29
  end
30
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
31
  needs_bundle!
38
32
  end
39
33
  ensure
@@ -48,19 +42,19 @@ module Gemrat
48
42
  end
49
43
 
50
44
  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)
45
+ @grep_file = file.grep(/gem.*#{gem.name}.*/)
46
+ @current_gem_version = get_current_gem_version
47
+ raise DuplicateGemFound if duplicate_gem? gem
54
48
 
55
- return unless current_gem_version =~ /\S/
49
+ return unless @current_gem_version =~ /\S/
56
50
 
57
- if current_gem_version < gem.version
58
- prompt_gem_replacement(gem, current_gem_version)
51
+ if @current_gem_version < gem.version
52
+ prompt_gem_replacement(gem)
59
53
  end
60
54
  end
61
55
 
62
- def prompt_gem_replacement(gem, gem_version)
63
- print (Messages::NEWER_GEM_FOUND % [gem.name, gem.version, gem_version]).chomp + " "
56
+ def prompt_gem_replacement(gem)
57
+ print (Messages::NEWER_GEM_FOUND % [gem.name, gem.version, @current_gem_version]).chomp + " "
64
58
  case input
65
59
  when /n|no/
66
60
  gem.skip!
@@ -69,11 +63,12 @@ module Gemrat
69
63
  end
70
64
  end
71
65
 
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
66
+ def duplicate_gem? gem
67
+ !@grep_file.empty? && (@current_gem_version == gem.version || @current_gem_version.empty?)
68
+ end
69
+
70
+ def get_current_gem_version
71
+ @grep_file.to_s.match(/\d[\d|.]+/).to_s
77
72
  end
78
73
 
79
74
  def input
@@ -28,5 +28,11 @@ module Gemrat
28
28
  Gem '%s' already exists, but there is a newer version of the gem (v %s > v %s).
29
29
  Update version? (Y/n)
30
30
  NEWER_GEM_FOUND
31
+
32
+ INVALID_FLAGS = <<-INVALID_FLAGS
33
+
34
+ You have specified flags that are incompatile with each other. The most common cause
35
+ is specifiying the --no-version and --optimistic or --pessimistic flags together.
36
+ INVALID_FLAGS
31
37
  end
32
38
  end
@@ -28,7 +28,8 @@ module Gemrat
28
28
 
29
29
  private
30
30
 
31
- attr_accessor :gems, :gemfile, :no_install, :no_version
31
+ attr_accessor :gems, :gemfile, :no_install, :no_version,
32
+ :version_constraint
32
33
 
33
34
  def parse_arguments(*args)
34
35
  Arguments.new(*args).tap do |a|
@@ -36,6 +37,7 @@ module Gemrat
36
37
  self.gemfile = a.gemfile
37
38
  self.no_install = a.options.no_install
38
39
  self.no_version = a.options.no_version
40
+ self.version_constraint = a.options.version_constraint
39
41
  end
40
42
  end
41
43
 
@@ -48,16 +50,24 @@ module Gemrat
48
50
  rescue Gemfile::DuplicateGemFound
49
51
  puts Messages::DUPLICATE_GEM_FOUND % gem.name
50
52
  gem.invalid!
53
+ rescue Gem::InvalidFlags
54
+ puts Messages::INVALID_FLAGS.red
55
+ gem.invalid!
51
56
  end
52
57
 
53
58
  def for_each_gem
54
59
  gems && gems.each do |gem|
55
60
  set_no_version(gem)
61
+ set_version_constraint(gem)
56
62
  self.gem = gem
57
63
  yield
58
64
  end
59
65
  end
60
66
 
67
+ def set_version_constraint(gem)
68
+ gem.version_constraint = version_constraint
69
+ end
70
+
61
71
  def set_no_version(gem)
62
72
  if no_version
63
73
  gem.no_version!
@@ -1,3 +1,3 @@
1
1
  module Gemrat
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.5"
3
3
  end
@@ -80,8 +80,32 @@ describe Gemrat do
80
80
  it "runs bundle install" do
81
81
  output.should include("Bundling")
82
82
  end
83
+
84
+ ["when the --optimistic flag is given with the --no-version flag", "--optimistic",
85
+ "when the --pessimistic flag is given with the --no-version flag", "--pessimistic"].each_slice(2) do |ctx, flag|
86
+ context ctx do
87
+ let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "-g", "TestGemfile", "--no-version", flag) }}
88
+ it "should raise Invalid Flags error" do
89
+ output.should include(Gemrat::Messages::INVALID_FLAGS)
90
+ end
91
+ end
92
+ end
83
93
  end
84
94
 
95
+ ["when the --optimistic flag is given", "--optimistic", ">=",
96
+ "when the --pessimistic flag is given", "--pessimistic", "~>",
97
+ "when the -o flag is given", "-o", ">=",
98
+ "when the -p flag is given", "-p", "~>"].each_slice(3) do |ctx, flag, constraint|
99
+ context ctx do
100
+ let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "-g", "TestGemfile", flag) }}
101
+ it "should add the gem with appropriate version constraint" do
102
+ output.should include("gem 'sinatra', '#{constraint} 1.4.3'")
103
+ gemfile_contents = File.open('TestGemfile', 'r').read
104
+ gemfile_contents.should include("gem 'sinatra', '#{constraint} 1.4.3'")
105
+ end
106
+ end
107
+ end
108
+
85
109
  pending "when the --environment or -e flag is given" do
86
110
  let(:output) { capture_stdout { Gemrat::Runner.run("sinatra", "-g", "TestGemfile", "--environment test") }}
87
111
  it "adds the gem to the specifiyed environment" do
@@ -174,7 +198,6 @@ describe Gemrat do
174
198
  end
175
199
 
176
200
  context "when gem already exists in a gemfile" do
177
-
178
201
  context "and the gem is the newest version" do
179
202
  before do
180
203
  test_gemfile = File.open("TestGemfile", "w")
@@ -259,5 +282,53 @@ describe Gemrat do
259
282
  end
260
283
  end
261
284
  end
285
+
286
+ context "and the gem doesn't have a version specified" do
287
+ before do
288
+ test_gemfile = File.open("TestGemfile", "w")
289
+ test_gemfile << %Q{https://rubygems.org'
290
+ # Specify your gem's dependencies in gemrat.gemspec
291
+ gem 'minitest'}
292
+ test_gemfile.close
293
+ end
294
+
295
+ let!(:output) { capture_stdout { Gemrat::Runner.run("minitest", "-g", "TestGemfile")} }
296
+
297
+ it "informs that a gem already exists" do
298
+ output.should include("gem 'minitest' already exists")
299
+ end
300
+
301
+ it "doesn't add the gem to the gemfile" do
302
+ File.read("TestGemfile").should_not match(/minitest.+5\.0\.5/)
303
+ end
304
+
305
+ it "doesn't touch the old gem in the gemfile" do
306
+ File.read("TestGemfile").should match(/minitest.$/)
307
+ end
308
+ end
309
+
310
+ context "the gem doesn't have a version specified and is mentioned in the comments (turbolinks issue)" do
311
+ before do
312
+ test_gemfile = File.open("TestGemfile", "w")
313
+ test_gemfile << %Q{https://rubygems.org'
314
+ # Specify your gem's dependencies in gemrat.gemspec
315
+ # Read more: https://github.com/rails/turbolinks
316
+ gem 'turbolinks'}
317
+ test_gemfile.close
318
+ end
319
+
320
+ let!(:output) { capture_stdout { Gemrat::Runner.run("turbolinks", "-g", "TestGemfile") }}
321
+ it "should not prompt for a replacement" do
322
+ output.should_not include("there is a newer version of the gem")
323
+ end
324
+
325
+ it "should notify you that the gem already exists and abort" do
326
+ output.should include("gem 'turbolinks' already exists in your Gemfile. Skipping...")
327
+ end
328
+
329
+ it "doesn't add the gem to the gemfile" do
330
+ File.read("TestGemfile").should_not match(/turbolinks.+1\.2\.0/)
331
+ end
332
+ end
262
333
  end
263
334
  end
@@ -0,0 +1,5 @@
1
+ turbolinks (1.2.0)
2
+ turbolinks-analytics (0.0.1)
3
+ turbolinks-js (0.6.1)
4
+ turbolinks-redirect (0.0.1)
5
+ turbolinks_transitions (0.0.5)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dru Riley
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-29 00:00:00.000000000 Z
13
+ date: 2013-07-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colored
@@ -127,6 +127,7 @@ files:
127
127
  - spec/resources/rubygems_response_shim_for_rails
128
128
  - spec/resources/rubygems_response_shim_for_sinatra
129
129
  - spec/resources/rubygems_response_shim_for_thin
130
+ - spec/resources/rubygems_response_shim_for_turbolinks
130
131
  - spec/spec_helper.rb
131
132
  homepage: https://github.com/DruRly/gemrat
132
133
  licenses:
@@ -159,4 +160,5 @@ test_files:
159
160
  - spec/resources/rubygems_response_shim_for_rails
160
161
  - spec/resources/rubygems_response_shim_for_sinatra
161
162
  - spec/resources/rubygems_response_shim_for_thin
163
+ - spec/resources/rubygems_response_shim_for_turbolinks
162
164
  - spec/spec_helper.rb