specific_install 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTg5NmQ2ZTU3YTY5ZTYwYjE1ZjdjZTVlMjI2MmRiNzljMjMzOGZlNA==
4
+ MWNmNjQ1MTg3NDk1OWU0ZmFhYWMwYzE3ZGUyYmQxOTlmOTc1OGFhMQ==
5
5
  data.tar.gz: !binary |-
6
- MDBiNDM4MmEyZTljMTljMWRiMjYwYmMwZTA4MjhlOTI1ZmRkZTRjYQ==
6
+ NzUxMTM1ZmZhNTM1YmI2OTU0YTIxNzczY2YyYWE5N2FkZDJmNjc5ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjlmNjFjZWY1YmIyYTMyZTcxN2ZiNDg1OWFiYTBhMTI2MDA1NDlmNzhlY2Ew
10
- MzljM2JmNjRiZTQwMWExZDAyMmFiN2YxYWE1MmQ0MGVjNjg3NDY2NTAxMjJh
11
- ZjM1M2JmNmNiMzFkYzViYjFkNDAyNzA2OWM2ZDI3YTQ0NDAxODY=
9
+ ODhlMDE5NjRhNTI1NmZmMmRkMzIwM2JlYzg0OTRmNTc5ZGFiN2Y4MmM0YTg1
10
+ YzVjYjAwNTI5ZDIxNzczNDU4YmUzMzE2YTM2MzhiNzE2OTM5ZGRiNzBmMDFl
11
+ NThkYjdjMjBhMTYwMjAzNzQyMjIzMTAzYWI1ZWMxOTY0MmI4ZTk=
12
12
  data.tar.gz: !binary |-
13
- NGNjOTliMWNhNWVkNjJiNDY2MjZmNjBhZWFjMWIzNzIxM2RiZDhlYzkyMWM5
14
- ZTA4MmNlZWE4YzJmYWJhNmI4ZTYxY2MxYzM2OTQ1YzQ3NGQ0NjZkYmMxNzI1
15
- NmFmZTNmMjE4MTQxYmY4NGQzMTZhNDAyNGYyZjRhM2M1MTE4YTg=
13
+ MTI2MzEwYzkwYmNhZWU2ZjlmOGZhZWQyNTAwOTBlZTQ2ZjI0ZTJkMzc0NjM5
14
+ NzBlMzQ1NDMzNjMyMjQ3ZjljZjdlODJlMjJhMjRiYjQ0NzNkYWNkMjQwMGFj
15
+ Mjk1YmMzOTRkYTdiMjUyMDJkNzRjNDg5Mjc0ODE1N2RmYjJkNDQ=
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ desc "Uninstall specific_install and release, then reinstall"
4
+ task :rubygems do
5
+ sh "gem uninstall specific_install --executables"
6
+ Rake::Task["release"].invoke
7
+ sh "gem install specific_install"
8
+ end
@@ -1,19 +1,20 @@
1
1
  require 'rubygems/command_manager'
2
2
  require 'rubygems/dependency_installer'
3
- require 'rubygems/builder'
4
3
  require 'tempfile'
5
4
  require 'backports'
6
5
  require 'fileutils'
7
6
  require 'open-uri'
8
7
 
9
8
  class Gem::Commands::SpecificInstallCommand < Gem::Command
9
+ attr_accessor :output
10
10
 
11
11
  def description
12
12
  "Allows you to install an 'edge' gem straight from its github repository or from a web site"
13
13
  end
14
14
 
15
- def initialize
15
+ def initialize(output=STDOUT)
16
16
  super 'specific_install', description
17
+ @output = output
17
18
 
18
19
  add_option('-l', '--location LOCATION', arguments) do |location|
19
20
  options[:location] = location
@@ -26,7 +27,7 @@ class Gem::Commands::SpecificInstallCommand < Gem::Command
26
27
  end
27
28
 
28
29
  def arguments
