vpm 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +1 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile.lock +13 -5
  4. data/README.md +13 -11
  5. data/Rakefile +26 -6
  6. data/bin/vpm +1 -1
  7. data/lib/transaction.rb +27 -0
  8. data/lib/vpm.rb +52 -16
  9. data/lib/vpm/command_options.rb +15 -0
  10. data/lib/vpm/command_options/abstract_command_options.rb +25 -0
  11. data/lib/vpm/command_options/install.rb +18 -0
  12. data/lib/vpm/command_options/list.rb +9 -0
  13. data/lib/vpm/commands.rb +18 -0
  14. data/lib/vpm/commands/install.rb +37 -0
  15. data/lib/vpm/commands/install_all_plugins.rb +8 -0
  16. data/lib/vpm/commands/invalid_command.rb +10 -0
  17. data/lib/vpm/commands/list.rb +8 -0
  18. data/lib/vpm/commands/setup.rb +63 -0
  19. data/lib/vpm/git.rb +17 -0
  20. data/lib/vpm/manifest_parser.rb +19 -1
  21. data/lib/vpm/plugin.rb +29 -5
  22. data/lib/vpm/plugins.rb +55 -0
  23. data/lib/vpm/runner.rb +55 -0
  24. data/lib/vpm/tasks.rb +7 -0
  25. data/lib/vpm/tasks/clone_pathogen.rb +13 -0
  26. data/lib/vpm/tasks/create_autoload_dir.rb +5 -0
  27. data/lib/vpm/tasks/create_bundle_dir.rb +5 -0
  28. data/lib/vpm/tasks/create_directory.rb +16 -0
  29. data/lib/vpm/tasks/create_our_rc_file.rb +16 -0
  30. data/lib/vpm/tasks/inject_our_load_script.rb +28 -0
  31. data/lib/vpm/tasks/move_pathogen_file.rb +17 -0
  32. data/lib/vpm/version.rb +1 -1
  33. data/spec/commands/install_spec.rb +10 -0
  34. data/spec/manifest_parser_spec.rb +3 -13
  35. data/spec/plugins_spec.rb +41 -0
  36. data/spec/spec_helper.rb +2 -4
  37. data/spec/tasks/create_bundle_dir_spec.rb +26 -0
  38. data/spec/tasks/create_directory_spec.rb +33 -0
  39. data/spec/tasks/create_our_rc_file_spec.rb +31 -0
  40. data/spec/tasks/inject_our_load_script_spec.rb +39 -0
  41. data/spec/tasks/move_pathogen_file_spec.rb +42 -0
  42. data/spec/transaction_spec.rb +65 -0
  43. data/vpm.gemspec +6 -4
  44. metadata +63 -17
  45. data/lib/vpm/git_plugin.rb +0 -22
  46. data/spec/git_plugin_spec.rb +0 -12
  47. data/spec/vpm_test.rb +0 -13
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe CreateDirectory do
4
+ before do
5
+ @dir = File.expand_path "temp"
6
+ @task = CreateDirectory.new @dir
7
+ end
8
+
9
+ context "#perform" do
10
+ it "creates the directory if it doesn't already exist" do
11
+ Dir.exists?(@dir).should be_false
12
+ @task.perform
13
+ Dir.exists?(@dir).should be_true
14
+ end
15
+
16
+ it "works even if the directory already exists" do
17
+ Dir.exists?(@dir).should be_true
18
+ @task.perform
19
+ Dir.exists?(@dir).should be_true
20
+ end
21
+ end
22
+
23
+ context "#undo" do
24
+ it "removes #{@dir} if this task created it" do
25
+ FileUtils.rmdir @dir
26
+ Dir.exists?(@dir).should be_false
27
+ @task.perform
28
+ Dir.exists?(@dir).should be_true
29
+ @task.undo
30
+ Dir.exists?(@dir).should be_false
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe CreateOurRCFile do
4
+ before do
5
+ @task = CreateOurRCFile.new
6
+ end
7
+
8
+ context "#perform" do
9
+ it "creates the file if it doesn't exist" do
10
+ File.exists?(VPM.vpmrc_path).should be_false
11
+ @task.perform
12
+ File.exists?(VPM.vpmrc_path).should be_true
13
+ end
14
+
15
+ it "inserts the call to pathogen#infect into the file" do
16
+ @task.perform
17
+ File.open(VPM.vpmrc_path, "r") do |file|
18
+ file.read.should include "call pathogen#infect()"
19
+ end
20
+ end
21
+ end
22
+
23
+ context "#undo" do
24
+ it "removes the rc file" do
25
+ @task.perform
26
+ File.exists?(VPM.vpmrc_path).should be_true
27
+ @task.undo
28
+ File.exists?(VPM.vpmrc_path).should be_false
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe InjectOurLoadScript do
4
+ context "#perform" do
5
+ it "sources our file at the top of the user's vimrc" do
6
+ Dir.mktmpdir do |temp_dir|
7
+ @task = InjectOurLoadScript.new(temp_dir)
8
+ FileUtils.touch File.expand_path(VPM.vimrc_path)
9
+ File.read(VPM.vimrc_path).should_not include "source #{VPM.vpmrc_path}"
10
+ @task.perform
11
+ File.read(VPM.vimrc_path).start_with?("source #{VPM.vpmrc_path}").should be_true
12
+ end
13
+ end
14
+
15
+ it "retains exactly the same text as the old file" do
16
+ Dir.mktmpdir do |temp_dir|
17
+ @task = InjectOurLoadScript.new(temp_dir)
18
+ File.open(VPM.vimrc_path, "w") {|file| file.puts "test\nother"}
19
+ File.read(VPM.vimrc_path).should_not include "source #{VPM.vpmrc_path}"
20
+ @task.perform
21
+ File.read(VPM.vimrc_path).should == "source #{VPM.vpmrc_path}\ntest\nother\n"
22
+ end
23
+ end
24
+ end
25
+
26
+ context "#undo" do
27
+ it "replaces the old file" do
28
+ Dir.mktmpdir do |temp_dir|
29
+ @task = InjectOurLoadScript.new(temp_dir)
30
+ File.open(VPM.vimrc_path, "w") {|file| file.print "test\nother"}
31
+ File.read(VPM.vimrc_path).should_not include "source #{VPM.vpmrc_path}"
32
+ @task.perform
33
+ File.read(VPM.vimrc_path).should == "source #{VPM.vpmrc_path}\ntest\nother\n"
34
+ @task.undo
35
+ File.read(VPM.vimrc_path).should == "test\nother"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe MovePathogenFile do
4
+ before do
5
+ @temp_dir = File.expand_path "temp"
6
+ @source_path = File.join(@temp_dir, "pathogen", "autoload", "pathogen.vim")
7
+ FileUtils.mkdir_p File.join(@temp_dir, "pathogen", "autoload")
8
+ FileUtils.touch @source_path
9
+ @autoload_path = File.join(VPM.vim_dir_path, "autoload")
10
+ @destination_path = File.join(@autoload_path, "pathogen.vim")
11
+ FileUtils.mkdir_p @autoload_path
12
+ @task = MovePathogenFile.new @temp_dir
13
+ end
14
+
15
+ context "#perform" do
16
+ it "moves the pathogen.vim file from its current location to vim's autoload directory" do
17
+ File.exists?(@destination_path).should be_false
18
+ @task.perform
19
+ File.exists?(@destination_path).should be_true
20
+ end
21
+ end
22
+
23
+ context "#undo" do
24
+ it "removes pathogen.vim if the task installed it" do
25
+ FileUtils.rm @destination_path
26
+ File.exists?(@destination_path).should be_false
27
+ @task.perform
28
+ File.exists?(@destination_path).should be_true
29
+ @task.undo
30
+ File.exists?(@destination_path).should be_false
31
+ end
32
+
33
+ it "does not remove the file if it already existed" do
34
+ FileUtils.touch @destination_path
35
+ File.exists?(@destination_path).should be_true
36
+ @task.perform
37
+ File.exists?(@destination_path).should be_true
38
+ @task.undo
39
+ File.exists?(@destination_path).should be_true
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Transaction do
4
+ context "#perform" do
5
+ before do
6
+ @transaction = Transaction.new
7
+ @task_one = double "Task One"
8
+ @task_two = double "Task Two"
9
+ @transaction << @task_one
10
+ @transaction << @task_two
11
+ end
12
+
13
+ it 'runs each task when the transaction is peformed' do
14
+ @task_one.should_receive("perform").and_return true
15
+ @task_two.should_receive("perform").and_return true
16
+ @transaction.perform
17
+ end
18
+
19
+ it 'undoes every task that has been run so far if any of them return false' do
20
+ @task_one.should_receive("perform").and_return true
21
+ @task_one.should_receive "undo"
22
+ @task_two.should_receive("perform").and_return false
23
+ @task_two.should_receive "undo"
24
+ @transaction.perform
25
+ end
26
+
27
+ it 'skips any tasks following a failing one' do
28
+ @task_one.should_receive("perform").and_return false
29
+ @task_one.should_receive "undo"
30
+ @task_two.should_not_receive "peform"
31
+ @transaction.perform
32
+ end
33
+
34
+ it 'undoes the tasks in the opposite order they were performed' do
35
+ @transaction = Transaction.new
36
+ result = []
37
+ @task_one = Object.new
38
+ @task_two = Object.new
39
+ @task_one.stub(:perform).and_return true
40
+ @task_one.stub(:undo) do result << "task one" end
41
+ @task_two.stub(:perform).and_return false
42
+ @task_two.stub(:undo) do result << "task two" end
43
+ @transaction << @task_one
44
+ @transaction << @task_two
45
+ @transaction.perform
46
+ result.should == ["task two", "task one"]
47
+ end
48
+
49
+ it 'undoes all of the tasks if one raises an execption' do
50
+ @task_one.should_receive("perform").and_return true
51
+ @task_one.should_receive "undo"
52
+ @task_two.should_receive("perform") { raise "an error" }
53
+ @task_two.should_receive "undo"
54
+ expect { @transaction.perform }.to raise_error
55
+ end
56
+
57
+ it 'rethrows exceptions raised by a task' do
58
+ @task_one.should_receive("perform").and_return true
59
+ @task_one.should_receive "undo"
60
+ @task_two.should_receive("perform") { raise "an error" }
61
+ @task_two.should_receive "undo"
62
+ expect { @transaction.perform }.to raise_error
63
+ end
64
+ end
65
+ end
data/vpm.gemspec CHANGED
@@ -5,10 +5,11 @@ require "vpm/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "vpm"
7
7
  s.version = VPM::VERSION
