Permalink
Browse files

Update vimrunner

  • Loading branch information...
1 parent 7800730 commit 1c39218242d60b935823dbff0248f1b925833a99 @AndrewRadev committed Dec 25, 2012
Showing with 8 additions and 29 deletions.
  1. +1 −1 Gemfile.lock
  2. +4 −6 spec/spec_helper.rb
  3. +3 −22 spec/support/files.rb
View
@@ -17,7 +17,7 @@ GEM
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3)
slop (3.3.2)
- vimrunner (0.1.1)
+ vimrunner (0.2.0)
PLATFORMS
ruby
View
@@ -1,9 +1,10 @@
-require 'tmpdir'
require 'vimrunner'
+require 'vimrunner/testing'
require_relative './support/vim'
require_relative './support/files'
RSpec.configure do |config|
+ config.include Vimrunner::Testing
config.include Support::Files
config.before(:suite) do
@@ -20,11 +21,8 @@
config.around do |example|
@vim = VIM
- Dir.mktmpdir do |dir|
- Dir.chdir(dir) do
- @vim.command("cd #{dir}")
- example.call
- end
+ tmpdir(@vim) do
+ example.call
end
end
end
View
@@ -4,35 +4,16 @@ module Support
#
module Files
def set_file_contents(string)
- string = normalize_string(string)
- File.open(filename, 'w') { |f| f.write(string + "\n") }
- @vim.edit! filename
+ write_file(filename, string)
+ @vim.edit!(filename)
end
def file_contents
IO.read(filename).chop # remove trailing newline
end
def assert_file_contents(string)
- file_contents.should eq normalize_string(string)
- end
-
- private
-
- # Note: #scan and #chop is being used instead of #split to avoid discarding
- # empty lines.
- def normalize_string(string)
- if string.end_with?("\n")
- lines = string.scan(/.*\n/).map(&:chop)
- whitespace = lines.grep(/\S/).first.scan(/^\s*/).first
- else
- lines = [string]
- whitespace = string.scan(/^\s*/).first
- end
-
- lines.map do |line|
- line.gsub(/^#{whitespace}/, '') if line =~ /\S/
- end.join("\n")
+ file_contents.should eq normalize_string_indent(string)
end
end
end

0 comments on commit 1c39218

Please sign in to comment.