robot-vim 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -5,7 +5,9 @@ and scripts.
5
5
 
6
6
  ## Installation
7
7
  To install RobotVim run
8
+
8
9
  gem install robot-vim
10
+
9
11
  or clone this reposity and run
10
12
  rake install
11
13
 
@@ -18,12 +20,15 @@ RobotVim is developed with Vim 7.3, Ruby 1.9.2, and bundler.
18
20
 
19
21
  ### Initialization
20
22
  Create an instance that will use your user's default Vim and vimrc
23
+
21
24
  robot = RobotVim::Runner.new()
22
25
 
23
26
  Create an instance with a specific Vim
27
+
24
28
  robot = RobotVim::Runner.new(:vim => "/bin/vim")
25
29
 
26
30
  Create an instance with a specific vimrc
31
+
27
32
  robot = RobotVim::Runner.new(:vimrc => "something/vimrc")
28
33
 
29
34
  ### Running commands
@@ -32,31 +37,38 @@ Commands are passed in as a string with one command per line.
32
37
  The input file can be specified as a path to an existing input file, or as a string which RobotVim will turn into an short lived file backed buffer.
33
38
 
34
39
  commands = <<-COMMANDS
35
- RunSomeCoolCommand
36
- SomeOtherCoolCommand
40
+ :s/old/new
41
+ :normal! gg
42
+ :call setline('.', "RobotVim")
43
+ :call MyAwesomePluginFunction
37
44
  COMMANDS
38
45
 
39
46
 
40
- buffer_text = robot.run(:input_file => "some/file.txt", :commands => commands)
47
+ vim_response = robot.run(:input_file => "some/file.txt", :commands => commands)
48
+
41
49
 
42
50
  input = <<-CONTENT
43
51
  This text will be used
44
52
  as the contents of my input file
45
53
  CONTENT
46
54
 
47
- buffer_text = robot.run(:input_file => input, :commands => commands)
55
+ vim_response = robot.run(:input_file => input, :commands => commands)
56
+ buffer_text = vim_response.body
57
+
58
+ ### VimResponse
59
+
60
+ The return value of RobotVim::Runner#run is a RobotVim::VimResponse instance with the following fields
48
61
 
62
+ - body: The contents of the last buffer that was active when your commands completed
63
+ - line\_number: The line number the cursor was on when your commands completed
64
+ - column\_number: The column number the cursor was on when your commands completed
65
+
66
+ **Please submit pull requests or issues if there are additional values that you want to be able to assert against**
49
67
 
50
68
  ### Making Assertions
51
69
  Use your preferred Ruby testing library to make assertions about the buffer text string returned by RobotVim::Runner#run
52
70
 
53
- spec/integration\_spec.rb contains examples of asserting with Rspec
54
-
55
- ## TODO
56
- - automatically save buffer to an output file after running the last command(done)
57
- - automatically close Vim after running the last command(done)
58
- - take a string for input and write out a temporary file that Vim will run against(done)
59
- - figure out if there is a way to specify a .vimrc file without disabling the normal Vim initialization process(done)
71
+ Take a look at spec/integration\_spec.rb for examples of asserting with Rspec
60
72
 
61
73
  ## Author
62
- RobotVim is developed by Matt Margolis | mrmargolis | matt@mattmargolis.net
74
+ RobotVim is developed by Matt Margolis | @mrmargolis | matt@mattmargolis.net
data/lib/robot-vim.rb CHANGED
@@ -3,3 +3,5 @@ require "robot-vim/runner"
3
3
  require "robot-vim/script_file"
4
4
  require "robot-vim/input_file"
5
5
  require "robot-vim/file_name_generator"
