Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit d5833c30bb4f36f0af1d2ba5c0aafbfc659f01a5 0 parents
@jferris authored
3  .gitignore
@@ -0,0 +1,3 @@
+*.swp
+.swo
+*~
22 features/movement.feature
@@ -0,0 +1,22 @@
+Feature: move around the buffer
+
+ Background:
+ Given the following buffer:
+ """
+ First line
+ Second line
+ Third line
+ Fourth line
+ """
+ Scenario: Use j and k
+ When I press "jjjk"
+ And I press "i"
+ And I press "x<Esc>"
+ Then line 3 should read "xThird line"
+
+ Scenario: Use h and l
+ When I press "lllh"
+ And I press "i"
+ And I press "x<Esc>"
+ Then line 1 should read "Fixrst line"
+
12 features/step_definitions/vi_steps.rb
@@ -0,0 +1,12 @@
+Given /^the following buffer:$/ do |contents|
+ @vim.create_buffer(contents)
+end
+
+When /^I press "([^\"]*)"$/ do |key_sequence|
+ @vim.press(key_sequence)
+end
+
+Then /^line (\d+) should read "([^\"]*)"$/ do |number, contents|
+ @vim.line(number).should == contents
+end
+
56 features/support/vi.rb
@@ -0,0 +1,56 @@
+class Vi
+ class << self
+ attr_accessor :instance
+ end
+
+ def self.use(*args, &block)
+ Vi.instance = new(*args, &block)
+ end
+
+ def self.reset
+ instance.reset
+ end
+
+ def self.teardown
+ instance.teardown
+ end
+
+ # Called after each example to clean up created buffers.
+ def reset
+ end
+
+ # Called after all examples are complete to clean up created servers, etc.
+ def teardown
+ end
+
+ # Create and enter a buffer with the given contents
+ # @param contents [String] the contents for the buffer
+ def create_buffer(contents)
+ end
+ undef_method :create_buffer
+
+ # Enter the given key sequence in the active buffer
+ # @param key_sequence [String] a vi-like string of keys, such as "iTest<Esc>"
+ def press(key_sequence)
+ end
+ undef_method :press
+
+ # Return the contents of the line with the given number in the active buffer
+ # @param number [Fixnum] the line number to return
+ # @return [String] the contents of the line
+ def line(number)
+ end
+ undef_method :line
+end
+
+Before do
+ @vim = Vi.instance
+end
+
+After do
+ Vi.reset
+end
+
+at_exit do
+ Vi.teardown
+end
45 features/support/vim.rb
@@ -0,0 +1,45 @@
+class Vim < Vi
+ def initialize
+ start_vim_server
+ end
+
+ def teardown
+ kill_vim_server
+ end
+
+ def create_buffer(contents)
+ content_keys = contents.gsub("\n", "<Enter>")
+ press "i#{content_keys}<Esc>gg"
+ end
+
+ def press(key_sequence)
+ remote_command("--remote-send #{key_sequence.inspect}")
+ end
+
+ def line(number)
+ remote_command(%{--remote-expr "getline('#{number}')"}).chop
+ end
+
+ def reset
+ press "enew!"
+ end
+
+ private
+
+ def start_vim_server
+ pid = Process.fork do
+ exec("mvim --servername vispec-server")
+ end
+ Process.wait(pid)
+ end
+
+ def kill_vim_server
+ remote_command("--remote-send '<C-C>:qa!<Enter>'")
+ end
+
+ def remote_command(command)
+ `mvim --servername vispec-server #{command}`
+ end
+end
+
+Vim.use
Please sign in to comment.
Something went wrong with that request. Please try again.