Class: SecretaryTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/sprockets/test/test_secretary.rb

Instance Method Summary collapse

Instance Method Details

#test_install_assets_into_empty_directoryObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sprockets/test/test_secretary.rb', line 35

def test_install_assets_into_empty_directory
  with_temporary_directory do |temp|
    secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
    secretary.add_source_file("src/script_with_assets.js")

    assert_equal [], Dir[File.join(temp, "**", "*")]
    secretary.install_assets
    assert_equal paths_relative_to(temp, 
      "images", "images/script_with_assets", "images/script_with_assets/one.png", 
      "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
      Dir[File.join(temp, "**", "*")].sort
  end
end

#test_install_assets_into_nonexistent_directoryObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sprockets/test/test_secretary.rb', line 49

def test_install_assets_into_nonexistent_directory
  with_temporary_directory do |temp|
    temp = File.join(temp, "assets")
    secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
    secretary.add_source_file("src/script_with_assets.js")

    assert_equal [], Dir[File.join(temp, "**", "*")]
    secretary.install_assets
    assert_equal paths_relative_to(temp, 
      "images", "images/script_with_assets", "images/script_with_assets/one.png", 
      "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
      Dir[File.join(temp, "**", "*")].sort
  end
end

#test_install_assets_into_subdirectories_that_already_existObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sprockets/test/test_secretary.rb', line 64

def test_install_assets_into_subdirectories_that_already_exist
  with_temporary_directory do |temp|
    secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
    secretary.add_source_file("src/script_with_assets.js")

    FileUtils.mkdir_p(File.join(temp, "images", "script_with_assets"))
    assert_equal paths_relative_to(temp, "images", "images/script_with_assets"), Dir[File.join(temp, "**", "*")]
    secretary.install_assets
    assert_equal paths_relative_to(temp, 
      "images", "images/script_with_assets", "images/script_with_assets/one.png", 
      "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
      Dir[File.join(temp, "**", "*")].sort
  end
end

#test_load_locations_are_expanded_when_expand_paths_is_trueObject



12
13
14
15
16
17
18
# File 'lib/sprockets/test/test_secretary.rb', line 12

def test_load_locations_are_expanded_when_expand_paths_is_true
  secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
  secretary.add_load_location("src/**/", :expand_paths => true)
  
  assert_equal [File.join(FIXTURES_PATH, "src", "foo"), File.join(FIXTURES_PATH, "src"), FIXTURES_PATH],
               secretary.environment.load_path.map { |pathname| pathname.absolute_location }
end

#test_load_locations_are_not_expanded_when_expand_paths_is_falseObject



4
5
6
7
8
9
10
# File 'lib/sprockets/test/test_secretary.rb', line 4

def test_load_locations_are_not_expanded_when_expand_paths_is_false
  secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
  secretary.add_load_location("src/**/", :expand_paths => false)
  
  assert_equal [File.join(FIXTURES_PATH, "src/**"), FIXTURES_PATH], 
               secretary.environment.load_path.map { |pathname| pathname.absolute_location }
end

#test_secretary_passes_strip_comments_option_through_to_preprocessorObject



79
80
81
82
83
# File 'lib/sprockets/test/test_secretary.rb', line 79

def test_secretary_passes_strip_comments_option_through_to_preprocessor
  secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :strip_comments => false)
  secretary.add_source_file("src/script_with_comments.js")
  assert_equal content_of_fixture("src/script_with_comments.js"), secretary.concatenation.to_s
end

#test_source_files_are_expanded_when_expand_paths_is_trueObject



27
28
29
30
31
32
33
# File 'lib/sprockets/test/test_secretary.rb', line 27

def test_source_files_are_expanded_when_expand_paths_is_true
  secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
  secretary.add_source_file("src/f*.js", :expand_paths => true)
  
  assert_equal [File.join(FIXTURES_PATH, "src", "foo.js")],
               secretary.preprocessor.source_files.map { |source_file| source_file.pathname.absolute_location }
end

#test_source_files_are_not_expanded_when_expand_paths_is_falseObject



20
21
22
23
24
25
# File 'lib/sprockets/test/test_secretary.rb', line 20

def test_source_files_are_not_expanded_when_expand_paths_is_false
  secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
  assert_raises(Sprockets::LoadError) do
    secretary.add_source_file("src/f*.js", :expand_paths => false)
  end
end