Skip to content

Commit 03699b6

Browse files
committed
fix(validation): use runtime config validation entrypoint
1 parent ce705bc commit 03699b6

3 files changed

Lines changed: 53 additions & 3 deletions

File tree

bin/validate_configs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
require 'bundler/setup'
55
require 'html2rss'
6-
require 'yaml'
76

87
files = Dir['lib/html2rss/configs/**/*.yml']
98
failed = []
109

1110
files.each do |file|
12-
config = YAML.safe_load_file(file, symbolize_names: true)
13-
result = Html2rss::Config.validate(config)
11+
result = Html2rss::Config.validate_yaml(file)
1412

1513
if result.success?
1614
puts "ok #{file}"

spec/bin/validate_configs_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require 'fileutils'
4+
require 'stringio'
5+
require 'tmpdir'
6+
7+
RSpec.describe 'bin/validate_configs' do
8+
let(:script_path) { File.expand_path('../../bin/validate_configs', __dir__) }
9+
10+
it 'passes validation for parameterized configs when defaults are present' do
11+
config = <<~YAML
12+
parameters:
13+
query:
14+
type: string
15+
default: ruby
16+
headers:
17+
X-Query: "%<query>s"
18+
channel:
19+
url: "https://example.com/search?q=%<query>s"
20+
selectors:
21+
items:
22+
selector: ".item"
23+
title:
24+
selector: "h2"
25+
YAML
26+
27+
Dir.mktmpdir do |dir|
28+
FileUtils.mkdir_p(File.join(dir, 'lib', 'html2rss', 'configs', 'example.com'))
29+
File.write(File.join(dir, 'lib', 'html2rss', 'configs', 'example.com', 'search.yml'), config)
30+
31+
stdout = StringIO.new
32+
stderr = StringIO.new
33+
original_stdout = $stdout
34+
original_stderr = $stderr
35+
$stdout = stdout
36+
$stderr = stderr
37+
38+
Dir.chdir(dir) { load script_path }
39+
40+
expect(stdout.string).to include('ok lib/html2rss/configs/example.com/search.yml')
41+
expect(stdout.string).to include('1 configs validated successfully.')
42+
expect(stderr.string).to be_empty
43+
ensure
44+
$stdout = original_stdout
45+
$stderr = original_stderr
46+
end
47+
end
48+
end

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
require 'bundler/setup'
44
require 'tzinfo'
5+
6+
local_html2rss_lib = File.expand_path('../../html2rss/lib', __dir__)
7+
$LOAD_PATH.unshift(local_html2rss_lib) if File.directory?(local_html2rss_lib)
8+
59
require 'html2rss'
610
require 'html2rss/configs'
711

0 commit comments

Comments
 (0)