-
Notifications
You must be signed in to change notification settings - Fork 630
/
Copy pathhelper.rb
49 lines (35 loc) · 970 Bytes
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
require "minitest/autorun"
require "fileutils"
require "pathname"
TEST_DIR = File.expand_path(__dir__)
TEMP_DIR = File.join(TEST_DIR, "tmp")
def setup_tempdir
FileUtils.mkdir_p(TEMP_DIR)
File.exist?(TEMP_DIR) ? TEMP_DIR : nil
end
def chdir_tempdir
setup_tempdir unless File.exist?(TEMP_DIR)
Dir.chdir(TEMP_DIR)
end
def teardown_tempdir
FileUtils.rm_rf(TEMP_DIR) if File.exist?(TEMP_DIR)
end
def create_file(path, content)
raise "path must be relative" unless Pathname.new(path).relative?
dir = File.dirname(path)
FileUtils.mkdir_p(dir)
File.write(path, content)
end
def linter_output
stdout, _stderr = capture_io { Linter.new(exit_on_errors: false).run }
stdout
end
def file_must_exist(filename)
assert File.exist?(filename),
"Expected file `#{filename}' to exist."
end
def file_wont_exist(filename)
assert !File.exist?(filename),
"Expected file `#{filename}' to not exist."
end