diff --git a/Rakefile b/Rakefile index 07cdfd9..d327fa3 100644 --- a/Rakefile +++ b/Rakefile @@ -9,6 +9,7 @@ require 'rake/minify' require 'time' require 'yaml' require 'octopress' +require 'rake/testtask' ### Configuring Octopress: ### Under _config/ you will find: @@ -525,3 +526,7 @@ task :list do puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}" puts "(type rake -T for more detail)\n\n" end + +Rake::TestTask.new do |t| + t.pattern = "spec/**/*_spec.rb" +end diff --git a/lib/octopress/configuration.rb b/lib/octopress/configuration.rb index 48c0bf5..0e0034c 100644 --- a/lib/octopress/configuration.rb +++ b/lib/octopress/configuration.rb @@ -2,8 +2,10 @@ require 'yaml' module Octopress module Configuration + CONFIG_DIR = File.join(File.dirname(__FILE__), '../', '../' '_config') + def self.config_dir(*subdirs) - File.absolute_path(File.join(File.dirname(__FILE__), '../', '../' '_config', *subdirs)) + File.absolute_path(File.join(CONFIG_DIR, *subdirs)) end # Static: Reads the configuration of the specified file diff --git a/spec/fixtures/no_override/defaults/classic.yml b/spec/fixtures/no_override/defaults/classic.yml new file mode 100644 index 0000000..1e586e7 --- /dev/null +++ b/spec/fixtures/no_override/defaults/classic.yml @@ -0,0 +1,11 @@ +--- +# ------------------------------- # +# Classic Theme Configuration # +# ------------------------------- # + +url: http://yoursite.com +title: My Octopress Blog +subtitle: A blogging framework for hackers. +author: Your Name +simple_search: http://google.com/search +description: diff --git a/spec/fixtures/override/defaults/classic.yml b/spec/fixtures/override/defaults/classic.yml new file mode 100644 index 0000000..1e586e7 --- /dev/null +++ b/spec/fixtures/override/defaults/classic.yml @@ -0,0 +1,11 @@ +--- +# ------------------------------- # +# Classic Theme Configuration # +# ------------------------------- # + +url: http://yoursite.com +title: My Octopress Blog +subtitle: A blogging framework for hackers. +author: Your Name +simple_search: http://google.com/search +description: diff --git a/spec/fixtures/override/site.yml b/spec/fixtures/override/site.yml new file mode 100644 index 0000000..83b9e6b --- /dev/null +++ b/spec/fixtures/override/site.yml @@ -0,0 +1,11 @@ +--- +# ------------------------------- # +# Classic Theme Configuration # +# ------------------------------- # + +url: http://myownsite.com +title: My Octopress custom Blog +subtitle: "How did this get here? I'm not good with computers" +author: John Doe +simple_search: http://google.com/search +description: diff --git a/spec/octopress/configuration_spec.rb b/spec/octopress/configuration_spec.rb new file mode 100644 index 0000000..59b4b0f --- /dev/null +++ b/spec/octopress/configuration_spec.rb @@ -0,0 +1,42 @@ +require 'minitest/autorun' +require_relative '../../lib/octopress' + +describe Octopress::Configuration do + describe '.read_configuration' do + subject do + Octopress::Configuration.read_configuration + end + + describe "when no override" do + before do + Octopress::Configuration::CONFIG_DIR = File.join(File.dirname(__FILE__), '../', 'fixtures', 'no_override') + end + + it "returns the default config with keys as symbols" do + expected_config = { :url => "http://yoursite.com", + :title => "My Octopress Blog", + :subtitle => "A blogging framework for hackers.", + :author => "Your Name", + :simple_search => "http://google.com/search", + :description => nil } + subject.must_equal expected_config + end + end + + describe "when override" do + before do + Octopress::Configuration::CONFIG_DIR = File.join(File.dirname(__FILE__), '../', 'fixtures', 'override') + end + + it "returns the default config with keys as symbols" do + expected_config = { :url => "http://myownsite.com", + :title => "My Octopress custom Blog", + :subtitle => "How did this get here? I'm not good with computers", + :author => "John Doe", + :simple_search => "http://google.com/search", + :description => nil } + subject.must_equal expected_config + end + end + end +end