29
- "LOCATION like http://github.com/rdp/ruby_tutorials_core or git://github.com/rdp/ruby_tutorials_core.git or http://host/gem_name.gem"
30
+ "LOCATION like http://github.com/rdp/ruby_tutorials_core or git://github.com/rdp/ruby_tutorials_core.git or http://host/gem_name.gem\n" +
30
31
  "BRANCH (optional) like beta, or new-feature"
31
32
  end
32
33
 
@@ -35,64 +36,74 @@ class Gem::Commands::SpecificInstallCommand < Gem::Command
35
36
  end
36
37
 
37
38
  def execute
38
- unless options[:location]
39
- puts "No location received. Use `gem specific_install -l http://example.com/rdp/specific_install`"
40
- exit 1
39
+ @loc ||= set_location
40
+ @branch ||= set_branch if set_branch
41
+ if @loc.nil?
42
+ raise ArgumentError, "No location received. Use `gem specific_install -l http://example.com/rdp/specific_install`"
41
43
  end
42
- # options are
43
- # http://github.com/githubsvnclone/rdoc.git
44
- # git://github.com/githubsvnclone/rdoc.git
45
- # git@github.com:rdp/install_from_git.git
46
- # http://github.com/rdp/install_from_git [later]
47
- # http://host/gem_name.gem
48
- # rdp/specific_install
49
- dir = Dir.mktmpdir
50
- begin
51
- loc = options[:location]
52
- case loc
53
- when /^http(.*)\.gem$/
54
- Dir.chdir dir do
55
- say "downloading #{loc}"
56
- gem_name = loc.split("/").last
57
- download(loc, gem_name)
58
-
59
- if install_gemspec
60
- success_message
61
- else
62
- puts "failed"
63
- end
64
- end
65
- when /\.git$/
66
- say 'git installing from ' + loc
44
+ Dir.mktmpdir do |dir|
45
+ @dir = dir
46
+ determine_source_and_install
47
+ end
48
+ end
67
49
 
68
- system("git clone #{loc} #{dir}")
69
- install_from_git(dir)
70
- when %r(.*/.*)
71
- puts "Installing from git@github.com:#{loc}.git"
50
+ def determine_source_and_install
51
+ case @loc
52
+ when /^https?(.*)\.gem$/
53
+ install_gem
54
+ when /\.git$/
55
+ install_git
56
+ when %r(.*/.*)
57
+ install_shorthand
58
+ else
59
+ warn 'Error: must end with .git to be a git repository' +
60
+ 'or be in shorthand form: rdp/specific_install'
61
+ end
62
+ end
72
63
 
73
- system("git clone git@github.com:#{loc}.git #{dir}")
74
- install_from_git(dir)
64
+ def install_gem
65
+ Dir.chdir @dir do
66
+ output.puts "downloading #{@loc}"
67
+ download(@loc, gem_name)
68
+
69
+ if install_gemspec
70
+ success_message
75
71
  else
76
- puts 'Error: must end with .git to be a git repository' +
77
- 'or be in shorthand form: rdp/specific_install'
72
+ output.puts "Failed"
78
73
  end
79
- ensure
80
- FileUtils.rm_rf dir
81
74
  end
75
+ end
82
76
 
77
+ def gem_name
78
+ @gem_name ||= @loc.split("/").last
83
79
  end
84
80
 
85
- private
81
+ def install_git
82
+ output.puts 'git installing from ' + @loc
83
+
84
+ redirect_for_specs = ENV.fetch( "SPECIFIC_INSTALL_SPEC" ) { "" }
85
+ system("git clone #{@loc} #{@dir} #{redirect_for_specs}")
86
+ install_from_git(@dir)
87
+ end
88
+
89
+ def install_shorthand
90
+ output.puts "Installing from git@github.com:#{@loc}.git"
91
+
92
+ redirect_for_specs = ENV.fetch( "SPECIFIC_INSTALL_SPEC" ) { "" }
93
+ system("git clone git@github.com:#{@loc}.git #{@dir} #{redirect_for_specs}")
94
+ install_from_git(@dir)
95
+ end
86
96
 
87
97
  def download( full_url, output_name )
88
98
  File.open(output_name, "wb") do |output_file|
89
- output_file.write(open(full_url).read)
99
+ uri = URI.parse(full_url)
100
+ output_file.write(uri.read)
90
101
  end
91
102
  end
92
103
 
93
104
  def install_from_git(dir)
94
105
  Dir.chdir dir do
95
- change_to_branch(options[:branch]) if options[:branch]
106
+ change_to_branch(@branch) if @branch
96
107
  ['', 'rake gemspec', 'rake gem', 'rake build', 'rake package'].each do |command|
97
108
  system command
98
109
  if install_gemspec
@@ -103,21 +114,54 @@ class Gem::Commands::SpecificInstallCommand < Gem::Command
103
114
  end
104
115
  end
105
116
 
117
+ def set_location
118
+ options[:location] || options[:args][0]
119
+ end
120
+
121
+ def set_branch
122
+ options[:branch] || options[:args][1]
123
+ end
124
+
106
125
  def success_message
107
- puts 'Successfully installed'
126
+ output.puts 'Successfully installed'
108
127
  end
109
128
 
110
129
  def install_gemspec
111
- if gemspec_file = Dir['*.gemspec'][0]
130
+ gem = find_or_build_gem
131
+
132
+ inst = Gem::DependencyInstaller.new
133
+ inst.install gem
134
+ end
135
+
136
+ def find_or_build_gem
137
+ if gemspec_exists?
112
138
  gemspec = Gem::Specification.load(gemspec_file)
113
- gem = Gem::Builder.new(gemspec).build
114
- elsif gem = Dir['**/*.gem'][0]
139
+ Gem::Package.build gemspec
140
+ elsif gemfile
141
+ gemfile
142
+ else
143
+ raise ArgumentError, "Can't find gemspec or gem"
144
+ end
145
+ end
146
+
147
+ def gemspec_file(name = "*.gemspec")
148
+ Dir[name][0]
149
+ end
150
+
151
+ def gemspec_exists?(name = "*.gemspec")
152
+ if gemspec_file(name)
153
+ File.exists?(gemspec_file(name))
115
154
  else
116
155
  false
117
156
  end
157
+ end
118
158
 
119
- inst = Gem::DependencyInstaller.new
120
- inst.install gem
159
+ def gemfile(name = '**/*.gem')
160
+ if Dir[name].empty?
161
+ false
162
+ else
163
+ Dir[name][0]
164
+ end
121
165
  end
122
166
 
123
167
  def change_to_branch(branch)
