Skip to content

Commit

Permalink
Specs: always build jekyll site
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead committed Aug 13, 2024
1 parent 3ca67ce commit 2dbcdcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
bundle exec rspec
- name: summary
if: always()
run: ruby specs/support/spec_summary.rb
run: ruby spec/support/spec_summary.rb
26 changes: 16 additions & 10 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration

require 'jekyll'
require 'rspec'
require 'rack'
require 'yaml'
Expand All @@ -30,23 +31,29 @@
require 'axe-rspec'
require 'axe-capybara'

RSPEC_CONFIG_FILE = '_config.yml' or ENV.fetch('RSPEC_CONFIG_FILE', nil)

# ------------
# Tools to build / compile the Jekyll site and extract the sitemap
def site_config
@site_config ||= YAML.load_file(RSPEC_CONFIG_FILE)
# TODO(template): We should standardize the build for specs
# Consider simplifying baseurl
# Consider forcing the desination folder
# Override the local URL too? Would it break the sitemap?
# Note: Config keys must be strings and thus use => style hashes.
@config ||= ::Jekyll.configuration({

Check warning on line 42 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Memoized variable `@config` does not match method name `site_config`. Use `@site_config` instead. Raw Output: spec/spec_helper.rb:42:3: C: Naming/MemoizedInstanceVariableName: Memoized variable `@config` does not match method name `site_config`. Use `@site_config` instead.

Check warning on line 42 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Remove redundant `::`. Raw Output: spec/spec_helper.rb:42:15: C: Style/RedundantConstantBase: Remove redundant `::`.
'sass' => { 'quiet_deps' => true }

Check warning on line 43 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis. Raw Output: spec/spec_helper.rb:43:5: C: Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
})

Check warning on line 44 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Indent the right brace the same as the first position after the preceding left parenthesis. Raw Output: spec/spec_helper.rb:44:3: C: Layout/FirstHashElementIndentation: Indent the right brace the same as the first position after the preceding left parenthesis.
end

def site_url
@site_url ||= site_config['url'] + site_config['baseurl']
end
@site = ::Jekyll::Site.new(site_config)

Check warning on line 47 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Remove redundant `::`. Raw Output: spec/spec_helper.rb:47:9: C: Style/RedundantConstantBase: Remove redundant `::`.
@site.process
puts "Site build complete"

Check warning on line 49 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Prefer single-quoted strings when you don't need string interpolation or special symbols. Raw Output: spec/spec_helper.rb:49:6: C: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

def load_site_urls
puts "Running accessibility tests, expected deploy URL: #{site_url}"
# TODO: Handle case where build is not in _site
puts "Running accessibility tests"

Check warning on line 52 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Prefer single-quoted strings when you don't need string interpolation or special symbols. Raw Output: spec/spec_helper.rb:52:8: C: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
sitemap_text = File.read('_site/sitemap.xml')
sitemap_links = sitemap_text.scan(%r{<loc>.+</loc>})
sitemap_links.filter_map do |link|
link = link.gsub("<loc>#{site_url}", '').gsub('</loc>', '')
link = link.gsub("<loc>#{site_config['url']}", '').gsub('</loc>', '')
# Skip non-html pages
# (FUTURE?) Are there other pages that should be audited for accessibility?
# (e.g. PDFs, documents. They'd need a different checker.)
Expand All @@ -55,7 +62,6 @@ def load_site_urls
link
end.sort
end

# --------

# This is the root of the repository, e.g. the bjc-r directory
Expand Down

0 comments on commit 2dbcdcf

Please sign in to comment.