test/unit/release/cleaner_test.rb in roger-1.2.2 vs test/unit/release/cleaner_test.rb in roger-1.3.0

- old
+ new

@@ -1,72 +1,69 @@ -require "./lib/roger/release.rb" -require "./lib/roger/release/cleaner.rb" -require "test/unit" +require "test_helper" +require "roger/testing/mock_release" -# Test Roger Cleaner -class CleanerTest < ::Test::Unit::TestCase - def setup - @base = File.dirname(__FILE__) + "/../../project" - end +module Roger + # Test Roger Cleaner + class CleanerTest < ::Test::Unit::TestCase + def setup + @release = Testing::MockRelease.new + end - def test_use_array_as_pattern - dirs = %w(dir1 dir2) + def teardown + @release.destroy + @release = nil + end - create_and_assert_directories(dirs) + def test_use_array_as_pattern + dirs = %w(dir1 dir2) - project = Roger::Project.new(@base) - release = Roger::Release.new(project, build_path: Pathname.new(@base)) + dirs.each do |dir| + @release.project.construct.directory "build/#{dir}" + end - cleaner = Roger::Release::Cleaner.new(dirs) - cleaner.call(release) + cleaner = Roger::Release::Cleaner.new(dirs) + cleaner.call(@release) - dirs.each do |dir| - path = @base + "/" + dir - assert(!File.directory?(path)) + dirs.each do |dir| + path = @release.build_path + dir + assert(!File.directory?(path)) + end end - end - def test_only_clean_inside_build_path_relative - cleaner = Roger::Release::Cleaner.new(@base) - inside_build_path = cleaner.send :inside_build_path?, @base, @base + "/html/formats" + def test_only_clean_inside_build_path_relative + project_path = @release.project.path + cleaner = Roger::Release::Cleaner.new(project_path) + inside = cleaner.send :inside_build_path?, project_path, project_path + "html" - assert(inside_build_path, "Only delete content inside build_path") - end + assert(inside, "Only delete content inside build_path") + end - def test_only_clean_inside_build_path_absolute - path = Pathname.new(@base).realpath.to_s - cleaner = Roger::Release::Cleaner.new(path) + def test_only_clean_inside_build_path_absolute + project_path = @release.project.path + path = Pathname.new(project_path).realpath.to_s + cleaner = Roger::Release::Cleaner.new(path) - inside_build_path = cleaner.send :inside_build_path?, path, @base + "/html/formats" + inside = cleaner.send :inside_build_path?, path, project_path + "html" - assert(inside_build_path, "Only delete content inside build_path") - end + assert(inside, "Only delete content inside build_path") + end - def test_dont_clean_outside_build_path - path = File.dirname(__FILE__) - cleaner = Roger::Release::Cleaner.new(path) + def test_dont_clean_outside_build_path + path = File.dirname(__FILE__) + cleaner = Roger::Release::Cleaner.new(path) - assert_raise RuntimeError do - cleaner.send :inside_build_path?, path, @base + "/html/formats" + assert_raise RuntimeError do + cleaner.send :inside_build_path?, path, @release.project.path + "html" + end end - end - def test_dont_fail_on_nonexistent_files - path = "bla" - cleaner = Roger::Release::Cleaner.new(path) + def test_dont_fail_on_nonexistent_files + path = "bla" + cleaner = Roger::Release::Cleaner.new(path) - assert( - !cleaner.send(:inside_build_path?, @base + "/html/formats", path), - "Failed on nonexistent directories/files" - ) - end - - protected - - def create_and_assert_directories(dirs) - dirs.each do |dir| - path = @base + "/" + dir - mkdir path unless File.directory?(path) - assert(File.directory?(path)) + assert( + !cleaner.send(:inside_build_path?, @release.project.path + "/html", path), + "Failed on nonexistent directories/files" + ) end end end