2
2
require "minitest/mock"
3
3
4
4
class Tailwindcss ::CommandsTest < ActiveSupport ::TestCase
5
- test ".platform is a string containing just the cpu and os (not the version)" do
6
- expected = "#{ Gem ::Platform . local . cpu } -#{ Gem ::Platform . local . os } "
7
- assert_equal ( expected , Tailwindcss ::Commands . platform )
5
+ setup do
6
+ @orig_path = ENV [ "PATH" ]
7
+ ENV [ "PATH" ] = ""
8
+ end
9
+
10
+ teardown do
11
+ ENV [ "PATH" ] = @orig_path
8
12
end
9
13
10
14
def mock_exe_directory ( platform )
@@ -18,6 +22,23 @@ def mock_exe_directory(platform)
18
22
end
19
23
end
20
24
25
+ def mock_path_binary
26
+ Dir . mktmpdir do |dir |
27
+ orig_path = ENV [ "PATH" ]
28
+ ENV [ "PATH" ] = [ dir , ENV [ "PATH" ] ] . join ( File ::PATH_SEPARATOR )
29
+ FileUtils . touch ( File . join ( dir , "tailwindcss" ) )
30
+ FileUtils . chmod ( "ugo+x" , File . join ( dir , "tailwindcss" ) )
31
+ yield ( dir )
32
+ ensure
33
+ ENV [ "PATH" ] = orig_path
34
+ end
35
+ end
36
+
37
+ test ".platform is a string containing just the cpu and os (not the version)" do
38
+ expected = "#{ Gem ::Platform . local . cpu } -#{ Gem ::Platform . local . os } "
39
+ assert_equal ( expected , Tailwindcss ::Commands . platform )
40
+ end
41
+
21
42
test ".executable returns the absolute path to the binary" do
22
43
mock_exe_directory ( "sparc-solaris2.8" ) do |dir , executable |
23
44
expected = File . expand_path ( File . join ( dir , "sparc-solaris2.8" , "tailwindcss" ) )
@@ -26,6 +47,23 @@ def mock_exe_directory(platform)
26
47
end
27
48
end
28
49
50
+ test "when a packaged exe is not found, .executable returns the absolute path to `tailwindcss` that is in PATH" do
51
+ mock_path_binary do |installed |
52
+ expected = File . join ( installed , "tailwindcss" )
53
+ assert_equal ( expected , Tailwindcss ::Commands . executable ( exe_path : "/blurgh" ) )
54
+ end
55
+ end
56
+
57
+ test "when a packaged exe is found, .executable ignores what's in PATH" do
58
+ mock_exe_directory ( "sparc-solaris2.8" ) do |dir , executable |
59
+ mock_path_binary do |installed |
60
+ expected = File . expand_path ( File . join ( dir , "sparc-solaris2.8" , "tailwindcss" ) )
61
+ assert_equal ( expected , executable , "assert on setup" )
62
+ assert_equal ( expected , Tailwindcss ::Commands . executable ( exe_path : dir ) )
63
+ end
64
+ end
65
+ end
66
+
29
67
test ".executable raises UnsupportedPlatformException when we're not on a supported platform" do
30
68
Gem ::Platform . stub ( :match , false ) do # nothing is supported
31
69
assert_raises ( Tailwindcss ::Commands ::UnsupportedPlatformException ) do
0 commit comments