Skip to content

Commit

Permalink
test: assert on the existence of Gem::Platform.match_gem?
Browse files Browse the repository at this point in the history
to avoid stubbing a method that doesn't exist
  • Loading branch information
flavorjones committed Oct 27, 2023
1 parent 3f34537 commit bcbd836
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit bcbd836

Please sign in to comment.