Skip to content

Commit ea96f2d

Browse files
committed
Issue #118. Better error when trying to generate MHTML without a base_url specified.
1 parent d706038 commit ea96f2d

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

lib/jammit.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ module Jammit
3434
# requested by a browser -- rendering a 404.
3535
class PackageNotFound < NameError; end
3636

37-
# Jammit raises a ConfigurationNotFound exception when you try to load the
38-
# configuration of an assets.yml file that doesn't exist.
39-
class ConfigurationNotFound < NameError; end
37+
# Jammit raises a MissingConfiguration exception when you try to load the
38+
# configuration of an assets.yml file that doesn't exist, or are missing
39+
# a piece of required configuration.
40+
class MissingConfiguration < NameError; end
4041

4142
# Jammit raises an OutputNotWritable exception if the output directory for
4243
# cached packages is locked.
@@ -64,7 +65,7 @@ class << self
6465
def self.load_configuration(config_path, soft=false)
6566
exists = config_path && File.exists?(config_path)
6667
return false if soft && !exists
67-
raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless exists
68+
raise MissingConfiguration, "could not find the \"#{config_path}\" configuration file" unless exists
6869
conf = YAML.load(ERB.new(File.read(config_path)).result)
6970

7071
# Optionally overwrite configuration based on the environment.

lib/jammit/packager.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def precache_all(output_dir=nil, base_url=nil)
4343
cache(p, 'css', pack_stylesheets(p), output_dir)
4444
if Jammit.embed_assets
4545
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri)
46-
if Jammit.mhtml_enabled && base_url
46+
if Jammit.mhtml_enabled
47+
raise MissingConfiguration, "A --base-url option is required in order to generate MHTML." unless base_url
4748
mtime = latest_mtime package_for(p, :css)[:paths]
4849
asset_url = "#{base_url}#{Jammit.asset_url(p, :css, :mhtml, mtime)}"
4950
cache(p, 'css', pack_stylesheets(p, :mhtml, asset_url), output_dir, :mhtml, mtime)

test/unit/test_configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def teardown
1212
end
1313

1414
def test_loading_a_nonexistent_file
15-
assert_raises(ConfigurationNotFound) do
15+
assert_raises(MissingConfiguration) do
1616
Jammit.load_configuration('nonexistent/assets.yml')
1717
end
1818
end

test/unit/test_packager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_exceptions_for_unwritable_directories
113113

114114
def test_package_helper
115115
FileUtils.rm_rf("test/public/assets/*")
116-
Jammit.package! :config_file => "test/config/assets.yml"
116+
Jammit.package! :config_file => "test/config/assets.yml", :base_url => "http://example.com/"
117117
assert File.exists?("test/public/assets/js_test.js")
118118
assert File.exists?("test/public/assets/css_test.css")
119119
FileUtils.rm_rf("test/public/assets")

0 commit comments

Comments
 (0)