test/unit/config_tests.rb in dassets-0.2.0 vs test/unit/config_tests.rb in dassets-0.3.0

- old
+ new

@@ -5,23 +5,68 @@ class Dassets::Config class BaseTests < Assert::Context include NsOptions::AssertMacros desc "Dassets::Config" - subject{ Dassets::Config } + setup do + @config = Dassets::Config.new + end + subject{ @config } - should have_option :assets_file, Pathname, :default => ENV['DASSETS_ASSETS_FILE'] - should have_option :root_path, Pathname, :required => true - should have_options :files_path, :digests_file_path + should have_option :root_path, Pathname, :required => true + should have_option :assets_file, Pathname, :default => ENV['DASSETS_ASSETS_FILE'] + should have_options :source_path, :output_path, :digests_path + should have_reader :engines + should have_imeth :source, :engine - should "should use `apps/assets/public` as the default files path" do + should "should use `apps/assets` as the default source path" do + exp_path = Dassets.config.root_path.join("app/assets").to_s + assert_equal exp_path, subject.source_path + end + + should "should use `apps/assets/public` as the default output path" do exp_path = Dassets.config.root_path.join("app/assets/public").to_s - assert_equal exp_path, subject.files_path + assert_equal exp_path, subject.output_path end should "should use `app/assets/.digests` as the default digests file path" do exp_path = Dassets.config.root_path.join("app/assets/.digests").to_s - assert_equal exp_path, subject.digests_file_path + assert_equal exp_path, subject.digests_path.to_s + end + + should "set the source path and filter proc with the `sources` method" do + path = Dassets::RootPath.new 'app/asset_files' + filter = proc{ |paths| [] } + + subject.source(path, &filter) + assert_equal path, subject.source_path + assert_equal filter, subject.source_filter + end + + should "know its engines and return a NullEngine by default" do + assert_kind_of ::Hash, subject.engines + assert_kind_of Dassets::NullEngine, subject.engines['some'] + assert_kind_of Dassets::NullEngine, subject.engines['thing'] + end + + should "allow registering new engines" do + empty_engine = Class.new(Dassets::Engine) do + def ext(input_ext); ''; end + def compile(input); ''; end + end + + assert_kind_of Dassets::NullEngine, subject.engines['empty'] + subject.engine 'empty', empty_engine, 'an' => 'opt' + assert_kind_of empty_engine, subject.engines['empty'] + + assert_equal({'an' => 'opt'}, subject.engines['empty'].opts) + assert_equal '', subject.engines['empty'].ext('empty') + assert_equal '', subject.engines['empty'].compile('some content') + end + + should "should use `apps/assets/public` as the default files path" do + exp_path = Dassets.config.root_path.join("app/assets/public").to_s + assert_equal exp_path, subject.output_path end end end