Skip to content

Commit c93a846

Browse files
committed
support folding on lower lines, give failure message
1 parent 27fcbaa commit c93a846

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

spec/spec_helper.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ def syntax(content, pattern)
6161
syngroups.gsub!(/["'\[\]]/, '').split(', ')
6262
end
6363

64-
def fold_and_delete(content)
64+
def fold_and_delete(content, opts)
65+
start_line = opts[:on_line]
6566
with_file content do
6667
@vim.command("set foldmethod=syntax")
6768

6869
@vim.normal("zO")
69-
@vim.normal("zM")
70+
@vim.normal("#{start_line}G")
71+
@vim.normal("zc")
7072
@vim.normal("dd")
7173
end
7274
end
@@ -203,14 +205,29 @@ def self.new
203205
end
204206
end
205207

206-
RSpec::Matchers.define :fold_lines do |lines|
208+
RSpec::Matchers.define :fold_lines do |lines, opts|
207209
buffer = Buffer.new(VIM, :ex)
210+
opts ||= {}
211+
start_line = opts[:on_line] ||= 1
212+
213+
after = nil
208214

209215
match do |code|
210-
after = buffer.fold_and_delete(code)
216+
after = buffer.fold_and_delete(code, opts)
211217

212218
code.lines.count - after.lines.count == lines
213219
end
220+
221+
failure_message do |code|
222+
<<~EOF
223+
expected
224+
#{code}
225+
to fold #{lines} lines at line #{start_line},
226+
but after folding at line #{start_line} and deleting a line I got
227+
#{after}
228+
back
229+
EOF
230+
end
214231
end
215232

216233
Vimrunner::RSpec.configure do |config|

0 commit comments

Comments
 (0)