@@ -1,3 +1,3 @@
1
1
  module SpecificInstall
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ require 'simplecov-vim/formatter'
3
+ require 'rspec'
4
+ require 'rspec/mocks'
5
+
6
+ SimpleCov.start do
7
+ formatter SimpleCov::Formatter::VimFormatter
8
+ end
9
+
10
+ require 'rubygems_plugin'
@@ -0,0 +1,209 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ require 'open3'
4
+
5
+ describe Gem::Commands::SpecificInstallCommand do
6
+ before do
7
+ module Kernel
8
+ alias_method :real_system, :system
9
+
10
+ def system(cmd)
11
+ 'system "#{cmd}"'
12
+ end
13
+
14
+ def puts(cmd)
15
+ cmd
16
+ end
17
+ end
18
+
19
+ end
20
+ after do
21
+ module Kernel
22
+ alias_method :system, :real_system
23
+ end
24
+ end
25
+
26
+ subject { Gem::Commands::SpecificInstallCommand.new(StringIO.new) }
27
+ describe "#gem_name" do
28
+ it "sets gem_name from location" do
29
+ subject.instance_variable_set(:@loc, "stuff/foo/bar")
30
+ expect(subject.gem_name).to eq("bar")
31
+ end
32
+ end
33
+
34
+ context "disable #install_from_git" do
35
+ before do
36
+ class Gem::Commands::SpecificInstallCommand
37
+ def install_from_git(dir)
38
+ dir
39
+ end
40
+ end
41
+ subject.instance_variable_set(:@dir, "foo")
42
+ end
43
+ describe "#install_git" do
44
+ before do
45
+ subject.instance_variable_set(:@loc, "bar")
46
+ end
47
+ it "sends correct command to system" do
48
+ subject.should_receive(:system).with(/git clone bar foo/)
49
+ subject.install_git
50
+ end
51
+ end
52
+
53
+ describe "#install_shorthand" do
54
+ it "formats the shorthand into a git repo" do
55
+ subject.instance_variable_set(:@loc, "bar/zoz")
56
+ subject.should_receive(:system).with(%r{git clone git@github.com:bar/zoz.git foo})
57
+ subject.install_shorthand
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "#success_message" do
63
+ it "returns correct message" do
64
+ subject.output.should_receive(:puts).with('Successfully installed')
65
+ subject.success_message
66
+ end
67
+ end
68
+
69
+ describe "#install_gemspec" do
70
+ context "when no gemspec or gem" do
71
+ xit "returns false" do
72
+ expect( subject.install_gemspec ).to eq(false)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#gemspec_exists?" do
78
+ it "response true to when exists" do
79
+ expect( subject.gemspec_exists? ).to be_true
80
+ end
81
+
82
+ it "responds false when not present" do
83
+ expect( subject.gemspec_exists?("*.gemNOTPRESENT") ).to be_false
84
+ end
85
+ end
86
+
87
+ describe "#gemfile" do
88
+ it "response false when not existing" do
89
+ expect( subject.gemfile("*.gemNOTPRESENT") ).to be_false
90
+ end
91
+ it "response true to when exists" do
92
+ expect( subject.gemfile("**/*.gem") ).to be_true
93
+ end
94
+ end
95
+
96
+ describe "#determine_source_and_install" do
97
+ it "executes http gem requests" do
98
+ subject.instance_variable_set(:@loc, "http://example.com/rad.gem")
99
+ subject.should_receive(:install_gem)
100
+ subject.determine_source_and_install
101
+ end
102
+ it "executes https gem requests" do
103
+ subject.instance_variable_set(:@loc, "https://example.com/rad.gem")
104
+ subject.should_receive(:install_gem)
105
+ subject.determine_source_and_install
106
+ end
107
+ it "executes https git install requests" do
108
+ subject.instance_variable_set(:@loc, "https://example.com/rad.git")
109
+ subject.should_receive(:install_git)
110
+ subject.determine_source_and_install
111
+ end
112
+ it "executes git url git install requests" do
113
+ subject.instance_variable_set(:@loc, "git@github.com:example/rad.git")
114
+ subject.should_receive(:install_git)
115
+ subject.determine_source_and_install
116
+ end
117
+ it "executes shorthand github install requests" do
118
+ subject.instance_variable_set(:@loc, "example/rad")
119
+ subject.should_receive(:install_shorthand)
120
+ subject.determine_source_and_install
121
+ end
122
+ it "executes shorthand github install requests" do
123
+ subject.instance_variable_set(:@loc, "example")
124
+ subject.should_receive(:warn)
125
+ subject.determine_source_and_install
126
+ end
127
+ end
128
+
129
+ describe "#set_location" do
130
+ it "sets from options[location]" do
131
+ subject.options[:location] = "example"
132
+ expect( subject.set_location ).to eq("example")
133
+ end
134
+ it "sets from options[args]" do
135
+ subject.options[:location] = nil
136
+ subject.options[:args] = ["args"]
137
+ expect( subject.set_location ).to eq("args")
138
+ end
139
+ it "sets neither and results in nil" do
140
+ subject.options[:location] = nil
141
+ subject.options[:args] = []
142
+ expect( subject.set_location ).to be_nil
143
+ end
144
+ end
145
+
146
+ describe "#execute" do
147
+ it "raises error when no location received" do
148
+ subject.options[:location] = nil
149
+ subject.options[:args] = []
150
+ expect{ subject.execute }.to raise_error(ArgumentError)
151
+ end
152
+ end
153
+
154
+ end
155
+
156
+
157
+ describe "Integration Tests" do
158
+
159
+ $STDOUT = StringIO.new
160
+ let(:output) { StringIO.new }
161
+ subject { Gem::Commands::SpecificInstallCommand.new(output) }
162
+ before(:all) do
163
+ # ENV.store( "SPECIFIC_INSTALL_SPEC", '2&> /dev/null' )
164
+ end
165
+ before(:each) do
166
+ `gem uninstall specific_install --executables 2&> /dev/null`
167
+ `rake install 2&> /dev/null`
168
+ end
169
+
170
+ after(:all) do
171
+ `gem uninstall specific_install --executables 2&> /dev/null`
172
+ `gem install specific_install`
173
+ ENV.delete( "SPECIFIC_INSTALL_SPEC" )
174
+ end
175
+
176
+ context "working URIs" do
177
+ it "installs from https" do
178
+ url = "https://github.com/rdp/specific_install.git"
179
+ subject.instance_variable_set(:@loc, url)
180
+ subject.options[:args] = []
181
+ stdout, status = Open3.capture2 "gem specific_install #{url}"
182
+ expect(stdout).to match(/Successfully installed/)
183
+ end
184
+ it "installs from http" do
185
+ url = "http://github.com/rdp/specific_install.git"
186
+ subject.instance_variable_set(:@loc, url)
187
+ subject.options[:args] = []
188
+ stdout, status = Open3.capture2 "gem specific_install #{url}"
189
+ expect(stdout).to match(/Successfully installed/)
190
+ end
191
+ it "installs from shorthand" do
192
+ url = "rdp/specific_install"
193
+ subject.instance_variable_set(:@loc, url)
194
+ subject.options[:args] = []
195
+ stdout, status = Open3.capture2 "gem specific_install #{url}"
196
+ expect(stdout).to match(/Successfully installed/)
197
+ end
198
+ it "installs from git" do
199
+ url = "git@github.com:zph/buff.git"
200
+ stdout, status = Open3.capture2 "gem specific_install #{url}"
201
+ expect(stdout).to match(/Successfully installed/)
202
+ end
203
+ it "installs from packaged gem" do
204
+ url = "https://rubygems.org/downloads/specific_install-0.2.7.gem"
205
+ stdout, status = Open3.capture2 "gem specific_install #{url}"
206
+ expect(stdout).to match(/Successfully installed/)
207
+ end
208
+ end
209
+ end
@@ -26,4 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency 'sane'
27
27
  s.add_development_dependency "bundler", "~> 1.3"
