diff --git a/Gemfile b/Gemfile index be260aa..104f863 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } gem 'html2rss', github: 'html2rss/html2rss', branch: :master group :development do - # gem 'html2rss-generator', path: '../generator' gem 'html2rss-generator', github: 'html2rss/generator', branch: :main gem 'nokogiri' diff --git a/Gemfile.lock b/Gemfile.lock index 7c32dfc..babf2a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,7 +12,7 @@ GIT GIT remote: https://github.com/html2rss/html2rss - revision: 762a09c15e5def5897b2d08f0e3c11c023cc9b35 + revision: e0dca5bf74b17c1e2a0618fc0a4af27c16da1883 branch: master specs: html2rss (0.17.0) @@ -224,7 +224,7 @@ GEM rubocop-ast (>= 1.49.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.49.0) + rubocop-ast (1.49.1) parser (>= 3.3.7.2) prism (~> 1.7) rubocop-performance (1.26.1) diff --git a/bin/setup b/bin/setup index 935796b..243eb57 100755 --- a/bin/setup +++ b/bin/setup @@ -7,7 +7,7 @@ bundle install echo echo "==> Installing Node dependencies (required for make lint)..." -npm install --ignore-scripts --no-fund --no-audit +npm ci --ignore-scripts --no-fund --no-audit echo echo "==> Checking system tools..." diff --git a/bin/validate_configs b/bin/validate_configs index 4fef430..13442e9 100755 --- a/bin/validate_configs +++ b/bin/validate_configs @@ -3,14 +3,18 @@ require 'bundler/setup' require 'html2rss' -require 'yaml' + +unless Html2rss::Config.respond_to?(:validate_yaml) + warn 'Error: installed html2rss gem does not support Config.validate_yaml.' + warn 'Run: bundle update html2rss' + exit 1 +end files = Dir['lib/html2rss/configs/**/*.yml'] failed = [] files.each do |file| - config = YAML.safe_load_file(file, symbolize_names: true) - result = Html2rss::Config.validate(config) + result = Html2rss::Config.validate_yaml(file) if result.success? puts "ok #{file}" diff --git a/spec/bin/validate_configs_spec.rb b/spec/bin/validate_configs_spec.rb new file mode 100644 index 0000000..cb8aa07 --- /dev/null +++ b/spec/bin/validate_configs_spec.rb @@ -0,0 +1,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: "%s" + channel: + url: "https://example.com/search?q=%s" + selectors: + items: + selector: ".item" + title: + selector: "h2" + YAML + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0c977d5..98fb42e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require 'bundler/setup' require 'tzinfo' + require 'html2rss' require 'html2rss/configs'