Skip to content
Browse files

Issue #118. Better error when trying to generate MHTML without a base…

…_url specified.
  • Loading branch information...
1 parent d706038 commit ea96f2d3d5c41d3790ddd60496197de98d81691a @jashkenas jashkenas committed May 25, 2011
Showing with 9 additions and 7 deletions.
  1. +5 −4 lib/jammit.rb
  2. +2 −1 lib/jammit/packager.rb
  3. +1 −1 test/unit/test_configuration.rb
  4. +1 −1 test/unit/test_packager.rb
View
9 lib/jammit.rb
@@ -34,9 +34,10 @@ module Jammit
# requested by a browser -- rendering a 404.
class PackageNotFound < NameError; end
- # Jammit raises a ConfigurationNotFound exception when you try to load the
- # configuration of an assets.yml file that doesn't exist.
- class ConfigurationNotFound < NameError; end
+ # Jammit raises a MissingConfiguration exception when you try to load the
+ # configuration of an assets.yml file that doesn't exist, or are missing
+ # a piece of required configuration.
+ class MissingConfiguration < NameError; end
# Jammit raises an OutputNotWritable exception if the output directory for
# cached packages is locked.
@@ -64,7 +65,7 @@ class << self
def self.load_configuration(config_path, soft=false)
exists = config_path && File.exists?(config_path)
return false if soft && !exists
- raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless exists
+ raise MissingConfiguration, "could not find the \"#{config_path}\" configuration file" unless exists
conf = YAML.load(ERB.new(File.read(config_path)).result)
# Optionally overwrite configuration based on the environment.
View
3 lib/jammit/packager.rb
@@ -43,7 +43,8 @@ def precache_all(output_dir=nil, base_url=nil)
cache(p, 'css', pack_stylesheets(p), output_dir)
if Jammit.embed_assets
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri)
- if Jammit.mhtml_enabled && base_url
+ if Jammit.mhtml_enabled
+ raise MissingConfiguration, "A --base-url option is required in order to generate MHTML." unless base_url
mtime = latest_mtime package_for(p, :css)[:paths]
asset_url = "#{base_url}#{Jammit.asset_url(p, :css, :mhtml, mtime)}"
cache(p, 'css', pack_stylesheets(p, :mhtml, asset_url), output_dir, :mhtml, mtime)
View
2 test/unit/test_configuration.rb
@@ -12,7 +12,7 @@ def teardown
end
def test_loading_a_nonexistent_file
- assert_raises(ConfigurationNotFound) do
+ assert_raises(MissingConfiguration) do
Jammit.load_configuration('nonexistent/assets.yml')
end
end
View
2 test/unit/test_packager.rb
@@ -113,7 +113,7 @@ def test_exceptions_for_unwritable_directories
def test_package_helper
FileUtils.rm_rf("test/public/assets/*")
- Jammit.package! :config_file => "test/config/assets.yml"
+ Jammit.package! :config_file => "test/config/assets.yml", :base_url => "http://example.com/"
assert File.exists?("test/public/assets/js_test.js")
assert File.exists?("test/public/assets/css_test.css")
FileUtils.rm_rf("test/public/assets")

0 comments on commit ea96f2d

Please sign in to comment.
Something went wrong with that request. Please try again.