Skip to content

Commit 27fcbaa

Browse files
committed
move matcher over, extract buffer method, example dsl
1 parent 2f38b3a commit 27fcbaa

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

spec/folding/basic_spec.rb

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,16 @@
22

33
require 'spec_helper'
44

5-
RSpec::Matchers.define :fold_lines do |lines|
6-
file = ".fixture.ex"
7-
8-
9-
match do |code|
10-
File.write(file, code)
11-
VIM.edit file
12-
VIM.command("set foldmethod=syntax")
13-
14-
VIM.normal("zO")
15-
VIM.normal("zM")
16-
VIM.normal("dd")
17-
VIM.write
18-
19-
written = IO.read(file)
20-
code.lines.count - written.lines.count == lines
21-
end
22-
end
23-
245
describe 'Basic folding' do
25-
it 'blah' do
26-
content = <<~EOF
27-
defmodule M do
6+
def self.it_folds_lines(content, lines, tags = nil)
7+
it("folds #{lines} lines on \n#{content}", tags) do
8+
expect(content).to fold_lines(lines, tags)
289
end
29-
EOF
10+
end
3011

31-
expect(content).to fold_lines(2)
12+
it_folds_lines(<<~EOF, 2)
13+
defmodule M do
3214
end
15+
EOF
3316
end
3417

spec/spec_helper.rb

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

64+
def fold_and_delete(content)
65+
with_file content do
66+
@vim.command("set foldmethod=syntax")
67+
68+
@vim.normal("zO")
69+
@vim.normal("zM")
70+
@vim.normal("dd")
71+
end
72+
end
73+
6474
private
6575

6676
def with_file(content = nil)
@@ -193,6 +203,16 @@ def self.new
193203
end
194204
end
195205

206+
RSpec::Matchers.define :fold_lines do |lines|
207+
buffer = Buffer.new(VIM, :ex)
208+
209+
match do |code|
210+
after = buffer.fold_and_delete(code)
211+
212+
code.lines.count - after.lines.count == lines
213+
end
214+
end
215+
196216
Vimrunner::RSpec.configure do |config|
197217
config.reuse_server = true
198218

0 commit comments

Comments
 (0)