require 'spec_helper' require 'fileutils' require 'yaml' describe Noumenon::Theme do describe "loading from a directory" do context "when the directory does not exist" do it "raises a Theme::NotFoundError" do lambda { Noumenon::Theme.load File.join(File.dirname(__FILE__), "non_existant") }.should raise_error Noumenon::Theme::NotFoundError end end context "when no theme.yml file exists in the directory" do it "raises a Theme::NotFoundError" do with_temporary_theme(nil) do lambda { Noumenon::Theme.load theme_path }.should raise_error Noumenon::Theme::NotFoundError end end end context "when a theme.yml file exists" do let(:description) do { "name" => "Example Theme", "author" => "Jon Wood", "email" => "jon@blankpad.net", "copyright" => "Blank Pad Development, 2011", "license" => "MIT" } end around(:each) do |example| with_temporary_theme(description) do example.run end end it "doesn't raise any errors on load" do lambda { Noumenon::Theme.load theme_path }.should_not raise_error end it "returns an instance of Noumenon::Theme" do Noumenon::Theme.load(theme_path).should be_instance_of Noumenon::Theme end it "registers the theme for use" do theme = Noumenon::Theme.load(theme_path) Noumenon::Theme.themes.keys.should include "Example Theme" Noumenon::Theme.themes["Example Theme"].should == theme end it "sets the path the theme has been loaded from" do theme = Noumenon::Theme.load theme_path theme.path.should == theme_path end %w(name author email copyright license).each do |field| it "reads the #{field} from the theme description" do theme = Noumenon::Theme.load theme_path theme.send(field).should == description[field] end end it "can load symbolised keys as well" do theme = Noumenon::Theme.new(theme_path, name: "Example") theme.name.should == "Example" end end end describe "a loaded theme" do around do |example| with_temporary_theme(name: "Example Theme") do example.run end end let(:theme) { Noumenon::Theme.load theme_path } describe "loading a template" do it "when the template did not exist, it raises Template::NotFoundError" do lambda { theme.template("not_found") }.should raise_error Noumenon::Template::NotFoundError end context "when the template did exist" do let(:template) { "