robot-vim 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1 @@
1
+ require "autotest/bundler"
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ .rvmrc
5
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -3,58 +3,44 @@ RobotVim is a Ruby gem that allows you to invoke Vim from inside of Ruby
3
3
  programs. It was designed to allow Vim developers to TDD/BDD their Vim plugins
4
4
  and scripts.
5
5
 
6
- ## Important
7
- Right now there is no real code to this project. It's just this README. Code is coming soon.
8
-
9
6
  ## Installation
10
7
  To install RobotVim run
11
8
  gem install robot-vim
12
9
  or clone this reposity and run
13
10
  rake install
14
11
 
12
+
15
13
  ## Dependencies
16
- RobotVim is developed with Ruby 1.9.2 and bundler. It has not been tested with older versions of Ruby.
14
+ RobotVim is developed with Vim 7.3, Ruby 1.9.2, and bundler.
15
+
17
16
 
18
17
  ## Example Usage
19
18
 
20
19
  ### Initialization
21
- Create an instance that will use your user's default Vim and vimrc file
22
- robot = RobotVim.new()
20
+ Create an instance that will use your user's default Vim
21
+ robot = RobotVim::Runner.new()
23
22
 
24
- Or create an instance with a specific Vim and/or vimrc file
25
- robot = RobotVim.new(:vim_path => "~/bin/vim",
26
- :vimrc_path => "examples/vimrc_with_weird_bindings")
23
+ Or create an instance with a specific Vim
24
+ robot = RobotVim::Runner.new(:vim => "/bin/vim")
27
25
 
28
26
  ### Running commands
29
27
  Commands are passed in as a string with one command per line.
30
28
 
31
- Run commands against inline input
32
29
  commands = <<-COMMANDS
33
30
  RunSomeCoolCommand
34
31
  SomeOtherCoolCommand
35
32
  COMMANDS
36
33
 
37
- input = <<-INPUT
38
- This is a some sample
39
- text that I can pass in as input.
40
- I could also use a file fixture as my input.
41
- See the examples folder for more examples.
42
- INPUT
43
-
44
- result = robot.run(:input_text => input, :commands => commands)
45
- puts result.buffer_text
34
+ robot.run(:input_file => "some/file.txt", :commands => commands)
46
35
 
47
- Run a command against a test input file
48
- command = "normal G|iTyping some text at the bottom of the buffer"
49
- result = robot.run(:input_file => "examples/input1.txt", :commands => commands)
50
- puts result.buffer_text
36
+ See spec/integration\_spec.rb for an example of sorting a file and saving the output.
51
37
 
52
- ## The result object
53
- The result of the RobotVim#run method has the following attributes
54
38
 
55
- - buffer\_text: the text of the buffer after the last command (not yet implemented)
56
- - buffer\_name: the name of the buffer after the last command (not yet implemented)
57
- - cursor\_location: the curson location after the last command(not yet implemented)
39
+ ## TODO
40
+ - automatically save buffer to an output file after running the last command
41
+ - automatically close Vim after running the last command
42
+ - take a string for input and write out a temporary file that Vim will run against
43
+ - figure out if there is a way to specify a .vimrc file without disabling the normal Vim initialization process
58
44
 
59
45
  ## Author
60
46
  RobotVim is developed by Matt Margolis | mrmargolis | matt@mattmargolis.net
