require 'spec_helper'

describe Willow::Initializer do

  before do
    @path = File.expand_path("spec/tmp-initializer")
    FileUtils.rm_rf @path if File.directory?(@path)
    @options = Willow.configure({ log_level: 'none' })
    Willow::Initializer.new(@path, @options)
  end

  after do
    FileUtils.rm_rf @path
  end

  %w(assets assets/javascripts assets/stylesheets pages posts public layouts layouts/partials).each do |dir|
    it "should create #{dir}" do
      File.directory?("#{@path}/#{dir}").must_equal true
    end
  end

  it "should copy the .htaccess file" do
    File.exists?("#{@path}/public/.htaccess").must_equal true
  end

  it "should copy starter assets" do
    File.exists?("#{@path}/assets/javascripts/application.js").must_equal true
    File.exists?("#{@path}/assets/stylesheets/application.css").must_equal true
  end

  %w(default.mustache partials/header.mustache partials/footer.mustache).each do |f|
    it "should copy the #{f} file" do
      File.exists?("#{@path}/layouts/#{f}").must_equal true
    end
  end

  it "should copy the default .gitignore" do
    File.exists?("#{@path}/.gitignore").must_equal true
  end

  it "should generate the config file" do
    File.exists?("#{@path}/config.yml").must_equal true
  end

  describe "config file contents" do

    before do
      @contents = File.open("#{@path}/config.yml", 'r') {|f| YAML.load(f) }
    end

    it "should not contain the paths info" do
      @contents.wont_include :paths
    end

    it "should not contain the source info" do
      @contents.wont_include :source
    end

    it "should contain target info" do
      @contents.must_include :target
    end

    it "should contain defaults info" do
      @contents[:defaults].must_include :layout
      @contents[:defaults].must_include :extension
      @contents[:defaults].must_include :site_name
      @contents[:defaults].must_include :copyright
      @contents[:defaults][:copyright].must_equal Time.now.year
    end

  end

end