6
+ require "robot-vim/command_generator"
7
+ require "robot-vim/vim_response"
@@ -0,0 +1,26 @@
1
+ module RobotVim
2
+ class CommandGenerator
3
+ def self.generate(user_commands, output_file)
4
+ user_commands +
5
+ record_location_command +
6
+ write_output_file_command(output_file) +
7
+ vim_close_commands
8
+ end
9
+
10
+ def self.write_output_file_command(output_file)
11
+ ":w #{output_file}\n"
12
+ end
13
+
14
+ def self.record_location_command
15
+ ":let current_line = line(\".\")\n" +
16
+ ":let current_column = col(\".\")\n" +
17
+ ":normal! G\n" +
18
+ ":execute \"normal! o\" . current_line\n" +
19
+ ":execute \"normal! o\" . current_column\n"
20
+ end
21
+
22
+ def self.vim_close_commands
23
+ "\n:%bd!\n:q!\n"
24
+ end
25
+ end
26
+ end
@@ -18,7 +18,7 @@ module RobotVim
18
18
 
19
19
  def run(args={})
20
20
  output_file_name = RobotVim::FileNameGenerator.generate
21
- commands = args[:commands] + output_write_command(output_file_name) + vim_close_commands
21
+ commands = RobotVim::CommandGenerator.generate(args[:commands], output_file_name)
22
22
 
23
23
  InputFile.path_for(args[:input_file]) do |input_file_path|
24
24
  ScriptFile.open(commands) do |script_file_path|
@@ -26,7 +26,7 @@ module RobotVim
26
26
  end
27
27
  end
28
28
 
29
- return read_output_file_contents(output_file_name)
29
+ return RobotVim::VimResponse.new(read_output_file_contents(output_file_name))
30
30
  ensure
31
31
  File.delete(output_file_name) if File.exists?(output_file_name)
32
32
  end
@@ -37,14 +37,6 @@ module RobotVim
37
37
  Kernel.send(:`, "#{self.vim_binary} -N -n -u #{self.vimrc} -s #{script_file_path} #{input_file} 2>/dev/null")
38
38
  end
39
39
 
40
- def output_write_command(output_file_name)
41
- ":w #{output_file_name}"
42
- end
43
-
44
- def vim_close_commands
45
- "\n:%bd!\n:q!\n"
46
- end
47
-
48
40
  def read_output_file_contents(output_file_name)
49
41
  File.read(output_file_name)
50
42
  end
@@ -1,5 +1,5 @@
1
1
  module Robot
2
2
  module Vim
3
- VERSION = "1.1.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ module RobotVim
2
+ class VimResponse
3
+ attr_reader :body, :column_number, :line_number
4
+ def initialize(response_string)
5
+ @response_string = response_string
6
+ lines = @response_string.split("\n")
7
+ @column_number = lines.pop.to_i
8
+ @line_number = lines.pop.to_i
9
+ @body = lines.join("\n")
10
+ end
11
+ end
12
+ end
data/robot-vim.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "robot-vim"
16
16
 
17
17
  s.add_development_dependency "bundler", ">= 1.0.0"
18
+ s.add_development_dependency "rake"
18
19
  s.add_development_dependency "rspec", "~> 2.5.0"
19
20
  s.add_development_dependency "autotest"
20
21
 
@@ -13,7 +13,7 @@ describe "Automating Vim with RobotVim" do
13
13
  COMMANDS
14
14
 
15
15
  result = runner.run(:commands => commands, :input_file => input_path)
16
- result.should == unsorted_text.split("\n").sort.join("\n") + "\n"
16
+ result.body.should == unsorted_text.split("\n").sort.join("\n")
17
17
  end
18
18
  end
19
19
 
@@ -26,7 +26,7 @@ describe "Automating Vim with RobotVim" do
26
26
  COMMANDS
27
27
 
28
28
  result = runner.run(:commands => commands, :input_file => text_to_uppercase)
29
- result.should == text_to_uppercase.upcase + "\n"
29
+ result.body.should == text_to_uppercase.upcase
30
30
  end
31
31
  end
32
32
  end
@@ -42,7 +42,7 @@ describe "Automating Vim with RobotVim" do
42
42
  vimrc = File.join(File.dirname(__FILE__), "fixtures", "vimrc_with_not_to_gross")
43
43
  runner = RobotVim::Runner.new(:vimrc => vimrc)
44
44
  result = runner.run(:commands => commands, :input_file => input)
45
- result.should == input.sub("not", "gross") + "\n"
45
+ result.body.should == input.sub("not", "gross")
46
46
  end
47
47
  end
48
48
 
@@ -58,9 +58,28 @@ yes please
58
58
  vimrc = File.join(File.dirname(__FILE__), "fixtures", "vimrc_with_user_input")
59
59
  runner = RobotVim::Runner.new(:vimrc => vimrc)
60
60
  result = runner.run(:commands => commands, :input_file => input)
61
- result.should == "yes please" + "\n"
61
+ result.body.should == "yes please"
62
62
  end
63
-
64
63
  end
65
64
 
65
+ describe "verifying location of cursor" do
66
+ it "detects the correct line and column numbers" do
67
+ input = "Here is some text\n" +
68
+ "and more on a different line\n" +
69
+ "behold, the lines just keep going\n" +
70
+ "really?"
71
+
72
+ commands = <<-COMMANDS
73
+ :normal! gg
74
+ :normal! jj
75
+ :normal! 0llll
76
+ COMMANDS
77
+
78
+ runner = RobotVim::Runner.new()
79
+ result = runner.run(:commands => commands, :input_file => input)
80
+ puts result.body
81
+ result.line_number.should == 3
82
+ result.column_number.should == 5
83
+ end
84
+ end
66
85
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe RobotVim::CommandGenerator do
4
+ describe ".generate" do
5
+ let(:output_file) { "some/file.extension" }
6
+ let(:user_commands) { "some user commands" }
7
+
8
+ let(:write_to_output_file_command) { RobotVim::CommandGenerator.write_output_file_command(output_file) }
9
+ let(:close_vim_commands) { RobotVim::CommandGenerator.vim_close_commands}
10
+ let(:record_location_command) { RobotVim::CommandGenerator.record_location_command }
11
+
12
+ subject { RobotVim::CommandGenerator.generate(user_commands, output_file) }
13
+
14
+ it { should include(user_commands) }
15
+ it { should include(write_to_output_file_command) }
16
+ it { should include(record_location_command) }
17
+ it { should include(close_vim_commands) }
18
+ end
19
+ end
20
+
@@ -37,7 +37,7 @@ describe RobotVim::Runner do
37
37
 
38
38
  before do
39
39
  Kernel.stub(:`)
40
- runner.stub(:read_output_file_contents)
40
+ runner.stub(:read_output_file_contents).and_return("some file contents")
41
41
  RobotVim::InputFile.stub(:path_for).and_yield(input_file)
42
42
  end
43
43
 
@@ -84,8 +84,10 @@ describe RobotVim::Runner do
84
84
  run_robot
85
85
  end
86
86
 
87
- it "adds a write command to the user supplied commands" do
88
- RobotVim::ScriptFile.should_receive(:open).with(/\n\:w/)
87
+ it "generates commands for the script file based on user input" do
88
+ generated_commands = stub('generated commands')
89
+ RobotVim::CommandGenerator.stub!(:generate).with(commands, anything()).and_return(generated_commands)
90
+ RobotVim::ScriptFile.should_receive(:open).with(generated_commands)
89
91
  run_robot
90
92
  end
91
93
 
@@ -99,11 +101,6 @@ describe RobotVim::Runner do
99
101
  files[0].should_not == files[1]
100
102
  end
101
103
 
102
- it "adds vim closing commands to the user supplied commands" do
103
- RobotVim::ScriptFile.should_receive(:open).with(/:%bd!\n:q!/)
104
- run_robot
105
- end
106
-
107
104
  describe "output file management" do
108
105
  let(:output_file_name){"output_file_name"}
109
106
 
@@ -111,18 +108,18 @@ describe RobotVim::Runner do
111
108
  RobotVim::FileNameGenerator.stub(:generate).and_return(output_file_name)
112
109
  end
113
110
 
114
- it "returns the contents of the output file" do
115
- expected_result = "awesome buffer"
116
- runner.stub(:read_output_file_contents).with(output_file_name).and_return(expected_result)
117
- result = run_robot
118
- result.should == expected_result
119
- end
120
-
121
111
  it "deletes the output file" do
122
112
  run_robot
123
113
  File.exists?(output_file_name).should be_false
124
114
  end
125
115
  end
116
+
117
+ describe "return value" do
118
+ it "returns a VimResponse that is initialized with the output file contents" do
119
+ response = run_robot
120
+ response.should be_kind_of(RobotVim::VimResponse)
121
+ end
122
+ end
126
123
  end
127
124
 
128
125
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe RobotVim::VimResponse do
4
+ let(:expected_body) { "hi there. This is some stuff.\n That is in vim\n and might be awesome" }
5
+ let(:expected_line) { 2 }
6
+ let(:expected_column) { 4 }
7
+ let(:file_contents) { expected_body + "\n" + expected_line.to_s + "\n" + expected_column.to_s }
8
+
9
+ subject { RobotVim::VimResponse.new(file_contents) }
10
+
11
+ its(:body) { should == expected_body }
12
+ its(:line_number) { should == expected_line }
13
+ its(:column_number) { should == expected_column }
14
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: robot-vim
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 2.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Margolis
@@ -10,12 +10,11 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-20 00:00:00 -05:00
13
+ date: 2011-09-11 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
18
- prerelease: false
19
18
  requirement: &id001 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
@@ -23,40 +22,52 @@ dependencies:
23
22
  - !ruby/object:Gem::Version
24
23
  version: 1.0.0
25
24
  type: :development
25
+ prerelease: false
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
29
- prerelease: false
28
+ name: rake
30
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &id003 !ruby/object:Gem::Requirement
31
41
  none: false
32
42
  requirements:
33
43
  - - ~>
34
44
  - !ruby/object:Gem::Version
35
45
  version: 2.5.0
36
46
  type: :development
37
- version_requirements: *id002
47
+ prerelease: false
48
+ version_requirements: *id003
38
49
  - !ruby/object:Gem::Dependency
39
50
  name: autotest
40
- prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
42
52
  none: false
43
53
  requirements:
44
54
  - - ">="
45
55
  - !ruby/object:Gem::Version
46
56
  version: "0"
47
57
  type: :development
48
- version_requirements: *id003
58
+ prerelease: false
59
+ version_requirements: *id004
49
60
  - !ruby/object:Gem::Dependency
50
61
  name: uuid
51
- prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
53
63
  none: false
54
64
  requirements:
55
65
  - - ~>
56
66
  - !ruby/object:Gem::Version
57
67
  version: 2.3.1
58
68
  type: :runtime
59
- version_requirements: *id004
69
+ prerelease: false
70
+ version_requirements: *id005
60
71
  description: Automate Vim with Ruby to allow for TDD/BDD of Vim plugins and scripts
61
72
  email:
62
73
  - matt@mattmargolis.net
@@ -75,20 +86,24 @@ files:
75
86
  - README.md
76
87
  - Rakefile
77
88
  - lib/robot-vim.rb
89
+ - lib/robot-vim/command_generator.rb
78
90
  - lib/robot-vim/file_name_generator.rb
79
91
  - lib/robot-vim/input_file.rb
80
92
  - lib/robot-vim/runner.rb
81
93
  - lib/robot-vim/script_file.rb
82
94
  - lib/robot-vim/version.rb
95
+ - lib/robot-vim/vim_response.rb
83
96
  - robot-vim.gemspec
84
97
  - spec/fixtures/unsorted_file.txt
85
98
  - spec/fixtures/vimrc_with_not_to_gross
86
99
  - spec/fixtures/vimrc_with_user_input
87
100
  - spec/integration_spec.rb
101
+ - spec/robot-vim/command_generator_spec.rb
88
102
  - spec/robot-vim/file_name_generator_spec.rb
89
103
  - spec/robot-vim/input_file_spec.rb
90
104
  - spec/robot-vim/runner_spec.rb
91
105
  - spec/robot-vim/script_file_spec.rb
106
+ - spec/robot-vim/vim_response_spec.rb
92
107
  - spec/spec_helper.rb
93
108
  has_rdoc: true
94
109
  homepage: https://github.com/mrmargolis/robot-vim
@@ -104,6 +119,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
119
  requirements:
105
120
  - - ">="
106
121
  - !ruby/object:Gem::Version
122
+ hash: 388667503405751599
123
+ segments:
124
+ - 0
107
125
  version: "0"
108
126
  required_rubygems_version: !ruby/object:Gem::Requirement
109
127
  none: false