Skip to content

Commit 0754f07

Browse files
committed
feat: setup dynamic rspec testing / good-bye manual test creation
1 parent 44c218d commit 0754f07

4 files changed

Lines changed: 97 additions & 7 deletions

File tree

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,41 @@ test-fetch-all-configs:
1616

1717
test-all: test test-fetch-all-configs
1818

19+
# Dynamic test commands
20+
test-config:
21+
@if [ -z "$(CONFIG)" ]; then \
22+
echo "Usage: make test-config CONFIG=github.com/releases.yml"; \
23+
echo " make test-config CONFIG=github.com"; \
24+
exit 1; \
25+
fi
26+
bundle exec rspec --example "$(CONFIG)" spec/html2rss/configs_dynamic_spec.rb
27+
28+
test-domain:
29+
@if [ -z "$(DOMAIN)" ]; then \
30+
echo "Usage: make test-domain DOMAIN=github.com"; \
31+
exit 1; \
32+
fi
33+
bundle exec rspec --example "$(DOMAIN)" spec/html2rss/configs_dynamic_spec.rb
34+
35+
test-debug:
36+
@if [ -z "$(CONFIG)" ]; then \
37+
echo "Usage: make test-debug CONFIG=github.com/releases.yml"; \
38+
exit 1; \
39+
fi
40+
DEBUG_CONFIG=$(CONFIG) bundle exec rspec spec/html2rss/configs_dynamic_spec.rb
41+
42+
# Migration commands
43+
migrate-tests:
44+
bin/migrate_to_dynamic_tests
45+
46+
restore-tests:
47+
@if [ -d "spec/html2rss/configs_backup" ]; then \
48+
cp -r spec/html2rss/configs_backup/* spec/html2rss/configs/; \
49+
echo "✅ Restored tests from backup"; \
50+
else \
51+
echo "❌ No backup found"; \
52+
fi
53+
1954
lintfix:
2055
bundle exec rubocop -a
2156
npx prettier --write lib/**/*.yml .github/**/*.yml README.md

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ channel:
2424

2525
The `type` field specifies the parameter type (currently only `string` is supported), and `default` provides the default value when no parameter is explicitly provided.
2626

27+
## Testing
28+
29+
Uses **dynamic test generation** - no individual spec files needed!
30+
31+
```bash
32+
# Test all configs
33+
bundle exec rspec spec/html2rss/configs_dynamic_spec.rb
34+
35+
# Test specific config
36+
make test-config CONFIG=github.com/releases.yml
37+
38+
# Test domain
39+
make test-domain DOMAIN=github.com
40+
```
41+
42+
**Adding new configs**: Just create the YAML file and run tests. No spec file needed.
43+
2744
## Documentation
2845

2946
- [Main Documentation](https://html2rss.github.io/html2rss-configs/)

bin/rspec_changed_configs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
changed_files = `git diff --name-only origin/master | grep 'lib/html2rss/configs/.*/.*.yml'`.split("\n")
55

6-
specs_to_run = changed_files.filter_map do |file|
7-
filepath = File.expand_path File.join(__dir__, '..', file)
6+
if changed_files.count.positive?
7+
# Use dynamic test file with environment variable to filter changed configs
8+
config_names = changed_files.map { |file| file.sub('lib/html2rss/configs/', '') }
89

9-
"#{file.gsub('lib/', 'spec/')}_spec.rb" if File.exist?(filepath)
10-
end
11-
12-
if specs_to_run.count.positive?
13-
exec "bundle exec rspec --tag fetch #{specs_to_run.join(' ')}"
10+
# Test each changed config individually
11+
config_names.each do |config_name|
12+
puts "Testing changed config: #{config_name}"
13+
system("bundle exec rspec --example '#{config_name}' --tag fetch spec/html2rss/configs_dynamic_spec.rb")
14+
end
1415
else
16+
puts 'No changed config files found'
1517
exit 0
1618
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Html2rss::Configs do
4+
# Get all YAML config files
5+
config_files = Dir.glob('lib/html2rss/configs/**/*.yml')
6+
7+
# Filter by environment variable if specified
8+
config_files = config_files.select { |f| f.include?(ENV['TEST_CONFIG']) } if ENV['TEST_CONFIG']
9+
10+
# Filter by RSpec example pattern if specified
11+
if RSpec.configuration.filter_manager.inclusions.rules[:example]
12+
pattern = RSpec.configuration.filter_manager.inclusions.rules[:example].first
13+
config_files = config_files.select { |f| f.include?(pattern) }
14+
end
15+
16+
config_files.each do |config_file|
17+
relative_path = config_file.sub('lib/html2rss/configs/', '')
18+
config_name = relative_path.tr('/', '_').gsub('.yml', '')
19+
domain = relative_path.split('/').first
20+
21+
describe "#{relative_path} (#{config_name})", config: config_name, domain: domain do
22+
it_behaves_like 'config.yml', relative_path
23+
24+
# Add debugging hook for specific configs
25+
if ENV['DEBUG_CONFIG'] == relative_path
26+
it 'debugs the config' do
27+
puts "Debugging config: #{relative_path}"
28+
puts "File path: #{config_file}"
29+
puts "Config name: #{config_name}"
30+
puts "Domain: #{domain}"
31+
expect(relative_path).to be_a(String) # Add meaningful expectation
32+
end
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)