"
end
private
def uri
return @uri if defined? @uri
@uri = if THEME_REGEX.match?(@raw_theme)
Addressable::URI.new(
:scheme => "https",
:host => "github.com",
:path => @raw_theme
)
else
Addressable::URI.parse @raw_theme
end
rescue Addressable::URI::InvalidURIError
@uri = nil
end
def theme_parts
@theme_parts ||= uri.path[1..-1].match(THEME_REGEX) if uri
end
def gemspec
@gemspec ||= MockGemspec.new(self)
end
def valid_hosts
@valid_hosts ||= [
"github.com",
ENV["PAGES_GITHUB_HOSTNAME"],
ENV["GITHUB_HOSTNAME"],
].compact.to_set
end
end
end
end
jekyll-remote-theme-0.4.3/lib/jekyll-remote-theme/version.rb 0000664 0000000 0000000 00000000142 14022223551 0024035 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module Jekyll
module RemoteTheme
VERSION = "0.4.3"
end
end
jekyll-remote-theme-0.4.3/script/ 0000775 0000000 0000000 00000000000 14022223551 0016701 5 ustar 00root root 0000000 0000000 jekyll-remote-theme-0.4.3/script/bootstrap 0000775 0000000 0000000 00000000032 14022223551 0020637 0 ustar 00root root 0000000 0000000 #!/bin/sh
bundle install
jekyll-remote-theme-0.4.3/script/cibuild 0000775 0000000 0000000 00000000137 14022223551 0020243 0 ustar 00root root 0000000 0000000 #!/bin/sh
set -e
bundle exec rspec
bundle exec rubocop
gem build jekyll-remote-theme.gemspec
jekyll-remote-theme-0.4.3/script/console 0000775 0000000 0000000 00000000075 14022223551 0020273 0 ustar 00root root 0000000 0000000 #!/bin/sh
bundle exec pry -r './lib/jekyll-remote-theme.rb'
jekyll-remote-theme-0.4.3/spec/ 0000775 0000000 0000000 00000000000 14022223551 0016327 5 ustar 00root root 0000000 0000000 jekyll-remote-theme-0.4.3/spec/fixtures/ 0000775 0000000 0000000 00000000000 14022223551 0020200 5 ustar 00root root 0000000 0000000 jekyll-remote-theme-0.4.3/spec/fixtures/gemspecs/ 0000775 0000000 0000000 00000000000 14022223551 0022006 5 ustar 00root root 0000000 0000000 jekyll-remote-theme-0.4.3/spec/fixtures/gemspecs/alldeps.gemspec 0000664 0000000 0000000 00000001057 14022223551 0025002 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "alldeps/version"
Gem::Specification.new do |s|
s.name = "alldeps"
s.version = AllDeps::VERSION
s.authors = ["John Doe"]
s.summary = "Dummy gemspec"
# runtime dependencies
s.add_dependency "jekyll", "~> 3.5"
s.add_dependency "jekyll-feed", "~> 0.6"
s.add_dependency "jekyll-sitemap", "~> 1.5"
# development dependencies
s.add_dependency "bundler", "~> 1.12"
s.add_dependency "rake", "~> 10.0"
end
jekyll-remote-theme-0.4.3/spec/fixtures/gemspecs/braces.gemspec 0000664 0000000 0000000 00000001234 14022223551 0024612 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "braces/version"
Gem::Specification.new do |s|
s.name = "braces"
s.version = Braces::VERSION
s.authors = ["John Doe"]
s.summary = "Dummy gemspec"
# rubocop:disable Style/StringLiterals
# runtime dependencies
s.add_dependency('jekyll', "~> 3.5")
s.add_dependency('jekyll-feed', "~> 0.6")
s.add_dependency('jekyll-sitemap', "~> 1.5")
# development dependencies
s.add_dependency('bundler', "~> 1.12")
s.add_dependency('rake', "~> 10.0")
# rubocop:enable Style/StringLiterals
end
jekyll-remote-theme-0.4.3/spec/fixtures/gemspecs/nodeps.gemspec 0000664 0000000 0000000 00000000622 14022223551 0024643 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "nodeps/version"
Gem::Specification.new do |s|
s.name = "nodeps"
s.version = Lorem::VERSION
s.authors = ["John Doe"]
s.summary = "Dummy gemspec"
s.add_development_dependency("bundler", "~> 1.12")
s.add_development_dependency("rake", "~> 10.0")
end
jekyll-remote-theme-0.4.3/spec/fixtures/gemspecs/rundev.gemspec 0000664 0000000 0000000 00000001134 14022223551 0024655 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "rundev/version"
Gem::Specification.new do |spec|
spec.name = "rundev"
spec.version = RunDev::VERSION
spec.authors = ["John Doe"]
spec.summary = "Dummy gemspec"
spec.add_runtime_dependency "jekyll", "~> 3.5"
spec.add_runtime_dependency "jekyll-feed", "~> 0.6" # some "random" comment
spec.add_runtime_dependency "jekyll-sitemap", "~> 1.5"
spec.add_development_dependency "bundler", "~> 1.12"
spec.add_development_dependency "rake", "~> 10.0"
end
jekyll-remote-theme-0.4.3/spec/fixtures/site-without-theme/ 0000775 0000000 0000000 00000000000 14022223551 0023745 5 ustar 00root root 0000000 0000000 jekyll-remote-theme-0.4.3/spec/fixtures/site-without-theme/index.md 0000664 0000000 0000000 00000000036 14022223551 0025375 0 ustar 00root root 0000000 0000000 ---
---
# Site without theme
jekyll-remote-theme-0.4.3/spec/fixtures/site/ 0000775 0000000 0000000 00000000000 14022223551 0021144 5 ustar 00root root 0000000 0000000 jekyll-remote-theme-0.4.3/spec/fixtures/site/_config.yml 0000664 0000000 0000000 00000000226 14022223551 0023273 0 ustar 00root root 0000000 0000000 plugins:
- jekyll-remote-theme
remote_theme: pages-themes/PrImeR
whitelist:
- jekyll-remote-theme
- jekyll-seo-tag
- jekyll-github-metadata
jekyll-remote-theme-0.4.3/spec/fixtures/site/_malicious_config.yml 0000664 0000000 0000000 00000000245 14022223551 0025341 0 ustar 00root root 0000000 0000000 plugins:
- jekyll-remote-theme
remote_theme: jekyll/jekyll-test-theme-malicious
whitelist:
- jekyll-remote-theme
- jekyll-seo-tag
- jekyll-github-metadata
jekyll-remote-theme-0.4.3/spec/fixtures/site/index.md 0000664 0000000 0000000 00000000050 14022223551 0022570 0 ustar 00root root 0000000 0000000 ---
layout: default
---
# Fixture site
jekyll-remote-theme-0.4.3/spec/jekyll-remote-theme/ 0000775 0000000 0000000 00000000000 14022223551 0022212 5 ustar 00root root 0000000 0000000 jekyll-remote-theme-0.4.3/spec/jekyll-remote-theme/downloader_spec.rb 0000664 0000000 0000000 00000005477 14022223551 0025724 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
RSpec.describe Jekyll::RemoteTheme::Downloader do
let(:raw_theme) { "pages-themes/primer" }
let(:theme) { Jekyll::RemoteTheme::Theme.new(raw_theme) }
subject { described_class.new(theme) }
before { reset_tmp_dir }
it "knows it's not downloaded" do
expect(subject.downloaded?).to be_falsy
end
it "creates a zip file" do
expect(subject.send(:zip_file)).to be_an_existing_file
end
context "downloading" do
before { subject.run }
after { FileUtils.rm_rf theme.root if Dir.exist?(theme.root) }
it "knows it's downloaded" do
expect(subject.downloaded?).to be_truthy
end
it "extracts the theme" do
expect("#{theme.root}/_layouts/default.html").to be_an_existing_file
end
it "deletes the zip file" do
expect(subject.send(:zip_file).path).to be_nil
end
it "knows the theme dir exists" do
expect(subject.send(:theme_dir_exists?)).to be_truthy
end
it "knows the theme dir isn't empty" do
expect(subject.send(:theme_dir_empty?)).to be_falsy
end
end
context "zip_url" do
it "builds the zip url" do
expected = "https://codeload.github.com/pages-themes/primer/zip/HEAD"
expect(subject.send(:zip_url).to_s).to eql(expected)
end
context "a custom host" do
let(:raw_theme) { "http://example.com/pages-themes/primer" }
it "builds the zip url" do
expected = "http://codeload.example.com/pages-themes/primer/zip/HEAD"
expect(subject.send(:zip_url).to_s).to eql(expected)
end
end
end
context "with zip_url stubbed" do
before { allow(subject).to receive(:zip_url) { Addressable::URI.parse zip_url } }
context "with an invalid URL" do
let(:zip_url) { "https://codeload.github.com/benbalter/_invalid_/zip/HEAD" }
before do
WebMock.disable_net_connect!
stub_request(:get, zip_url).to_return(:status => [404, "Not Found"])
end
after { WebMock.allow_net_connect! }
it "raises a DownloadError" do
msg = "404 - Not Found - Loading URL: https://codeload.github.com/benbalter/_invalid_/zip/HEAD"
expect { subject.run }.to raise_error(Jekyll::RemoteTheme::DownloadError, msg)
end
end
context "with a large file" do
let(:zip_url) { "https://codeload.github.com/benbalter/_invalid_/zip/HEAD" }
let(:content_length) { 10 * 1024 * 1024 * 1024 }
let(:headers) { { "Content-Length" => content_length } }
before do
WebMock.disable_net_connect!
stub_request(:get, zip_url).to_return(:headers => headers)
end
after { WebMock.allow_net_connect! }
it "raises a DownloadError" do
msg = "Maximum file size of 1073741824 bytes exceeded"
expect { subject.run }.to raise_error(Jekyll::RemoteTheme::DownloadError, msg)
end
end
end
end
jekyll-remote-theme-0.4.3/spec/jekyll-remote-theme/integration_spec.rb 0000664 0000000 0000000 00000005253 14022223551 0026101 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
RSpec.describe "Jekyll::RemoteTheme Integration" do
attr_reader :output, :status
def config_path
File.join source_dir, "_config.yml"
end
def malicious_config_path
File.join source_dir, "_malicious_config.yml"
end
def args(config_path)
[
"bundle", "exec", "jekyll", "build", "--config", config_path,
"--source", source_dir, "--dest", dest_dir, "--verbose", "--safe",
]
end
def build_site(config_path)
Dir.chdir tmp_dir do
@output, @status = Open3.capture2e(*args(config_path))
@output = @output.encode("UTF-8",
:invalid => :replace, :undef => :replace, :replace => "")
end
end
let(:theme) { "pages-themes/primer" }
let(:index_path) { File.join dest_dir, "index.html" }
let(:index_contents) { File.read(index_path) }
let(:stylesheet_path) { File.join dest_dir, "assets", "css", "style.css" }
context "the pages-themes/primer theme" do
before(:all) { reset_tmp_dir }
before(:all) { build_site(config_path) }
after(:all) { reset_tmp_dir }
it "returns a zero exit code" do
expect(status.exitstatus).to eql(0), output
end
it "outputs that it's using a remote theme" do
expect(output).to match("Remote Theme: Using theme #{theme}")
end
it "build the index" do
expect(index_path).to be_an_existing_file
end
it "uses the theme" do
expected = ''
expect(index_contents).to match(expected)
end
it "builds stylesheets" do
expect(stylesheet_path).to be_an_existing_file
end
it "requires dependencies" do
expect(output).to include("Requiring: jekyll-seo-tag")
expect(index_contents).to include("Begin Jekyll SEO tag")
end
end
context "the jekyll/jekyll-test-theme-malicious theme" do
let(:theme) { "jekyll/jekyll-test-theme-malicious" }
before(:all) { reset_tmp_dir }
before(:all) { build_site(malicious_config_path) }
after(:all) { reset_tmp_dir }
it "returns a zero exit code" do
expect(status.exitstatus).to eql(0), output
end
it "outputs that it's using a remote theme" do
expect(output).to match("Remote Theme: Using theme #{theme}")
end
it "build the index" do
expect(index_path).to be_an_existing_file
end
it "uses the theme" do
expect(index_contents).to include("Begin Jekyll SEO tag")
end
it "requires whitelisted dependencies" do
expect(output).to include("Requiring: jekyll-seo-tag")
end
it "dosn't requires unsafe dependencies" do
expect(output).to_not include("jekyll_test_plugin_malicious"), output
end
end
end
jekyll-remote-theme-0.4.3/spec/jekyll-remote-theme/mock_gemspec_spec.rb 0000664 0000000 0000000 00000003602 14022223551 0026206 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
RSpec.describe Jekyll::RemoteTheme::MockGemspec do
let(:fixture) { "alldeps" }
let(:contents) { File.read gemspec_dir("#{fixture}.gemspec") }
let(:filename) { "#{theme.name}.gemspec" }
let(:path) { File.expand_path filename, theme.root }
let(:nwo) { "pages-themes/primer" }
let(:theme) { Jekyll::RemoteTheme::Theme.new(nwo) }
subject { described_class.new(theme) }
before { File.write path, contents }
it "stores the theme" do
expect(subject.send(:theme)).to eql(theme)
end
it "determines the path" do
expect(subject.send(:path)).to eql(path)
end
it "reads the contents" do
expect(subject.send(:contents)).to eql(contents)
end
it "builds potential_paths" do
expect(subject.send(:potential_paths)).to include(path)
end
it "returns the theme root" do
expect(subject.full_gem_path).to eql(theme.root)
end
context "fixtures" do
let(:dependency_names) { subject.send(:dependency_names) }
let(:runtime_dependencies) { subject.runtime_dependencies }
# Hash in the form of gemspec fixture => expected dependencies
{
"alldeps" => %w(jekyll jekyll-feed jekyll-sitemap bundler rake),
"braces" => %w(jekyll jekyll-feed jekyll-sitemap bundler rake),
"rundev" => %w(jekyll jekyll-feed jekyll-sitemap),
"nodeps" => [],
}.each do |fixture, expected|
context "the #{fixture} gemspec" do
let(:fixture) { fixture }
it "returns dependency names" do
expect(dependency_names).to eql(expected)
end
it "returns #{expected.count} runtime dependencies" do
expect(runtime_dependencies.count).to eql(expected.count)
unless expected.empty?
expect(runtime_dependencies.first).to be_a(Gem::Dependency)
expect(runtime_dependencies.map(&:name)).to eql(expected)
end
end
end
end
end
end
jekyll-remote-theme-0.4.3/spec/jekyll-remote-theme/munger_spec.rb 0000664 0000000 0000000 00000007706 14022223551 0025060 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
RSpec.describe Jekyll::RemoteTheme::Munger do
let(:source) { source_dir }
let(:overrides) { {} }
let(:config) { { "source" => source, "safe" => true }.merge(overrides) }
let(:site) { make_site(config) }
let(:theme_dir) { theme&.root }
let(:layout_path) { File.expand_path "_layouts/default.html", theme_dir }
let(:sass_dir) { File.expand_path "_sass/", theme_dir }
let(:sass_path) { File.expand_path "jekyll-theme-primer.scss", sass_dir }
let(:includes_dir) { File.expand_path "_includes/", theme_dir }
let(:theme) { subject.send(:theme) }
subject { described_class.new(site) }
before { Jekyll.logger.log_level = :error }
before { reset_tmp_dir }
# Remove :after_reset hook to allow themes to be stubbed prior to munging
before(:each) do
hooks = Jekyll::Hooks.instance_variable_get("@registry")
hooks[:site][:after_reset] = []
Jekyll::Hooks.instance_variable_set("@registry", hooks)
end
it "stores the site" do
expect(subject.site).to be_a(Jekyll::Site)
end
context "without a theme" do
let(:source) { fixture_path("site-without-theme") }
it "doesn't set a theme" do
expect(site.theme).to_not be_a(Jekyll::RemoteTheme::Theme)
end
it "doesn't clone" do
expect(layout_path).to_not be_an_existing_file
end
end
context "with theme as a hash" do
let(:overrides) { { "remote_theme" => { "foo" => "bar" } } }
before { subject.munge! }
it "doesn't set a theme" do
expect(site.theme).to_not be_a(Jekyll::RemoteTheme::Theme)
end
it "doesn't clone" do
expect(layout_path).to_not be_an_existing_file
end
end
context "with a remote theme" do
let(:overrides) { { "remote_theme" => "pages-themes/primer" } }
before do
@old_logger = Jekyll.logger
@stubbed_logger = StringIO.new
Jekyll.logger = Logger.new(@stubbed_logger)
Jekyll.logger.log_level = :debug
end
before { subject.munge! }
after { Jekyll.instance_variable_set("@logger", @old_logger) }
it "sets the theme" do
expect(site.theme).to be_a(Jekyll::RemoteTheme::Theme)
expect(site.theme.name).to eql("primer")
expect(site.config["theme"]).to eql("primer")
end
it "downloads" do
expect(layout_path).to be_an_existing_file
end
it "sets sass paths" do
expect(sass_path).to be_an_existing_file
if Jekyll::VERSION >= "4.0"
converter = Jekyll::Converters::Scss.new(site.config)
expect(converter.sass_configs[:load_paths]).to include(sass_dir)
else
expect(Sass.load_paths).to include(sass_dir)
end
end
it "sets include paths" do
expect(site.includes_load_paths).to include(includes_dir)
end
it "sets layouts" do
site.read
expect(site.layouts["default"]).to be_truthy
expect(site.layouts["default"].path).to eql(layout_path)
end
it "requires plugins" do
@stubbed_logger.rewind
expect(@stubbed_logger.read).to include("Requiring: jekyll-seo-tag")
end
end
context "with a malicious theme" do
let(:overrides) { { "remote_theme" => "jekyll/jekyll-test-theme-malicious" } }
before do
@old_logger = Jekyll.logger
@stubbed_logger = StringIO.new
Jekyll.logger = Logger.new(@stubbed_logger)
Jekyll.logger.log_level = :debug
end
before { subject.munge! }
after { Jekyll.instance_variable_set("@logger", @old_logger) }
it "sets the theme" do
expect(site.theme).to be_a(Jekyll::RemoteTheme::Theme)
expect(site.theme.name).to eql("jekyll-test-theme-malicious")
expect(site.config["theme"]).to eql("jekyll-test-theme-malicious")
end
it "requires whitelisted plugins" do
@stubbed_logger.rewind
expect(@stubbed_logger.read).to include("Requiring: jekyll-seo-tag")
end
it "doesn't require malicious plugins" do
@stubbed_logger.rewind
expect(@stubbed_logger.read).to_not include("jekyll_test_plugin_malicious")
end
end
end
jekyll-remote-theme-0.4.3/spec/jekyll-remote-theme/theme_spec.rb 0000664 0000000 0000000 00000007121 14022223551 0024654 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
RSpec.describe Jekyll::RemoteTheme::Theme do
let(:scheme) { nil }
let(:host) { nil }
let(:owner) { "foo" }
let(:name) { "bar" }
let(:nwo) { "#{owner}/#{name}" }
let(:git_ref) { nil }
let(:raw_theme) do
raw_theme = +""
raw_theme << "#{scheme}://#{host}/" if scheme && host
raw_theme << nwo.to_s
raw_theme << "@#{git_ref}" if git_ref
raw_theme
end
subject { described_class.new(raw_theme) }
it "stores the theme" do
expect(subject.instance_variable_get("@raw_theme")).to eql(nwo)
end
context "with an abnormal NWO" do
let(:nwo) { " FoO/bAr " }
it "normalizes the nwo" do
expect(subject.instance_variable_get("@raw_theme")).to eql("foo/bar")
end
end
it "extracts the name" do
expect(subject.name).to eql(name)
end
it "extracts the owner" do
expect(subject.owner).to eql(owner)
end
it "uses the default host" do
expect(subject.host).to eql("github.com")
end
it "uses the default scheme" do
expect(subject.scheme).to eql("https")
end
it "builds the name with owner" do
expect(subject.name_with_owner).to eql(nwo)
expect(subject.nwo).to eql(nwo)
end
it "knows it's valid" do
expect(subject).to be_valid
end
context "a random string" do
let(:nwo) { "foo" }
it "isn't valid" do
expect(subject).to_not be_valid
end
end
context "with a non-string" do
let(:nwo) { [1, 2] }
it "isn't valid" do
expect(subject).to_not be_valid
end
end
context "with a non-nwo string" do
let(:nwo) { "foo/javascript: alert(1);" }
it "isn't valid" do
expect(subject).to_not be_valid
end
end
it "defaults git_ref to HEAD" do
expect(subject.git_ref).to eql("HEAD")
end
context "with a git_ref" do
let(:git_ref) { "foo" }
it "parses the git ref" do
expect(subject.git_ref).to eql(git_ref)
end
end
it "knows its root" do
expect(Dir.exist?(subject.root)).to be_truthy
end
it "exposes gemspec" do
expect(subject.send(:gemspec)).to be_a(Jekyll::RemoteTheme::MockGemspec)
end
context "a full URL" do
let(:host) { "github.com" }
let(:scheme) { "https" }
it "extracts the name" do
expect(subject.name).to eql(name)
end
it "extracts the owner" do
expect(subject.owner).to eql(owner)
end
it "extracts the host" do
expect(subject.host).to eql("github.com")
end
it "extracts the scheme" do
expect(subject.scheme).to eql("https")
end
it "is valid" do
with_env "GITHUB_HOSTNAME", "enterprise.github.com" do
expect(subject).to be_valid
end
end
context "a custom host" do
let(:host) { "example.com" }
let(:scheme) { "http" }
it "extracts the name" do
expect(subject.name).to eql(name)
end
it "extracts the owner" do
expect(subject.owner).to eql(owner)
end
it "extracts the host" do
expect(subject.host).to eql(host)
end
it "extracts the scheme" do
expect(subject.scheme).to eql(scheme)
end
it "is valid if a whitelisted host name" do
with_env "GITHUB_HOSTNAME", "example.com" do
expect(subject).to be_valid
end
end
it "is invalid if not a whitelisted host name" do
with_env "GITHUB_HOSTNAME", "enterprise.github.com" do
expect(subject).to_not be_valid
end
end
context "with a git ref" do
let(:git_ref) { "foo" }
it "parses the git ref" do
expect(subject.git_ref).to eql(git_ref)
end
end
end
end
end
jekyll-remote-theme-0.4.3/spec/jekyll_remote_theme_spec.rb 0000664 0000000 0000000 00000001034 14022223551 0023713 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
RSpec.describe Jekyll::RemoteTheme do
let(:source) { source_dir }
let(:config) { { "source" => source } }
let(:site) { make_site(config) }
subject { described_class }
it "returns the version" do
expect(subject::VERSION).to match(%r!\d+\.\d+\.\d+!)
end
it "inits" do
expect(subject.init(site)).to be_a(Jekyll::RemoteTheme::Theme)
expect(site.theme).to be_a(Jekyll::RemoteTheme::Theme)
expect(File.join(site.theme.root, "_layouts/default.html")).to be_an_existing_file
end
end
jekyll-remote-theme-0.4.3/spec/spec_helper.rb 0000664 0000000 0000000 00000002470 14022223551 0021150 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require_relative "../lib/jekyll-remote-theme"
require "fileutils"
require "open3"
require "pathname"
require "webmock/rspec"
WebMock.allow_net_connect!
RSpec.configure do |config|
config.example_status_persistence_file_path = "spec/examples.txt"
config.disable_monkey_patching!
config.warnings = true
config.default_formatter = "doc" if config.files_to_run.one?
config.order = :random
Kernel.srand config.seed
end
RSpec::Matchers.define :be_an_existing_file do
match { |path| File.exist?(path) }
end
def tmp_dir
@tmp_dir ||= File.expand_path "../tmp", __dir__
end
def source_dir
@source_dir ||= fixture_path "site"
end
def dest_dir
@dest_dir ||= File.join tmp_dir, "dest"
end
def gemspec_dir(*contents)
File.join(fixture_path("gemspecs"), *contents)
end
def reset_tmp_dir
FileUtils.rm_rf tmp_dir
FileUtils.mkdir_p tmp_dir
end
def fixture_path(fixture)
File.expand_path "fixtures/#{fixture}", __dir__
end
def config_defaults
{
"source" => source_dir,
"destination" => dest_dir,
"gems" => ["jekyll-remote-theme"],
}
end
def make_site(options = {})
config = Jekyll.configuration config_defaults.merge(options)
Jekyll::Site.new(config)
end
def with_env(key, value)
old_env = ENV[key]
ENV[key] = value
yield
ENV[key] = old_env
end