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

Raise better error when mjml binary is not found #13

Merged
merged 1 commit into from
May 15, 2019
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
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 for path '#{config.bin_path}'"
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_match(/^mjml binary not found/)

MJML.config.bin_path = bin_path
end
end
end