-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvalidate_configs_spec.rb
More file actions
56 lines (49 loc) · 1.37 KB
/
validate_configs_spec.rb
File metadata and controls
56 lines (49 loc) · 1.37 KB
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
50
51
52
53
54
55
56
# frozen_string_literal: true
require 'fileutils'
require 'tmpdir'
RSpec.describe 'bin/validate_configs' do # rubocop:disable RSpec/DescribeClass
let(:script_path) { File.expand_path('../../bin/validate_configs', __dir__) }
let(:config_path) { File.join('lib', 'html2rss', 'configs', 'example.com', 'search.yml') }
let(:success_output) do
a_string_including(
"ok #{config_path}",
'1 configs validated successfully.'
)
end
it 'passes validation for parameterized configs when defaults are present' do
with_temp_config do |dir|
expect { run_script(dir) }.to output(success_output).to_stdout
.and output('').to_stderr
end
end
def with_temp_config
Dir.mktmpdir do |dir|
write_config(dir)
yield dir
end
end
def write_config(dir)
FileUtils.mkdir_p(File.join(dir, File.dirname(config_path)))
File.write(File.join(dir, config_path), valid_config)
end
def run_script(dir)
Dir.chdir(dir) { load script_path }
end
def valid_config
<<~YAML
parameters:
query:
type: string
default: ruby
headers:
X-Query: "%<query>s"
channel:
url: "https://example.com/search?q=%<query>s"
selectors:
items:
selector: ".item"
title:
selector: "h2"
YAML
end
end