Skip to content

Commit 3fc0e81

Browse files
committed
style: fixes
1 parent 8eace25 commit 3fc0e81

5 files changed

Lines changed: 49 additions & 47 deletions

File tree

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
77
gem 'html2rss', github: 'html2rss/html2rss', branch: :master
88

99
group :development do
10-
# gem 'html2rss-generator', path: '../generator'
1110
gem 'html2rss-generator', github: 'html2rss/generator', branch: :main
1211

1312
gem 'nokogiri'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GIT
1212

1313
GIT
1414
remote: https://github.com/html2rss/html2rss
15-
revision: 762a09c15e5def5897b2d08f0e3c11c023cc9b35
15+
revision: e0dca5bf74b17c1e2a0618fc0a4af27c16da1883
1616
branch: master
1717
specs:
1818
html2rss (0.17.0)
@@ -224,7 +224,7 @@ GEM
224224
rubocop-ast (>= 1.49.0, < 2.0)
225225
ruby-progressbar (~> 1.7)
226226
unicode-display_width (>= 2.4.0, < 4.0)
227-
rubocop-ast (1.49.0)
227+
rubocop-ast (1.49.1)
228228
parser (>= 3.3.7.2)
229229
prism (~> 1.7)
230230
rubocop-performance (1.26.1)

bin/validate_configs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,25 @@ files = Dir['lib/html2rss/configs/**/*.yml']
1414
failed = []
1515

1616
files.each do |file|
17-
begin
18-
result = Html2rss::Config.validate_yaml(file)
17+
result = Html2rss::Config.validate_yaml(file)
1918

20-
if result.success?
21-
puts "ok #{file}"
22-
else
23-
puts "FAIL #{file}"
24-
result.errors.to_h.each do |key, messages|
25-
Array(messages).each { |msg| warn " #{key}: #{msg}" }
26-
end
27-
failed << file
28-
end
29-
rescue Psych::Exception => error
30-
puts "FAIL #{file}"
31-
warn " parse: #{error.message}"
32-
failed << file
33-
rescue StandardError => error
19+
if result.success?
20+
puts "ok #{file}"
21+
else
3422
puts "FAIL #{file}"
35-
warn " validation: #{error.class}: #{error.message}"
23+
result.errors.to_h.each do |key, messages|
24+
Array(messages).each { |msg| warn " #{key}: #{msg}" }
25+
end
3626
failed << file
3727
end
28+
rescue Psych::Exception => error
29+
puts "FAIL #{file}"
30+
warn " parse: #{error.message}"
31+
failed << file
32+
rescue StandardError => error
33+
puts "FAIL #{file}"
34+
warn " validation: #{error.class}: #{error.message}"
35+
failed << file
3836
end
3937

4038
puts

spec/bin/validate_configs_spec.rb

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
11
# frozen_string_literal: true
22

33
require 'fileutils'
4-
require 'stringio'
54
require 'tmpdir'
65

7-
RSpec.describe 'bin/validate_configs' do
6+
RSpec.describe 'bin/validate_configs' do # rubocop:disable RSpec/DescribeClass
87
let(:script_path) { File.expand_path('../../bin/validate_configs', __dir__) }
8+
let(:config_path) { File.join('lib', 'html2rss', 'configs', 'example.com', 'search.yml') }
9+
let(:success_output) do
10+
a_string_including(
11+
"ok #{config_path}",
12+
'1 configs validated successfully.'
13+
)
14+
end
915

1016
it 'passes validation for parameterized configs when defaults are present' do
11-
config = <<~YAML
17+
with_temp_config do |dir|
18+
expect { run_script(dir) }.to output(success_output).to_stdout
19+
.and output('').to_stderr
20+
end
21+
end
22+
23+
def with_temp_config
24+
Dir.mktmpdir do |dir|
25+
write_config(dir)
26+
yield dir
27+
end
28+
end
29+
30+
def write_config(dir)
31+
FileUtils.mkdir_p(File.join(dir, File.dirname(config_path)))
32+
File.write(File.join(dir, config_path), valid_config)
33+
end
34+
35+
def run_script(dir)
36+
Dir.chdir(dir) { load script_path }
37+
end
38+
39+
def valid_config
40+
<<~YAML
1241
parameters:
1342
query:
1443
type: string
@@ -23,26 +52,5 @@
2352
title:
2453
selector: "h2"
2554
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
4755
end
4856
end

spec/spec_helper.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
require 'bundler/setup'
44
require 'tzinfo'
55

6-
local_html2rss_lib = File.expand_path('../../html2rss/lib', __dir__)
7-
$LOAD_PATH.unshift(local_html2rss_lib) if File.directory?(local_html2rss_lib)
8-
96
require 'html2rss'
107
require 'html2rss/configs'
118

0 commit comments

Comments
 (0)