8
- s.authors = ["Jingwen Owen Ou"]
8
+ s.authors = ["Jingwen Owen Ou", "Michael Baker"]
9
9
  s.email = ["jingweno@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{An awesome utility for managing VIM plugins}
10
+ s.homepage = "https://github.com/jingweno/vpm"
11
+ s.summary = %q{An awesome utility for managing Vim plugins}
12
+ s.description = %q{An awesome utility for managing Vim plugins}
12
13
 
13
14
  s.rubyforge_project = "vpm"
14
15
 
@@ -19,6 +20,7 @@ Gem::Specification.new do |s|
19
20
 
20
21
  # specify any dependencies here; for example:
21
22
  s.add_development_dependency "rake"
22
- s.add_development_dependency "turn"
23
+ s.add_development_dependency "rspec"
24
+ s.add_development_dependency "fakefs"
23
25
  # s.add_runtime_dependency "rest-client"
24
26
  end
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jingwen Owen Ou
9
+ - Michael Baker
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-01-14 00:00:00.000000000 Z
13
+ date: 2012-01-21 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rake
16
- requirement: &70192619467680 !ruby/object:Gem::Requirement
17
+ requirement: &2154096600 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,10 +22,10 @@ dependencies:
21
22
  version: '0'
22
23
  type: :development
23
24
  prerelease: false
24
- version_requirements: *70192619467680
25
+ version_requirements: *2154096600
25
26
  - !ruby/object:Gem::Dependency
26
- name: turn
27
- requirement: &70192619467260 !ruby/object:Gem::Requirement
27
+ name: rspec
28
+ requirement: &2154096180 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ! '>='
@@ -32,8 +33,19 @@ dependencies:
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70192619467260
36
- description:
36
+ version_requirements: *2154096180
37
+ - !ruby/object:Gem::Dependency
38
+ name: fakefs
39
+ requirement: &2154095760 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2154095760
48
+ description: An awesome utility for managing Vim plugins
37
49
  email:
38
50
  - jingweno@gmail.com
39
51
  executables:
@@ -42,22 +54,50 @@ extensions: []
42
54
  extra_rdoc_files: []
43
55
  files:
44
56
  - .gitignore
57
+ - .rvmrc
45
58
  - Gemfile
46
59
  - Gemfile.lock
47
60
  - README.md
48
61
  - Rakefile
49
62
  - bin/vpm
63
+ - lib/transaction.rb
50
64
  - lib/vpm.rb
51
- - lib/vpm/git_plugin.rb
65
+ - lib/vpm/command_options.rb
66
+ - lib/vpm/command_options/abstract_command_options.rb
67
+ - lib/vpm/command_options/install.rb
68
+ - lib/vpm/command_options/list.rb
69
+ - lib/vpm/commands.rb
70
+ - lib/vpm/commands/install.rb
71
+ - lib/vpm/commands/install_all_plugins.rb
72
+ - lib/vpm/commands/invalid_command.rb
73
+ - lib/vpm/commands/list.rb
74
+ - lib/vpm/commands/setup.rb
75
+ - lib/vpm/git.rb
52
76
  - lib/vpm/manifest_parser.rb
53
77
  - lib/vpm/plugin.rb
78
+ - lib/vpm/plugins.rb
79
+ - lib/vpm/runner.rb
80
+ - lib/vpm/tasks.rb
81
+ - lib/vpm/tasks/clone_pathogen.rb
82
+ - lib/vpm/tasks/create_autoload_dir.rb
83
+ - lib/vpm/tasks/create_bundle_dir.rb
84
+ - lib/vpm/tasks/create_directory.rb
85
+ - lib/vpm/tasks/create_our_rc_file.rb
86
+ - lib/vpm/tasks/inject_our_load_script.rb
87
+ - lib/vpm/tasks/move_pathogen_file.rb
54
88
  - lib/vpm/version.rb
55
- - spec/git_plugin_spec.rb
89
+ - spec/commands/install_spec.rb
56
90
  - spec/manifest_parser_spec.rb
91
+ - spec/plugins_spec.rb
57
92
  - spec/spec_helper.rb
58
- - spec/vpm_test.rb
93
+ - spec/tasks/create_bundle_dir_spec.rb
94
+ - spec/tasks/create_directory_spec.rb
95
+ - spec/tasks/create_our_rc_file_spec.rb
96
+ - spec/tasks/inject_our_load_script_spec.rb
97
+ - spec/tasks/move_pathogen_file_spec.rb
98
+ - spec/transaction_spec.rb
59
99
  - vpm.gemspec
60
- homepage: ''
100
+ homepage: https://github.com/jingweno/vpm
61
101
  licenses: []
62
102
  post_install_message:
63
103
  rdoc_options: []
@@ -71,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
111
  version: '0'
72
112
  segments:
73
113
  - 0
74
- hash: 1524590733277353739
114
+ hash: -1969408185855622509
75
115
  required_rubygems_version: !ruby/object:Gem::Requirement
76
116
  none: false
77
117
  requirements:
@@ -80,15 +120,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
120
  version: '0'
81
121
  segments:
82
122
  - 0
83
- hash: 1524590733277353739
123
+ hash: -1969408185855622509
84
124
  requirements: []
85
125
  rubyforge_project: vpm
86
126
  rubygems_version: 1.8.10
87
127
  signing_key:
88
128
  specification_version: 3
89
- summary: An awesome utility for managing VIM plugins
129
+ summary: An awesome utility for managing Vim plugins
90
130
  test_files:
91
- - spec/git_plugin_spec.rb
131
+ - spec/commands/install_spec.rb
92
132
  - spec/manifest_parser_spec.rb
133
+ - spec/plugins_spec.rb
93
134
  - spec/spec_helper.rb
94
- - spec/vpm_test.rb
135
+ - spec/tasks/create_bundle_dir_spec.rb
136
+ - spec/tasks/create_directory_spec.rb
137
+ - spec/tasks/create_our_rc_file_spec.rb
138
+ - spec/tasks/inject_our_load_script_spec.rb
139
+ - spec/tasks/move_pathogen_file_spec.rb
140
+ - spec/transaction_spec.rb
@@ -1,22 +0,0 @@
1
- module VPM
2
- class GitPlugin < Plugin
3
- attr_accessor :git_commander
4
-
5
- def initialize(name, options)
6
- super
7
- @git_commander = GitCommander
8
- end
9
-
10
- def install
11
- @git_commander.clone(options[:git], VPM.plugin_dir)
12
- end
13
-
14
- module GitCommander
15
- def self.clone(repo, destination)
16
- Dir.chdir destination do
17
- `git clone #{repo}`
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe VPM::GitPlugin do
4
- it "intalls the plugin if it hasn't" do
5
- mock_git_command = MiniTest::Mock.new
6
- mock_git_command.expect(:clone, true, ["https://xxx.git", "#{ENV['HOME']}/.vim/bundle"])
7
- plugin = VPM::GitPlugin.new("command-t", :git => "https://xxx.git")
8
- plugin.git_commander = mock_git_command
9
- plugin.install
10
- mock_git_command.verify
11
- end
12
- end
data/spec/vpm_test.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe VPM do
4
- it "parses install command with args" do
5
- parser = MiniTest::Mock.new
6
-
7
- VPM.run(['intstall', 'xxx.git'])
8
- # ['<command'>, args]
9
- # InstallCommand.run(args)
10
- # RemoveCommadn.run(args)
11
- VPM.parse
12
- end
13
- end