diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9600052 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '3.5', '4.0'] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e33a32 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--require spec_helper +--color +--format documentation diff --git a/CHANGELOG.md b/CHANGELOG.md index 3721763..2e35976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # main [(unreleased)](https://github.com/fastruby/jekyll-external-link-accessibility/compare/v0.2.0...main) -- Your changes/patches go here. +- [CHORE: Add an RSpec test suite and CI matrix running Ruby 2.7 through 4.0](https://github.com/fastruby/jekyll-external-link-accessibility/pull/6) # v0.2.0 / 2026-07-15 [(commits)](https://github.com/fastruby/jekyll-external-link-accessibility/compare/v0.1.0...v0.2.0) diff --git a/Gemfile.lock b/Gemfile.lock index 28bc345..42c62e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ PATH remote: . specs: - jekyll-external-link-accessibility (0.1.0) + jekyll-external-link-accessibility (0.2.0) jekyll (~> 4.0, >= 4.0.1) - nokogiri (~> 1.8, >= 1.8.5) + nokogiri (>= 1.12.0, < 2.0) GEM remote: https://rubygems.org/ @@ -12,6 +12,7 @@ GEM public_suffix (>= 2.0.2, < 6.0) colorator (1.1.0) concurrent-ruby (1.1.9) + diff-lcs (1.6.2) em-websocket (0.5.2) eventmachine (>= 0.12.9) http_parser.rb (~> 0.6.0) @@ -57,11 +58,25 @@ GEM forwardable-extended (~> 2.6) public_suffix (5.0.1) racc (1.6.2) + rake (13.4.2) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) rexml (3.2.5) rouge (3.26.0) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) safe_yaml (1.0.5) sassc (2.4.0) ffi (~> 1.9) @@ -74,6 +89,8 @@ PLATFORMS DEPENDENCIES jekyll-external-link-accessibility! + rake (~> 13.0) + rspec (~> 3.0) BUNDLED WITH - 2.1.4 + 2.4.22 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cffdd09 --- /dev/null +++ b/Rakefile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new(:spec) + +task default: :spec diff --git a/jekyll-external-link-accessibility.gemspec b/jekyll-external-link-accessibility.gemspec index 5f9e09b..71fa15e 100644 --- a/jekyll-external-link-accessibility.gemspec +++ b/jekyll-external-link-accessibility.gemspec @@ -23,5 +23,8 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_dependency "jekyll", '~> 4.0', '>= 4.0.1' - spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.5' + spec.add_dependency 'nokogiri', '>= 1.12.0', '< 2.0' + + spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rake', '~> 13.0' end diff --git a/spec/hooks_spec.rb b/spec/hooks_spec.rb new file mode 100644 index 0000000..0dae260 --- /dev/null +++ b/spec/hooks_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.describe 'pages :post_render hook' do + # Fires the registered hook for a page with the given extension. + def trigger(extname) + page = fake_page('
', 'url' => 'https://example.com') + page.define_singleton_method(:extname) { extname } + Jekyll::Hooks.trigger(:pages, :post_render, page) + end + + before do + allow(Jekyll::ExternalLinkAccessibility).to receive(:modify_links) + end + + it 'rewrites html pages' do + trigger('.html') + trigger('.htm') + + expect(Jekyll::ExternalLinkAccessibility).to have_received(:modify_links).twice + end + + it 'skips non-html pages so xml/json/txt are not corrupted' do + trigger('.xml') + trigger('.json') + trigger('.txt') + + expect(Jekyll::ExternalLinkAccessibility).not_to have_received(:modify_links) + end +end diff --git a/spec/jekyll-external-link-accessibility_spec.rb b/spec/jekyll-external-link-accessibility_spec.rb new file mode 100644 index 0000000..2ae8beb --- /dev/null +++ b/spec/jekyll-external-link-accessibility_spec.rb @@ -0,0 +1,131 @@ +# frozen_string_literal: true + +RSpec.describe Jekyll::ExternalLinkAccessibility do + # Runs modify_links over a snippet wrapped in .post-content and hands back a + # parsed document so specs can assert on the rewritten markup. + def rewrite(inner_html, config: { 'url' => 'https://example.com' }, wrapper: 'post-content') + html = "