test/unit/dassets_tests.rb in dassets-0.2.0 vs test/unit/dassets_tests.rb in dassets-0.3.0
- old
+ new
@@ -6,22 +6,32 @@
class BaseTests < Assert::Context
desc "Dassets"
subject{ Dassets }
- should have_imeths :config, :configure, :init, :digests, :[]
+ should have_imeths :config, :sources, :digests
+ should have_imeths :configure, :reset, :init, :[]
+ should have_imeths :digest_source_files
- should "return its `Config` class with the `config` method" do
- assert_same Config, subject.config
+ should "return a `Config` instance with the `config` method" do
+ assert_kind_of Config, subject.config
end
+ should "read the source list on init" do
+ subject.reset
+ assert_empty subject.sources
+
+ subject.init
+ assert_not_empty subject.sources
+ end
+
should "read/parse the digests on init" do
subject.reset
- assert_empty subject.digests
+ assert_empty subject.digests.paths
subject.init
- assert_not_empty subject.digests
+ assert_not_empty subject.digests.paths
end
should "return asset files given a their path using the index operator" do
subject.init
file = subject['nested/file3.txt']
@@ -40,9 +50,53 @@
subject.init
file = subject['path/not/found.txt']
assert_equal '', file.md5
subject.reset
+ end
+
+ end
+
+ class SourceListTests < BaseTests
+ desc "source list"
+
+ should "build from the configured source path and filter proc" do
+ config = Dassets::Config.new
+ config.source_path = "source_files" # test/support/source_files
+ exp_list = [
+ 'test1.txt', '_ignored.txt', 'nested/test2.txt', 'nested/_nested_ignored.txt'
+ ].map{ |p| File.expand_path(p, config.source_path) }.sort
+
+ assert_equal exp_list, Dassets::SourceList.new(config)
+ end
+
+ should "filter out any paths in the output path" do
+ config = Dassets::Config.new
+ config.source_path = "source_files" # test/support/source_files
+ config.output_path = "source_files/nested"
+ exp_list = [
+ 'test1.txt', '_ignored.txt'
+ ].map{ |p| File.expand_path(p, config.source_path) }.sort
+
+ assert_equal exp_list, Dassets::SourceList.new(config)
+ end
+
+ should "run the supplied source filter on the paths" do
+ config = Dassets::Config.new
+ config.source_path = "source_files" # test/support/source_files
+ config.source_filter = proc do |paths|
+ paths.reject{ |path| File.basename(path) =~ /^_/ }
+ end
+ exp_list = [
+ 'test1.txt', 'nested/test2.txt'
+ ].map{ |p| File.expand_path(p, config.source_path) }.sort
+
+ assert_equal exp_list, Dassets::SourceList.new(config)
+
+ config.source "source_files" do |paths|
+ paths.reject{ |path| File.basename(path) =~ /^_/ }
+ end
+ assert_equal exp_list, Dassets::SourceList.new(config)
end
end
end