Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stray stderr output on machines with GNU which #124

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 10 additions & 3 deletions lib/mjml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def self.check_for_custom_mjml_binary
end

def self.check_for_mjml_package(package_manager, bin_command, binary_path)
pm_bin = `which #{package_manager}`.chomp
return if pm_bin.blank?
stdout, _, status = Open3.capture3("which #{package_manager}")
return unless status.success?

pm_bin = stdout.chomp

stdout, _, status = Open3.capture3("#{pm_bin} #{bin_command}")
return unless status.success?
Expand All @@ -93,11 +95,16 @@ def self.check_for_package_mjml_binary
end

def self.check_for_global_mjml_binary
mjml_bin = `which mjml`.chomp
stdout, _, status = Open3.capture3('which mjml')
return unless status.success?

mjml_bin = stdout.chomp
return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
end

def self.check_for_mrml_binary
return unless Mjml.use_mrml

MRML.present?
rescue NameError
Mjml.mjml_binary_error_string = 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/valid-mjml-binary/empty-path/which
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# simulate GNU which's stderr message when it cannot find something
>&2 echo "I should not show up in test output"

# simulate an empty path by always returning nonzero
exit 1
11 changes: 11 additions & 0 deletions test/mjml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,19 @@ class NotifierMailerTest < ActiveSupport::TestCase

Mjml.valid_mjml_binary = nil
MRML.stubs(:present?).raises(NameError)
Mjml.stubs(:puts) # silence printed error message from test output
assert_nil(Mjml.valid_mjml_binary)
expect(Mjml.mjml_binary_error_string).must_equal 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
end

it 'with nothing on the path, sets valid_mjml_binary to nil' do
old_path = ENV['PATH']
ENV['PATH'] = './test/fixtures/valid-mjml-binary/empty-path/'

Mjml.stubs(:puts) # silence printed error message from test output
assert_nil(Mjml.valid_mjml_binary)
ensure
ENV['PATH'] = old_path
end
end
end
Loading