vimpack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.autotest +13 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE +21 -0
  7. data/README.md +47 -0
  8. data/Rakefile +5 -0
  9. data/autotest/discover.rb +2 -0
  10. data/bin/vimpack +103 -0
  11. data/cucumber.yml +13 -0
  12. data/features/commands/environments.feature +26 -0
  13. data/features/commands/git.feature +77 -0
  14. data/features/commands/info.feature +28 -0
  15. data/features/commands/init.feature +47 -0
  16. data/features/commands/install.feature +50 -0
  17. data/features/commands/list.feature +18 -0
  18. data/features/commands/search.feature +137 -0
  19. data/features/commands/uninstall.feature +46 -0
  20. data/features/step_definitions/environment_steps.rb +3 -0
  21. data/features/step_definitions/file_utils_steps.rb +36 -0
  22. data/features/step_definitions/initialize_steps.rb +14 -0
  23. data/features/step_definitions/output_steps.rb +12 -0
  24. data/features/step_definitions/vimpack_git_steps.rb +91 -0
  25. data/features/support/env.rb +11 -0
  26. data/features/support/executable_paths.rb +15 -0
  27. data/lib/vimpack/commands/command.rb +46 -0
  28. data/lib/vimpack/commands/git.rb +32 -0
  29. data/lib/vimpack/commands/info.rb +26 -0
  30. data/lib/vimpack/commands/init.rb +23 -0
  31. data/lib/vimpack/commands/install.rb +35 -0
  32. data/lib/vimpack/commands/list.rb +14 -0
  33. data/lib/vimpack/commands/search.rb +37 -0
  34. data/lib/vimpack/commands/uninstall.rb +27 -0
  35. data/lib/vimpack/commands.rb +8 -0
  36. data/lib/vimpack/models/apibase.rb +7 -0
  37. data/lib/vimpack/models/base.rb +29 -0
  38. data/lib/vimpack/models/repo.rb +117 -0
  39. data/lib/vimpack/models/script.rb +110 -0
  40. data/lib/vimpack/models.rb +8 -0
  41. data/lib/vimpack/utils/api.rb +39 -0
  42. data/lib/vimpack/utils/file.rb +66 -0
  43. data/lib/vimpack/utils/file_path.rb +25 -0
  44. data/lib/vimpack/utils/git.rb +103 -0
  45. data/lib/vimpack/utils/github.rb +41 -0
  46. data/lib/vimpack/utils/io.rb +26 -0
  47. data/lib/vimpack/utils/process.rb +61 -0
  48. data/lib/vimpack/utils/vimscripts.rb +64 -0
  49. data/lib/vimpack/version.rb +4 -0
  50. data/lib/vimpack.rb +46 -0
  51. data/simplecov_setup.rb +5 -0
  52. data/spec/spec_helper.rb +32 -0
  53. data/spec/vimpack/models/repo_spec.rb +150 -0
  54. data/spec/vimpack/models/script_spec.rb +230 -0
  55. data/spec/vimpack/utils/github_spec.rb +39 -0
  56. data/spec/vimpack/utils/vimscripts_spec.rb +38 -0
  57. data/tasks/cucumber.rake +8 -0
  58. data/tasks/default.rake +2 -0
  59. data/tasks/rspec.rake +5 -0
  60. data/templates/vimrc.erb +6 -0
  61. data/vimpack.gemspec +42 -0
  62. metadata +333 -0
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+ require 'pathname'
3
+
4
+ describe Vimpack::Models::Repo do
5
+
6
+ let :vimpack, do Vimpack::Models::Repo end
7
+
8
+ %w( initialize! initialized? publish! git_exec installed_script_names
9
+ installed_scripts ).each do |meth|
10
+ it "should respond to #{meth}" do
11
+ vimpack.should respond_to(meth.to_sym)
12
+ end
13
+ end
14
+
15
+ it "should have home path set to #{HOME}" do
16
+ vimpack.home_path.to_s.should == HOME
17
+ end
18
+
19
+ context "installed_script_names" do
20
+
21
+ it "should return a collection of script names" do
22
+ vimpack.initialize!
23
+ Vimpack::Models::Script.get('rails.vim').install!
24
+ vimpack.installed_script_names.should == ['rails.vim']
25
+ end
26
+
27
+ end
28
+
29
+ context "installed_scripts" do
30
+
31
+ it "should return a collection of scripts" do
32
+ vimpack.initialize!
33
+ rails_vim_script = Vimpack::Models::Script.info('rails.vim')
34
+ rails_vim_script.install!
35
+ vimpack.installed_scripts.count.should == 1
36
+ vimpack.installed_scripts.each do |script|
37
+ script.should be_a(Vimpack::Models::Script)
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ context "publish!" do
44
+
45
+ it "should raise error with no origin remote set" do
46
+ vimpack.initialize!
47
+ expect { vimpack.publish!("[TEST] test from rspec") }.to raise_error(Vimpack::Models::Repo::OriginRemoteUnset)
48
+ end
49
+
50
+ it "should return true" do
51
+ vimpack.initialize!('git@github.com:bramswenson/vimpack-repo-test.git')
52
+ script_names = %w( rails.vim )
53
+ script_names.each do |script_name|
54
+ script = Vimpack::Models::Script.get(script_name)
55
+ if script.installed?
56
+ script.uninstall!
57
+ vimpack.publish!("[uninstall] uninstalled #{script.name}")
58
+ end
59
+ script.install!
60
+ end
61
+ vimpack.publish!("[TEST] test from rspec").should be_true
62
+ script_names.each do |script_name|
63
+ Vimpack::Models::Script.get(script_name).uninstall!
64
+ end
65
+ vimpack.publish!("[TEST] cleanup testing").should be_true
66
+ end
67
+ end
68
+
69
+ context "initialized?" do
70
+
71
+ it "should be false when no ~/.vimpack directory exists" do
72
+ vimpack.should_not be_initialized
73
+ end
74
+
75
+ it "should be true when no ~/.vimpack directory exists" do
76
+ ::FileUtils.mkdir_p(vimpack.pack_path.to_s)
77
+ ::File.should be_a_directory(::File.join(HOME, '.vimpack'))
78
+ vimpack.should be_initialized
79
+ end
80
+ end
81
+
82
+ context "initialize!" do
83
+
84
+ context "when already initialized" do
85
+
86
+ it "should raise error" do
87
+ ::FileUtils.mkdir_p(vimpack.pack_path.to_s)
88
+ ::File.should be_a_directory(::File.join(HOME, '.vimpack'))
89
+ expect { vimpack.initialize! }.to raise_error(Vimpack::Models::Repo::AlreadyInitialized)
90
+ end
91
+
92
+ end
93
+
94
+ context "when not initialized" do
95
+
96
+ [ nil, 'git@github.com:bramswenson/vimpack-repo-test.git' ].each do |repo_url_arg|
97
+
98
+ context "and given #{repo_url_arg} as the repo_url argument" do
99
+
100
+ before(:each) do
101
+ FileUtils.mkdir_p(vimpack.home_path.join('.vim'))
102
+ File.new(vimpack.home_path.join('.vimrc'), 'w').close
103
+ vimpack.initialize!(repo_url_arg)
104
+ end
105
+
106
+ it "should backup existing vim files" do
107
+ File.should exist(vimpack.home_path.join('.vim.before_vimpack'))
108
+ File.should exist(vimpack.home_path.join('.vimrc.before_vimpack'))
109
+ end
110
+
111
+ %w( .vimpack .vimpack/vim .vimpack/vim/autoload .vimpack/vim/bundle
112
+ .vimpack/scripts
113
+ ).each do |dir_path|
114
+ it "should have created a #{dir_path} directory in the home directory" do
115
+ File.should be_a_directory(::File.join(HOME, dir_path))
116
+ end
117
+ end
118
+
119
+ it "should be a git repository" do
120
+ check_git_repo(vimpack.pack_path)
121
+ end
122
+
123
+ it "should have pathogen installed into autoload/bundle" do
124
+ check_git_submodule(vimpack.vim_path.join('autoload', 'pathogen.vim'), vimpack.pack_path)
125
+ end
126
+
127
+ it "should have created a link .vim to .vimpack/vim" do
128
+ File.should be_a_directory(vimpack.vim_path.to_s)
129
+ File.should exist(vimpack.home_path.join('.vim'))
130
+ Pathname.new(vimpack.home_path.join('.vim')).realpath.to_s.gsub('/private', '').should == vimpack.vim_path.to_s
131
+ end
132
+
133
+ it "should have created a link .vimrc to .vimpack/vimrc" do
134
+ File.should exist(vimpack.pack_path.join('vimrc'))
135
+ File.should exist(vimpack.home_path.join('.vimrc'))
136
+ Pathname.new(vimpack.home_path.join('.vimrc')).realpath.to_s.gsub('/private', '').should == vimpack.pack_path.join('vimrc')
137
+ end
138
+
139
+ unless repo_url_arg.nil?
140
+
141
+ it "should have a remote origin of git@github.com:bramswenson/vimpack-repo-test.git" do
142
+ check_vimpack_remote('origin', 'git@github.com:bramswenson/vimpack-repo-test.git')
143
+ end
144
+
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,230 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vimpack::Models::Script do
4
+ let(:script_model) { Vimpack::Models::Script }
5
+
6
+ context "the class" do
7
+ %w( search get info ).each do |meth|
8
+ it "should respond to #{meth}" do
9
+ script_model.should respond_to(meth.to_sym)
10
+ end
11
+ end
12
+
13
+ context "search" do
14
+
15
+ context "by exact name" do
16
+
17
+ it "should return a 1 item collection" do
18
+ script_model.search('cucumber').count.should == 1
19
+ end
20
+
21
+ it "should return a Script as the first result in the collection" do
22
+ script_model.search('cucumber').first.should be_a(script_model)
23
+ end
24
+
25
+ end
26
+
27
+ context "by name that returns more than one result" do
28
+
29
+ it "should return a more than 1 item collection" do
30
+ script_model.search('rails').count.should > 1
31
+ end
32
+
33
+ it "should return a collection of Script instances" do
34
+ script_model.search('rails').each do |script|
35
+ script.should be_a(script_model)
36
+ end
37
+ end
38
+
39
+ end
40
+ context "by name that does not exist" do
41
+
42
+ it "should return an empty collection" do
43
+ script_model.search('boogity_boogity_boo').count.should == 0
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ context "info" do
50
+
51
+ it "should raise an error when the script does not exist" do
52
+ expect { script_model.info('boogity_boo_hoo') }.to raise_error
53
+ end
54
+
55
+ it "should return script when found" do
56
+ script_model.info('rails.vim').should be_a(script_model)
57
+ end
58
+
59
+ end
60
+
61
+ context "get" do
62
+
63
+ it "should raise an error when the script does not exist" do
64
+ expect { script_model.get('boogity_boo_hoo') }.to raise_error
65
+ end
66
+
67
+ it "should return script when found" do
68
+ script_model.get('rails.vim').should be_a(script_model)
69
+ end
70
+
71
+ end
72
+ end
73
+
74
+ context "an instance" do
75
+
76
+ context "should respond to" do
77
+ let(:script) { script_model.get('rails.vim') }
78
+ %w(
79
+ name type version author author_email version version_date url description
80
+ install! uninstall! installed? installable? install_path
81
+ ).each do |meth|
82
+ it meth do
83
+ script.should respond_to(meth.to_sym)
84
+ end
85
+ end
86
+ end
87
+
88
+ context "that exists in vim-scripts.org" do
89
+
90
+ let(:script) { script_model.get('rails.vim') }
91
+ let(:repo) { Vimpack::Models::Repo }
92
+
93
+ it "script should not be nil" do
94
+ script.should_not be_nil
95
+ end
96
+
97
+ { :name => "rails.vim",
98
+ :type => "utility",
99
+ :version => "4.3",
100
+ :version_date => '2010-09-09T17:00:00-07:00',
101
+ :author => "Tim Pope",
102
+ :author_email => "vimNOSPAM@tpope.org",
103
+ :url => "https://github.com/vim-scripts/rails.vim",
104
+ :description => "Ruby on Rails: easy file navigation, enhanced syntax highlighting, and more",
105
+ }.each_pair do |attribute, value|
106
+
107
+ it "should have a #{attribute} of '#{value}'" do
108
+ script.send(attribute).should == value
109
+ end
110
+
111
+ end
112
+
113
+ context "installable?" do
114
+
115
+ it "should be false if vimpack is not initialized" do
116
+ script.should_not be_installable
117
+ end
118
+
119
+ it "should be true if vimpack is initialized" do
120
+ repo.initialize!
121
+ script.should be_installable
122
+ end
123
+
124
+ end
125
+
126
+ context "bundle_path" do
127
+
128
+ before(:each) { repo.initialize! }
129
+
130
+ it "should have an bundle path when not installed" do
131
+ script.bundle_path.should_not be_nil
132
+ end
133
+
134
+ it "should have an bundle path when installed" do
135
+ script.install!
136
+ script.bundle_path.should_not be_nil
137
+ end
138
+
139
+ it "should be a path in the bundle dir" do
140
+ script.bundle_path.should include(Vimpack::Models::Repo.bundle_path.to_s)
141
+ end
142
+
143
+ end
144
+
145
+ context "install_path" do
146
+
147
+ before(:each) { repo.initialize! }
148
+
149
+ it "should have an install path when not installed" do
150
+ script.install_path.should_not be_nil
151
+ end
152
+
153
+ it "should have an install path when installed" do
154
+ script.install!
155
+ script.install_path.should_not be_nil
156
+ end
157
+
158
+ it "should be a path in the scripts dir" do
159
+ script.install_path.should include(Vimpack::Models::Repo.script_path.to_s)
160
+ end
161
+
162
+ it "should be a path named after the type" do
163
+ script.install_path.should match(/#{script.type}/)
164
+ end
165
+
166
+ end
167
+
168
+ context "installed?" do
169
+
170
+ before(:each) { repo.initialize! }
171
+
172
+ it "should be false if script is not installed" do
173
+ script.should_not be_installed
174
+ end
175
+
176
+ it "should be true if script is installed" do
177
+ script.install!
178
+ script.should be_installed
179
+ end
180
+
181
+ end
182
+
183
+ context "install!" do
184
+
185
+ context "when vimpack is not initialized" do
186
+ it "should raise an error" do
187
+ expect { script.install! }.to raise_error
188
+ end
189
+ end
190
+
191
+ context "when vimpack is initialized" do
192
+ before(:each) { repo.initialize! }
193
+
194
+ it "should return true when script installed without errors" do
195
+ script.install!.should be_true
196
+ end
197
+
198
+ it "should raise an error if script is already installed" do
199
+ script.install!
200
+ expect { script.install! }.to raise_error
201
+ end
202
+
203
+ end
204
+ end
205
+
206
+ context "uninstall!" do
207
+
208
+ context "when vimpack is not initialized" do
209
+ it "should raise an error" do
210
+ expect { script.uninstall! }.to raise_error
211
+ end
212
+ end
213
+
214
+ context "when vimpack is initialized" do
215
+ before(:each) { repo.initialize! }
216
+
217
+ it "should return true when script uninstalled without errors" do
218
+ script.install!
219
+ script.uninstall!.should be_true
220
+ end
221
+
222
+ it "should raise an error if script is already uninstalled" do
223
+ expect { script.uninstall! }.to raise_error
224
+ end
225
+
226
+ end
227
+ end
228
+ end
229
+ end
230
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vimpack::Utils::Github do
4
+ class GithubTest
5
+ include Vimpack::Utils::Github
6
+ end
7
+
8
+ let(:github) { GithubTest }
9
+
10
+ context ".search_all_repos" do
11
+
12
+ it "should return a collection" do
13
+ github.search_all_repos('rails').should respond_to(:[])
14
+ end
15
+
16
+ it "and the values should be github repo attributes" do
17
+ github.search_all_repos('rails').count.should be >= 1
18
+ github.search_all_repos('rails').each do |repo|
19
+ repo.name.should_not be_nil
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ context ".search_vimscript_repos" do
26
+
27
+ it "should return a collection" do
28
+ github.search_vimscript_repos('rails').should respond_to(:[])
29
+ end
30
+
31
+ it "and the github repos username should be vim-scripts" do
32
+ github.search_vimscript_repos('rails').count.should be >= 1
33
+ github.search_vimscript_repos('rails').each do |repo|
34
+ repo.username.should == 'vim-scripts'
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vimpack::Utils::Vimscripts do
4
+ class VimscriptsTest
5
+ include Vimpack::Utils::Vimscripts
6
+ end
7
+
8
+ let(:vimscripts) { VimscriptsTest }
9
+
10
+ context ".vimscripts" do
11
+
12
+ it "should be a collection of script attribute hashes" do
13
+ vimscripts.vimscripts.first["n"].should == 'test.vim'
14
+ end
15
+ end
16
+
17
+ context ".search_vimscripts" do
18
+
19
+ it "should return a collection of hash like objects" do
20
+ vimscripts.search_vimscripts('rails').each do |script|
21
+ script.should respond_to(:keys)
22
+ end
23
+ end
24
+
25
+ it "all scripts returned should include the query in the name" do
26
+ vimscripts.search_vimscripts('rails').each do |script|
27
+ (script[:description].downcase.include?('rails') or
28
+ script[:name].downcase.include?('rails')).should be_true
29
+ end
30
+ end
31
+
32
+ it "should leave the vimscripts in place" do
33
+ vimscripts.search_vimscripts('rails')
34
+ vimscripts.vimscripts.count.should be_between(3000, 4000)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ require 'cucumber'
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new(:features) do |t|
5
+ t.cucumber_opts = "--color --require features --format pretty features"
6
+ end
7
+ task :cucumber => :features
8
+ task :cuke => :features
@@ -0,0 +1,2 @@
1
+
2
+ task :default => [ :spec, :cucumber ]
data/tasks/rspec.rake ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec) do |t|
4
+ t.fail_on_error = true
5
+ end
@@ -0,0 +1,6 @@
1
+ " THE NEXT 3 LINES MUST BE FIRST
2
+ filetype off
3
+ call pathogen#runtime_append_all_bundles()
4
+ filetype plugin indent on
5
+ " ADD YOUR LINES BELOW HERE
6
+ <%= @vimrc_contents %>
data/vimpack.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "vimpack/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "vimpack"
7
+ s.version = Vimpack::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Bram Swenson"]
10
+ s.email = ["bram@craniumisajar.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{ Vim Script Package Manager }
13
+ s.description = %q{ Vim Script Package Manager based on pathogen.vim by Tim Pope }
14
+
15
+ s.rubyforge_project = "vimpack"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('bundler', '>= 1.0.13')
23
+ s.add_dependency('trollop', '~> 1.16.2')
24
+ s.add_dependency('rainbow', '~> 1.1.1')
25
+ s.add_dependency('childprocess', '~> 0.1.8')
26
+ s.add_dependency('activemodel', '~> 3.0.4')
27
+ s.add_dependency('yajl-ruby', '~> 0.8.1')
28
+ s.add_dependency('enviro', '>=0.0.4')
29
+ s.add_dependency('nokogiri', '~> 1.4.4')
30
+ s.add_dependency('octokit', '~> 0.6.3')
31
+
32
+ s.add_development_dependency('vcr')
33
+ s.add_development_dependency('webmock')
34
+ s.add_development_dependency('cucumber')
35
+ s.add_development_dependency('rspec')
36
+ s.add_development_dependency('aruba')
37
+ s.add_development_dependency('autotest-standalone')
38
+ s.add_development_dependency('autotest-growl')
39
+ s.add_development_dependency('simplecov')
40
+ s.add_development_dependency('ruby-debug19')
41
+ end
42
+