File: test_uri_tar.rb

package info (click to toggle)
ruby-sprockets 4.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,964 kB
  • sloc: ruby: 13,014; javascript: 157; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 2,989 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
require 'sprockets_test'

class TestURITar < Sprockets::TestCase

  def setup
    @fake_env = Class.new do
      include Sprockets::PathUtils
      attr_accessor :root
    end.new
  end

  test "works with nix" do
    skip "Only runs on nix" if File::ALT_SEPARATOR

    uri = "/Sites/sprockets/test/fixtures/paths/application.css?type=text/css"
    @fake_env.root = "/Different/path"
    tar = Sprockets::URITar.new(uri, @fake_env)
    assert_equal uri, tar.expand
    assert_equal uri, tar.compress
    assert_equal uri, tar.compressed_path

    uri = "file:///Sites/sprockets/test/fixtures/paths/application.css?type=text/css"
    @fake_env.root = "/Sites/sprockets"
    tar = Sprockets::URITar.new(uri, @fake_env)
    assert_equal uri, tar.expand
    assert_equal Sprockets::URITar.new(tar.compress, @fake_env).expand, uri
    assert_equal "test/fixtures/paths/application.css?type=text/css", tar.compressed_path
    assert_equal "file://test/fixtures/paths/application.css?type=text/css", tar.compress
    assert_equal Sprockets::URITar.new(tar.compress, @fake_env).compress, tar.compress
    assert_equal Sprockets::URITar.new(tar.expand, @fake_env).compress, tar.compress

    uri = "/Sites/sprockets/test/fixtures/paths/application.css?type=text/css"
    @fake_env.root = "/Sites/sprockets"
    tar = Sprockets::URITar.new(uri, @fake_env)
    assert_equal uri, tar.expand
    assert_equal "test/fixtures/paths/application.css?type=text/css", tar.compressed_path
    assert_equal "test/fixtures/paths/application.css?type=text/css", tar.compress
  end

  test "works with windows" do
    skip "Only runs on windows" unless File::ALT_SEPARATOR

    uri = "C:/Sites/sprockets/test/fixtures/paths/application.css?type=text/css"
    @fake_env.root = "C:/Different/path"
    tar = Sprockets::URITar.new(uri, @fake_env)
    assert_equal uri, tar.expand
    assert_equal uri, tar.compress
    assert_equal uri, tar.compressed_path

    uri = "file:///C:/Sites/sprockets/test/fixtures/paths/application.css?type=text/css"
    @fake_env.root = "C:/Sites/sprockets"
    tar = Sprockets::URITar.new(uri, @fake_env)
    assert_equal uri, tar.expand
    assert_equal Sprockets::URITar.new(tar.compress, @fake_env).expand, uri
    assert_equal "test/fixtures/paths/application.css?type=text/css", tar.compressed_path
    assert_equal "file://test/fixtures/paths/application.css?type=text/css", tar.compress
    assert_equal Sprockets::URITar.new(tar.compress, @fake_env).compress, tar.compress
    assert_equal Sprockets::URITar.new(tar.expand, @fake_env).compress, tar.compress

    uri = "C:/Sites/sprockets/test/fixtures/paths/application.css?type=text/css"
    @fake_env.root = "C:/Sites/sprockets"
    tar = Sprockets::URITar.new(uri, @fake_env)
    assert_equal uri, tar.expand
    assert_equal "test/fixtures/paths/application.css?type=text/css", tar.compressed_path
    assert_equal "test/fixtures/paths/application.css?type=text/css", tar.compress
  end
end