Skip to content

Commit

Permalink
Raise better error when mjml binary is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed May 15, 2019
1 parent bb6b78a commit 9a0b01a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mjml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# MJML library for ruby
module MJML
class BinaryNotFound < StandardError; end

# Constants
MIME_TYPE = 'text/mjml'.freeze
EXTENSION = '.mjml'.freeze
Expand Down Expand Up @@ -62,6 +64,8 @@ def self.extract_executable_version
end

match.nil? ? nil : match[1]
rescue Errno::ENOENT => _e
raise BinaryNotFound, 'mjml binary not found'
end

def self.logger
Expand Down
20 changes: 20 additions & 0 deletions spec/mjml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative 'spec_helper'
require 'mjml'

describe 'MJML' do
describe '#extract_executable_version' do
it 'should return the version if mjml is installed' do
MJML.extract_executable_version.must_be_instance_of String
end

it 'should return false for unknown feature' do
_bin_path = MJML.config.bin_path
MJML.config.bin_path = '/usr/bin/env mjml-not-installed'

error = -> { MJML.extract_executable_version }.must_raise MJML::BinaryNotFound
error.message.must_equal 'mjml binary not found'

MJML.config.bin_path = _bin_path
end
end
end

0 comments on commit 9a0b01a

Please sign in to comment.