Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: assert on the existence of Gem::Platform.match_gem?
to avoid stubbing a method that doesn't exist
  • Loading branch information
flavorjones committed Oct 27, 2023
commit bcbd8360c8d9ff2df88f2396eb9bfa985a6d877d
13 changes: 10 additions & 3 deletions test/lib/tailwindcss/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ def mock_exe_directory(platform)
FileUtils.mkdir(File.join(dir, platform))
path = File.join(dir, platform, "tailwindcss")
FileUtils.touch(path)
Gem::Platform.stub(:match_gem?, true) do
stub_gem_platform_match_gem(true) do
yield(dir, path)
end
end
end

def stub_gem_platform_match_gem(value)
assert_respond_to(Gem::Platform, :match_gem?)
Gem::Platform.stub(:match_gem?, value) do
yield
end
end

def mock_local_tailwindcss_install
Dir.mktmpdir do |dir|
path = File.join(dir, "tailwindcss")
Expand All @@ -35,7 +42,7 @@ def mock_local_tailwindcss_install
end

test ".executable raises UnsupportedPlatformException when we're not on a supported platform" do
Gem::Platform.stub(:match_gem?, false) do # nothing is supported
stub_gem_platform_match_gem(false) do # nothing is supported
assert_raises(Tailwindcss::Commands::UnsupportedPlatformException) do
Tailwindcss::Commands.executable
end
Expand Down Expand Up @@ -66,7 +73,7 @@ def mock_local_tailwindcss_install
end

test ".executable returns the executable in TAILWINDCSS_INSTALL_DIR when we're not on a supported platform" do
Gem::Platform.stub(:match_gem?, false) do # nothing is supported
stub_gem_platform_match_gem(false) do # nothing is supported
mock_local_tailwindcss_install do |local_install_dir, expected|
result = nil
begin
Expand Down