robot-vim 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,12 +17,15 @@ RobotVim is developed with Vim 7.3, Ruby 1.9.2, and bundler.
17
17
  ## Example Usage
18
18
 
19
19
  ### Initialization
20
- Create an instance that will use your user's default Vim
20
+ Create an instance that will use your user's default Vim and vimrc
21
21
  robot = RobotVim::Runner.new()
22
22
 
23
- Or create an instance with a specific Vim
23
+ Create an instance with a specific Vim
24
24
  robot = RobotVim::Runner.new(:vim => "/bin/vim")
25
25
 
26
+ Create an instance with a specific vimrc
27
+ robot = RobotVim::Runner.new(:vimrc => "something/vimrc")
28
+
26
29
  ### Running commands
27
30
  Commands are passed in as a string with one command per line.
28
31
 
@@ -53,7 +56,7 @@ spec/integration\_spec.rb contains examples of asserting with Rspec
53
56
  - automatically save buffer to an output file after running the last command(done)
54
57
  - automatically close Vim after running the last command(done)
55
58
  - take a string for input and write out a temporary file that Vim will run against(done)
56
- - figure out if there is a way to specify a .vimrc file without disabling the normal Vim initialization process
59
+ - figure out if there is a way to specify a .vimrc file without disabling the normal Vim initialization process(done)
57
60
 
58
61
  ## Author
59
62
  RobotVim is developed by Matt Margolis | mrmargolis | matt@mattmargolis.net
@@ -1,15 +1,21 @@
1
1
  module RobotVim
2
2
  class Runner
3
3
  DEFAULT_VIM_BINARY = "vim"
4
+ DEFAULT_VIMRC = File.join(File.expand_path("~"), ".vimrc")
4
5
 
5
6
  def initialize(args={})
6
7
  @vim_binary = args[:vim]
8
+ @vimrc = args[:vimrc]
7
9
  end
8
10
 
9
11
  def vim_binary
10
12
  @vim_binary || DEFAULT_VIM_BINARY
11
13
  end
12
14
 
15
+ def vimrc
16
+ @vimrc || DEFAULT_VIMRC
17
+ end
18
+
13
19
  def run(args={})
14
20
  output_file_name = RobotVim::FileNameGenerator.generate
15
21
  commands = args[:commands] + output_write_command(output_file_name) + vim_close_commands
@@ -28,7 +34,7 @@ module RobotVim
28
34
  private
29
35
 
30
36
  def invoke_vim(script_file_path, input_file)
31
- Kernel.send(:`, "#{self.vim_binary} -n -s #{script_file_path} #{input_file}")
37
+ Kernel.send(:`, "#{self.vim_binary} -N -n -u #{self.vimrc} -s #{script_file_path} #{input_file}")
32
38
  end
33
39
 
34
40
  def output_write_command(output_file_name)
@@ -1,5 +1,5 @@
1
1
  module Robot
2
2
  module Vim
3
- VERSION = "0.10.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ function! ConvertNotToGross(...)
2
+ :s/not/gross
3
+ endfunction
@@ -1,32 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Automating Vim with RobotVim" do
4
- let(:runner){RobotVim::Runner.new}
4
+ describe "Input files" do
5
+ let(:runner){RobotVim::Runner.new}
6
+ context "When using an existing input file" do
7
+ it "can sort a file using vim" do
8
+ input_path = File.join(File.dirname(__FILE__), "fixtures", "unsorted_file.txt")
9
+ unsorted_text = File.read(input_path)
10
+
11
+ commands = <<-COMMANDS
12
+ :%!sort
13
+ COMMANDS
5
14
 
6
- context "When using an existing input file" do
7
- it "can sort a file using vim" do
8
- input_path = File.join(File.dirname(__FILE__), "fixtures", "unsorted_file.txt")
9
- unsorted_text = File.read(input_path)
15
+ result = runner.run(:commands => commands, :input_file => input_path)
16
+ result.should == unsorted_text.split("\n").sort.join("\n") + "\n"
17
+ end
18
+ end
10
19
 
11
- commands = <<-COMMANDS
12
- :%!sort
13
- COMMANDS
20
+ context "When using a string for input" do
21
+ it "can uppercase the first line" do
22
+ text_to_uppercase = "this line should be uppercased"
23
+
24
+ commands = <<-COMMANDS
25
+ :normal 0|gU$
26
+ COMMANDS
14
27
 
15
- result = runner.run(:commands => commands, :input_file => input_path)
16
- result.should == unsorted_text.split("\n").sort.join("\n") + "\n"
28
+ result = runner.run(:commands => commands, :input_file => text_to_uppercase)
29
+ result.should == text_to_uppercase.upcase + "\n"
30
+ end
17
31
  end
18
32
  end
19
33
 
20
- context "When using a string for input" do
21
- it "can uppercase the first line" do
22
- text_to_uppercase = "this line should be uppercased"
34
+ describe "Specifying a vimrc" do
35
+ it "can run a little function defined in a vimrc" do
36
+ input = "Beer bread is delicious. Beard bread is not"
23
37
 
24
38
  commands = <<-COMMANDS
25
- :normal 0|gU$
39
+ :call ConvertNotToGross()
26
40
  COMMANDS
27
41
 
28
- result = runner.run(:commands => commands, :input_file => text_to_uppercase)
29
- result.should == text_to_uppercase.upcase + "\n"
42
+ vimrc = File.join(File.dirname(__FILE__), "fixtures", "vimrc_with_not_to_gross")
43
+ runner = RobotVim::Runner.new(:vimrc => vimrc)
44
+ result = runner.run(:commands => commands, :input_file => input)
45
+ result.should == input.sub("not", "gross") + "\n"
30
46
  end
31
47
  end
32
48
 
@@ -16,6 +16,19 @@ describe RobotVim::Runner do
16
16
  end
17
17
  end
18
18
 
19
+ describe "specifying which vimrc to use" do
20
+ it "uses the vimrc passed in during initialization if provided" do
21
+ vimrc = "/testing/vimrc"
22
+ runner = RobotVim::Runner.new(:vimrc => vimrc)
23
+ runner.vimrc.should == vimrc
24
+ end
25
+
26
+ it "defaults to vimrc in user's path" do
27
+ runner = RobotVim::Runner.new()
28
+ runner.vimrc.should == RobotVim::Runner::DEFAULT_VIMRC
29
+ end
30
+ end
31
+
19
32
  describe "running commands in vim" do
20
33
  let(:vim_path){"/usr/local/bin/vim"}
21
34
  let(:runner){RobotVim::Runner.new(:vim => vim_path)}
@@ -47,6 +60,11 @@ describe RobotVim::Runner do
47
60
  run_robot
48
61
  end
49
62
 
63
+ it "runs vim in No-compatible mode so vim properly loads vimrcs and plugins" do
64
+ Kernel.should_receive(:`).with(/-N/)
65
+ run_robot
66
+ end
67
+
50
68
  it "invokes vim with a script file" do
51
69
  script_file_path = "path/to/script/file"
52
70
  RobotVim::ScriptFile.stub(:open).and_yield(script_file_path)
@@ -54,6 +72,13 @@ describe RobotVim::Runner do
54
72
  run_robot
55
73
  end
56
74
 
75
+ it "invokes vim with a vimrc" do
76
+ vimrc = "some/vimrc"
77
+ runner.stub(:vimrc).and_return(vimrc)
78
+ Kernel.should_receive(:`).with(/-u #{vimrc}/)
79
+ run_robot
80
+ end
81
+
57
82
  it "adds a write command to the user supplied commands" do
58
83
  RobotVim::ScriptFile.should_receive(:open).with(/\n\:w/)
59
84
  run_robot
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: robot-vim
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.10.0
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Margolis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-27 00:00:00 -05:00
13
+ date: 2011-03-28 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ files:
82
82
  - lib/robot-vim/version.rb
83
83
  - robot-vim.gemspec
84
84
  - spec/fixtures/unsorted_file.txt
85
+ - spec/fixtures/vimrc_with_not_to_gross
85
86
  - spec/integration_spec.rb
86
87
  - spec/robot-vim/file_name_generator_spec.rb
87
88
  - spec/robot-vim/input_file_spec.rb