@@ -0,0 +1,19 @@
1
+ module RobotVim
2
+ class Runner
3
+ DEFAULT_VIM_BINARY = "vim"
4
+
5
+ def initialize(args={})
6
+ @vim_binary = args[:vim]
7
+ end
8
+
9
+ def vim_binary
10
+ @vim_binary || DEFAULT_VIM_BINARY
11
+ end
12
+
13
+ def run(args={})
14
+ ScriptFile.open(args[:commands]) do |script_file_path|
15
+ Kernel.send(:`, "#{self.vim_binary} -n -s #{script_file_path} #{args[:input_file]}")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module RobotVim
2
+ class ScriptFile
3
+
4
+ def self.open(commands)
5
+ Tempfile.open('script_file') do |temp_file|
6
+ temp_file << commands
7
+ temp_file.flush
8
+ yield temp_file.path
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Robot
2
2
  module Vim
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/lib/robot-vim.rb CHANGED
@@ -1,5 +1,3 @@
1
- module Robot
2
- module Vim
3
- # Your code goes here...
4
- end
5
- end
1
+ require 'tempfile'
2
+ require "robot-vim/runner"
3
+ require "robot-vim/script_file"
data/output.txt ADDED
@@ -0,0 +1,3 @@
1
+ A first line
2
+ Middle line
3
+ This line should be last
data/robot-vim.gemspec CHANGED
@@ -15,6 +15,8 @@ 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 "rspec", "~> 2.5.0"
19
+ s.add_development_dependency "autotest"
18
20
 
19
21
  s.files = `git ls-files`.split("\n")
20
22
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
@@ -0,0 +1,3 @@
1
+ This line should be last
2
+ A first line
3
+ Middle line
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Automating Vim with RobotVim" do
4
+ it "can sort a file using vim" do
5
+ input_path = File.join(File.dirname(__FILE__), "fixtures", "unsorted_file.txt")
6
+ unsorted_text = File.read(input_path)
7
+
8
+ output_file = "output.txt"
9
+
10
+ commands = <<-COMMANDS
11
+ :%!sort
12
+ :w #{output_file}
13
+ :%bd!
14
+ :q!
15
+ COMMANDS
16
+
17
+ runner = RobotVim::Runner.new
18
+ runner.run(:commands => commands, :input_file => input_path)
19
+ result = File.read(output_file)
20
+ result.should eql(unsorted_text.split("\n").sort.join("\n") + "\n")
21
+ end
22
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe RobotVim::Runner do
4
+
5
+ describe "specifying which vim to use" do
6
+ it "uses the vim passed in during initialization if provided" do
7
+ vim = "/usr/local/bin/vim"
8
+ runner = RobotVim::Runner.new(:vim => vim)
9
+ runner.vim_binary.should == vim
10
+ end
11
+
12
+ it "defaults to vim in user's path" do
13
+ vim = "vim"
14
+ runner = RobotVim::Runner.new()
15
+ runner.vim_binary.should == vim
16
+ end
17
+ end
18
+
19
+ describe "running commands in vim" do
20
+ let(:vim_path){"/usr/local/bin/vim"}
21
+ let(:runner){RobotVim::Runner.new(:vim => vim_path)}
22
+ let(:commands){"some vim commands"}
23
+ let(:input_file){"some/path/to/a/file"}
24
+
25
+ def run_robot
26
+ runner.run(:commands => commands, :input_file => input_file)
27
+ end
28
+
29
+ it "invokes the correct vim" do
30
+ Kernel.should_receive(:`).with(/#{vim_path}/)
31
+ run_robot
32
+ end
33
+
34
+ it "runs against the requested input file" do
35
+ Kernel.should_receive(:`).with(/#{input_file}$/)
36
+ run_robot
37
+ end
38
+
39
+ it "runs vim without swap files so vim doesn't show swap warnings" do
40
+ Kernel.should_receive(:`).with(/-n/)
41
+ run_robot
42
+ end
43
+
44
+ it "invokes vim with a script file" do
45
+ script_file_path = "path/to/script/file"
46
+ RobotVim::ScriptFile.stub(:open).and_yield(script_file_path)
47
+ Kernel.should_receive(:`).with(/-s #{script_file_path}/)
48
+ run_robot
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe RobotVim::ScriptFile do
4
+ describe "when creating a script file from a string" do
5
+ let(:commands_string){"some string of vim commands"}
6
+
7
+ it "yields the path of the script file" do
8
+ expected_path = "/some/path/somewhere"
9
+ tempfile = stub("tempfile", :path => expected_path).as_null_object
10
+ Tempfile.stub(:open).and_yield(tempfile)
11
+
12
+ RobotVim::ScriptFile.open(commands_string) do |file_path|
13
+ file_path.should == expected_path
14
+ end
15
+ end
16
+
17
+ it "writes the commands out to the script file" do
18
+ RobotVim::ScriptFile.open(commands_string) do |file_path|
19
+ File.read(file_path).should == commands_string
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require File.join(File.dirname(__FILE__), '/../lib/robot-vim.rb')
3
+
4
+ Rspec.configure do |c|
5
+ c.mock_with :rspec
6
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robot-vim
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
4
+ prerelease:
5
+ version: 0.1.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Matt Margolis
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-03-20 00:00:00 -05:00
13
+ date: 2011-03-26 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,13 +21,31 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 0
31
- - 0
32
24
  version: 1.0.0
33
25
  type: :development
34
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 2.5.0
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: autotest
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
35
49
  description: Invoke Vim from inside of Ruby to allow for TDD/BDD of Vim plugins and scripts
36
50
  email:
37
51
  - matt@mattmargolis.net
@@ -42,14 +56,24 @@ extensions: []
42
56
  extra_rdoc_files: []
43
57
 
44
58
  files:
59
+ - .autotest
45
60
  - .gitignore
61
+ - .rspec
46
62
  - Gemfile
47
63
  - License.txt
48
64
  - README.md
49
65
  - Rakefile
50
66
  - lib/robot-vim.rb
67
+ - lib/robot-vim/runner.rb
68
+ - lib/robot-vim/script_file.rb
51
69
  - lib/robot-vim/version.rb
70
+ - output.txt
52
71
  - robot-vim.gemspec
72
+ - spec/fixtures/unsorted_file.txt
73
+ - spec/integration_spec.rb
74
+ - spec/robot-vim/runner_spec.rb
75
+ - spec/robot-vim/script_file_spec.rb
76
+ - spec/spec_helper.rb
53
77
  has_rdoc: true
54
78
  homepage: http://rubygems.org/gems/robot-vim
55
79
  licenses: []
@@ -64,23 +88,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
88
  requirements:
65
89
  - - ">="
66
90
  - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
91
  version: "0"
70
92
  required_rubygems_version: !ruby/object:Gem::Requirement
71
93
  none: false
72
94
  requirements:
73
95
  - - ">="
74
96
  - !ruby/object:Gem::Version
75
- segments:
76
- - 1
77
- - 3
78
- - 6
79
97
  version: 1.3.6
80
98
  requirements: []
81
99
 
82
100
  rubyforge_project: robot-vim
83
- rubygems_version: 1.3.7
101
+ rubygems_version: 1.6.2
84
102
  signing_key:
85
103
  specification_version: 3
86
104
  summary: Vim automation with Ruby