add theme tests
This commit is contained in:
parent
ada7c4f441
commit
8b880cb993
1
Gemfile
1
Gemfile
|
@ -22,6 +22,7 @@ group :test do
|
||||||
gem "rspec-mocks"
|
gem "rspec-mocks"
|
||||||
gem "nokogiri"
|
gem "nokogiri"
|
||||||
gem "rspec"
|
gem "rspec"
|
||||||
|
gem "test-theme", path: File.expand_path("./test/fixtures/test-theme", File.dirname(__FILE__))
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -4,11 +4,11 @@ module Jekyll
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
@name = name.downcase.strip
|
@name = name.downcase.strip
|
||||||
raise MissingDependencyException unless gemspec
|
raise Jekyll::Errors::MissingDependencyException unless gemspec
|
||||||
end
|
end
|
||||||
|
|
||||||
def root
|
def root
|
||||||
@root ||= gemspec.gem_dir
|
@root ||= gemspec.full_gem_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
|
@ -34,7 +34,8 @@ module Jekyll
|
||||||
private
|
private
|
||||||
|
|
||||||
def path_for(folder)
|
def path_for(folder)
|
||||||
Jekyll.sanitized_path root, "_#{folder}"
|
path = Jekyll.sanitized_path root, "_#{folder}"
|
||||||
|
path if Dir.exists?(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def gemspec
|
def gemspec
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = 'test-theme'
|
||||||
|
s.version = '0.1.0'
|
||||||
|
s.licenses = ['MIT']
|
||||||
|
s.summary = "This is a theme used to test Jekyll"
|
||||||
|
s.authors = ["Jekyll"]
|
||||||
|
s.files = ["lib/example.rb"]
|
||||||
|
s.homepage = 'https://github.com/jekyll/jekyll'
|
||||||
|
end
|
|
@ -0,0 +1,55 @@
|
||||||
|
require 'helper'
|
||||||
|
|
||||||
|
class TestTheme < JekyllUnitTest
|
||||||
|
def setup
|
||||||
|
@theme = Theme.new('test-theme')
|
||||||
|
@expected_root = File.expand_path "./fixtures/test-theme", File.dirname(__FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "initializing" do
|
||||||
|
should "normalize the theme name" do
|
||||||
|
theme = Theme.new(' Test-Theme ')
|
||||||
|
assert_equal "test-theme", theme.name
|
||||||
|
end
|
||||||
|
|
||||||
|
should "know the theme root" do
|
||||||
|
assert_equal @expected_root, @theme.root
|
||||||
|
end
|
||||||
|
|
||||||
|
should "know the theme version" do
|
||||||
|
assert_equal Gem::Version.new("0.1.0"), @theme.version
|
||||||
|
end
|
||||||
|
|
||||||
|
should "raise an error for invalid themes" do
|
||||||
|
assert_raises Jekyll::Errors::MissingDependencyException do
|
||||||
|
Theme.new("foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "path generation" do
|
||||||
|
["assets", "layouts", "includes", "sass"].each do |folder|
|
||||||
|
should "know the #{folder} path" do
|
||||||
|
expected = File.expand_path("_#{folder}", @expected_root)
|
||||||
|
assert_equal expected, @theme.public_send("#{folder}_path")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "generate folder paths" do
|
||||||
|
expected = File.expand_path("_assets", @expected_root)
|
||||||
|
assert_equal expected, @theme.send(:path_for, "assets")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not allow paths outside of the theme root" do
|
||||||
|
assert_equal nil, @theme.send(:path_for, "../../source")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return nil for paths that don't exist" do
|
||||||
|
assert_equal nil, @theme.send(:path_for, "foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "retrieve the gemspec" do
|
||||||
|
assert_equal "test-theme-0.1.0", @theme.send(:gemspec).full_name
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue