Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 80 lines (72 sloc) 2.276 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
require 'spec_helper'

describe Barista do

  context 'hooks'

  context 'configuration'

  context 'setting app_root' do
    it "defaults to Rails.root" do
      Barista::app_root.should == Rails.root
    end
    it "can be set to another directory" do
      new_path = File.expand_path("../../public/javascripts", __FILE__)
      Barista.configure do |c|
        c.app_root = new_path
      end
      Barista::app_root.to_s.should == new_path
    end
  end
  
  context 'preamble' do
    before(:each) do
      @assets_path = File.expand_path("../assets", __FILE__)
      @public_path = File.expand_path("../public", __FILE__)
      Barista.configure do |c|
        c.root = @assets_path
        c.output_root = @public_path
      end
      FileUtils.rm_rf @public_path if File.directory?(@public_path)
    end
    it "is written by default" do
      Barista.add_preamble = true
      Barista::compile_all!
      alert_js = IO.read(File.join(@public_path, "alert.js"))
      alert_js.should include "DO NOT MODIFY"
    end
    it "can be disabled" do
      Barista.add_preamble = false
      Barista::compile_all!
      alert_js = IO.read(File.join(@public_path, "alert.js"))
      alert_js.should_not include "DO NOT MODIFY"
    end
  end

  context 'compiling files'

  context 'compiling all' do
    before(:each) do
      @assets_path = File.expand_path("../assets", __FILE__)
      @public_path = File.expand_path("../public", __FILE__)
      Barista.configure do |c|
        c.root = @assets_path
        c.output_root = @public_path
      end
      FileUtils.rm_rf @public_path if File.directory?(@public_path)
    end
    it "compiles nothing" do
      lambda { Barista::compile_all! false, false }.should_not raise_error
    end
    it "produces alert.js" do
      Barista::compile_all!
      File.exist?(File.join(@public_path, "alert.js")).should be_true
    end
    it "logs when verbose is true" do
      log = StringIO.new
      Barista.logger = Logger.new(log)
      Barista.compile_all!
      log.string.should =~ /\[Barista\].+/
    end
    it "does not log when verbose is false" do
      log = StringIO.new
      Barista.logger = Logger.new(log)
      Barista.verbose = false
      Barista.compile_all!
      log.string.should be_empty
    end
  end

end
Something went wrong with that request. Please try again.