28
28
  s.add_development_dependency "rake"
29
+ s.add_development_dependency "rspec"
30
+ s.add_development_dependency "simplecov"
31
+ s.add_development_dependency "simplecov-vim"
29
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specific_install
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Pack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-21 00:00:00.000000000 Z
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backports
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-vim
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description: rubygems plugin that allows you you to install a gem from from its github
84
126
  repository (like 'edge'), or from an arbitrary URL
85
127
  email: rogerdpack@gmail.com
@@ -95,6 +137,8 @@ files:
95
137
  - lib/rubygems/commands/specific_install_command.rb
96
138
  - lib/rubygems_plugin.rb
97
139
  - lib/specific_install/version.rb
140
+ - spec/spec_helper.rb
141
+ - spec/specific_install_spec.rb
98
142
  - specific_install.gemspec
99
143
  homepage: https://github.com/rdp/specific_install
100
144
  licenses:
@@ -121,5 +165,7 @@ signing_key:
121
165
  specification_version: 4
122
166
  summary: rubygems plugin that allows you you to install a gem from from its github
123
167
  repository (like 'edge'), or from an arbitrary URL
124
- test_files: []
168
+ test_files:
169
+ - spec/spec_helper.rb
170
+ - spec/specific_install_spec.rb
125
171
  has_rdoc: