robot-vim 0.1.1 → 0.9.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
@@ -31,14 +31,17 @@ Commands are passed in as a string with one command per line.
31
31
  SomeOtherCoolCommand
32
32
  COMMANDS
33
33
 
34
- robot.run(:input_file => "some/file.txt", :commands => commands)
34
+ buffer_text = robot.run(:input_file => "some/file.txt", :commands => commands)
35
35
 
36
- See spec/integration\_spec.rb for an example of sorting a file and saving the output.
37
36
 
37
+ ### Making Assertions
38
+ Use your preferred Ruby testing library to make assertions about the buffer text string returned by RobotVim::Runner#run
39
+
40
+ See spec/integration\_spec.rb for an example of sorting a file and making an assertion.
38
41
 
39
42
  ## TODO
40
- - automatically save buffer to an output file after running the last command
41
- - automatically close Vim after running the last command
43
+ - automatically save buffer to an output file after running the last command(done)
44
+ - automatically close Vim after running the last command(done)
42
45
  - take a string for input and write out a temporary file that Vim will run against
43
46
  - figure out if there is a way to specify a .vimrc file without disabling the normal Vim initialization process
44
47
 
data/lib/robot-vim.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'tempfile'
1
+ require 'uuid'
2
2
  require "robot-vim/runner"
3
3
  require "robot-vim/script_file"
@@ -11,8 +11,20 @@ module RobotVim
11
11
  end
12
12
 
13
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]}")
14
+ output_file_name = UUID.new.generate(:compact)
15
+ commands = args[:commands] + ":w #{output_file_name}"
16
+ commands = commands + "\n:%bd!\n:q!\n"
17
+ invoke_vim(commands, args[:input_file])
18
+ return File.read(output_file_name)
19
+ ensure
20
+ File.delete(output_file_name) if File.exists?(output_file_name)
21
+ end
22
+
23
+ private
24
+
25
+ def invoke_vim(commands, input_file)
26
+ ScriptFile.open(commands) do |script_file_path|
27
+ Kernel.send(:`, "#{self.vim_binary} -n -s #{script_file_path} #{input_file}")
16
28
  end
17
29
  end
18
30
  end
@@ -2,11 +2,14 @@ module RobotVim
2
2
  class ScriptFile
3
3
 
4
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
5
+ file_name = UUID.new.generate(:compact)
6
+ script_file = File.new(file_name, "w")
7
+ script_file << commands
8
+ script_file.flush
9
+ script_file.close
10
+ yield file_name
11
+ ensure
12
+ File.delete(file_name) if File.exists?(file_name)
10
13
  end
11
14
 
12
15
  end
@@ -1,5 +1,5 @@
1
1
  module Robot
2
2
  module Vim
3
- VERSION = "0.1.1"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
data/robot-vim.gemspec CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |s|
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Matt Margolis"]
9
9
  s.email = ["matt@mattmargolis.net"]
10
- s.homepage = "http://rubygems.org/gems/robot-vim"
10
+ s.homepage = "https://github.com/mrmargolis/robot-vim"
11
11
  s.summary = "Vim automation with Ruby"
12
- s.description = "Invoke Vim from inside of Ruby to allow for TDD/BDD of Vim plugins and scripts"
12
+ s.description = "Automate Vim with Ruby to allow for TDD/BDD of Vim plugins and scripts"
13
13
 
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "robot-vim"
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency "rspec", "~> 2.5.0"
19
19
  s.add_development_dependency "autotest"
20
20
 
21
+ s.add_dependency "uuid", "~> 2.3.1"
22
+
21
23
  s.files = `git ls-files`.split("\n")
22
24
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
23
25
  s.require_path = 'lib'
@@ -5,19 +5,12 @@ describe "Automating Vim with RobotVim" do
5
5
  input_path = File.join(File.dirname(__FILE__), "fixtures", "unsorted_file.txt")
6
6
  unsorted_text = File.read(input_path)
7
7
 
8
- output_file = "output.txt"
9
-
10
8
  commands = <<-COMMANDS
11
9
  :%!sort
12
- :w #{output_file}
13
- :%bd!
14
- :q!
15
10
  COMMANDS
16
11
 
17
12
  runner = RobotVim::Runner.new
18
- runner.run(:commands => commands, :input_file => input_path)
19
- result = File.read(output_file)
13
+ result = runner.run(:commands => commands, :input_file => input_path)
20
14
  result.should eql(unsorted_text.split("\n").sort.join("\n") + "\n")
21
- File.delete(output_file)
22
15
  end
23
16
  end
@@ -19,8 +19,14 @@ describe RobotVim::Runner do
19
19
  describe "running commands in vim" do
20
20
  let(:vim_path){"/usr/local/bin/vim"}
21
21
  let(:runner){RobotVim::Runner.new(:vim => vim_path)}
22
- let(:commands){"some vim commands"}
22
+ let(:commands){"some vim commands\n"}
23
23
  let(:input_file){"some/path/to/a/file"}
24
+ let(:output_file_name){"output_file_name"}
25
+
26
+ before do
27
+ Kernel.stub(:`)
28
+ File.stub(:read)
29
+ end
24
30
 
