Class: PreprocessorTest

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

Instance Method Summary collapse

Instance Method Details

#setupObject



4
5
6
7
# File 'lib/sprockets/test/test_preprocessor.rb', line 4

def setup
  @environment  = environment_for_fixtures
  @preprocessor = Sprockets::Preprocessor.new(@environment)
end

#test_double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_falseObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sprockets/test/test_preprocessor.rb', line 15

def test_double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false
  @preprocessor = Sprockets::Preprocessor.new(@environment, :strip_comments => false)
  require_file_for_this_test
  assert_concatenation_contains_line "// This is a double-slash comment that should appear in the resulting output file."
  assert_concatenation_contains_line "/* This is a slash-star comment that should appear in the resulting output file. */"

  assert_concatenation_contains_line "/* This is multiline slash-star comment"
  assert_concatenation_contains_line "*  that should appear in the resulting"
  assert_concatenation_contains_line "*  output file */"

  assert_concatenation_contains_line "This is not a PDoc comment that should appear in the resulting output file."
end

#test_double_slash_comments_that_are_not_requires_should_be_removed_by_defaultObject



9
10
11
12
13
# File 'lib/sprockets/test/test_preprocessor.rb', line 9

def test_double_slash_comments_that_are_not_requires_should_be_removed_by_default
  require_file_for_this_test
  assert_concatenation_does_not_contain_line "// This is a double-slash comment that should not appear in the resulting output file."
  assert_concatenation_contains_line "/* This is a slash-star comment that should not appear in the resulting output file. */"
end

#test_multiline_comments_should_be_removed_by_defaultObject



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

def test_multiline_comments_should_be_removed_by_default
  require_file_for_this_test
  assert_concatenation_does_not_contain_line "/**"
  assert_concatenation_does_not_contain_line " *  This is a PDoc comment"
  assert_concatenation_does_not_contain_line " *  that should appear in the resulting output file."
  assert_concatenation_does_not_contain_line "**/"
end

#test_requiring_a_file_after_it_has_already_been_required_should_do_nothingObject



56
57
58
59
60
61
62
63
64
# File 'lib/sprockets/test/test_preprocessor.rb', line 56

def test_requiring_a_file_after_it_has_already_been_required_should_do_nothing
  require_file_for_this_test
  assert_concatenation_contains "    var before_first_require;\n    var Foo = { };\n    var after_first_require_and_before_second_require;\n    var after_second_require;\n  LINES\nend\n"

#test_requiring_a_file_that_does_not_exist_should_raise_an_errorObject



45
46
47
48
49
# File 'lib/sprockets/test/test_preprocessor.rb', line 45

def test_requiring_a_file_that_does_not_exist_should_raise_an_error
  assert_raises(Sprockets::LoadError) do
    require_file_for_this_test
  end
end

#test_requiring_a_single_file_should_replace_the_require_comment_with_the_file_contentsObject



36
37
38
39
40
41
42
43
# File 'lib/sprockets/test/test_preprocessor.rb', line 36

def test_requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents
  require_file_for_this_test
  assert_concatenation_contains "    var before_require;\n    var Foo = { };\n    var after_require;\n  LINES\nend\n"

#test_requiring_the_current_file_should_do_nothingObject



51
52
53
54
# File 'lib/sprockets/test/test_preprocessor.rb', line 51

def test_requiring_the_current_file_should_do_nothing
  require_file_for_this_test
  assert_equal "", output_text
end