25
31
  def run_robot
26
32
  runner.run(:commands => commands, :input_file => input_file)
@@ -47,6 +53,41 @@ describe RobotVim::Runner do
47
53
  Kernel.should_receive(:`).with(/-s #{script_file_path}/)
48
54
  run_robot
49
55
  end
56
+
57
+ it "adds a write command to the user supplied commands" do
58
+ RobotVim::ScriptFile.should_receive(:open).with(/\n\:w/)
59
+ run_robot
60
+ end
61
+
62
+ it "generates a unique filename for the output file on each run" do
63
+ files = []
64
+ RobotVim::ScriptFile.should_receive(:open) do |msg|
65
+ files << msg.match(/:w (.*)/)[1]
66
+ end.twice
67
+ run_robot
68
+ run_robot
69
+ files[0].should_not == files[1]
70
+ end
71
+
72
+ it "adds vim closing commands to the user supplied commands" do
73
+ RobotVim::ScriptFile.should_receive(:open).with(/:%bd!\n:q!/)
74
+ run_robot
75
+ end
76
+
77
+ it "returns the contents of the output file" do
78
+ UUID.stub_chain(:new, :generate => output_file_name)
79
+ expected_result = "awesome buffer"
80
+ File.stub(:read).with(output_file_name).and_return(expected_result)
81
+ result = run_robot
82
+ result.should == expected_result
83
+ end
84
+
85
+ it "deletes the output file" do
86
+ output_file_name = "somefile"
87
+ UUID.stub_chain(:new, :generate => output_file_name)
88
+ run_robot
89
+ File.exists?(output_file_name).should be_false
90
+ end
50
91
  end
51
92
 
52
93
  end
@@ -6,8 +6,9 @@ describe RobotVim::ScriptFile do
6
6
 
7
7
  it "yields the path of the script file" do
8
8
  expected_path = "/some/path/somewhere"
9
- tempfile = stub("tempfile", :path => expected_path).as_null_object
10
- Tempfile.stub(:open).and_yield(tempfile)
9
+ UUID.stub_chain(:new, :generate => expected_path)
10
+ file = stub("file").as_null_object
11
+ File.stub(:new).and_return(file)
11
12
 
12
13
  RobotVim::ScriptFile.open(commands_string) do |file_path|
13
14
  file_path.should == expected_path
@@ -20,5 +21,13 @@ describe RobotVim::ScriptFile do
20
21
  end
21
22
  end
22
23
 
24
+ it "deletes the file after we are done using it" do
25
+ file_name = "somefile"
26
+ UUID.stub_chain(:new, :generate => file_name)
27
+ RobotVim::ScriptFile.open(commands_string) do |file_path|
28
+ end
29
+ File.exists?(file_name).should be_false
30
+ end
31
+
23
32
  end
24
33
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: robot-vim
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.9.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Margolis
@@ -46,7 +46,18 @@ dependencies:
46
46
  version: "0"
47
47
  type: :development
48
48
  version_requirements: *id003
49
- description: Invoke Vim from inside of Ruby to allow for TDD/BDD of Vim plugins and scripts
49
+ - !ruby/object:Gem::Dependency
50
+ name: uuid
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 2.3.1
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ description: Automate Vim with Ruby to allow for TDD/BDD of Vim plugins and scripts
50
61
  email:
51
62
  - matt@mattmargolis.net
52
63
  executables: []
@@ -74,7 +85,7 @@ files:
74
85
  - spec/robot-vim/script_file_spec.rb
75
86
  - spec/spec_helper.rb
76
87
  has_rdoc: true
77
- homepage: http://rubygems.org/gems/robot-vim
88
+ homepage: https://github.com/mrmargolis/robot-vim
78
89
  licenses: []
79
90
 
80
91
  post_install_message: