polyglot 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.2.7 2009-08-17
2
+
3
+ * 1 minor fix:
4
+ * Fix Polyglot catching LoadErrors not raised in Polyglot.find and re-raising the
5
+ wrong message.
6
+
1
7
  == 0.2.6 2009-06-21
2
8
 
3
9
  * 1 significant fix:
@@ -2,7 +2,7 @@ module Polyglot #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/polyglot.rb CHANGED
@@ -4,6 +4,8 @@ require 'pathname'
4
4
  module Polyglot
5
5
  @registrations ||= {} # Guard against reloading
6
6
  @loaded ||= {}
7
+
8
+ class PolyglotLoadError < LoadError; end
7
9
 
8
10
  def self.register(extension, klass)
9
11
  extension = [extension] unless Enumerable === extension
@@ -41,7 +43,7 @@ module Polyglot
41
43
  if defined?(MissingSourceFile)
42
44
  raise MissingSourceFile.new(msg, file)
43
45
  else
44
- raise LoadError.new(msg)
46
+ raise PolyglotLoadError.new(msg)
45
47
  end
46
48
  end
47
49
  end
@@ -56,7 +58,7 @@ module Kernel
56
58
  rescue LoadError => load_error
57
59
  begin
58
60
  Polyglot.load(*a, &b)
59
- rescue LoadError
61
+ rescue Polyglot::PolyglotLoadError
60
62
  # Raise the original exception, possibly a MissingSourceFile with a path
61
63
  raise load_error
62
64
  end
@@ -2,21 +2,43 @@ require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestPolyglot < Test::Unit::TestCase
4
4
  TEST_FILE = 'test_file.stub'
5
+ TEST_REQUIRES_FILE = 'test_requires_file.eval'
5
6
  class StubLoader
6
7
  def self.load(*args); end
7
8
  end
9
+ class EvalLoader
10
+ def self.load(file)
11
+ File.open(file) do |source_file|
12
+ source = source_file.read
13
+ eval source
14
+ end
15
+ end
16
+ end
8
17
 
9
18
  def setup
10
19
  Polyglot.register('stub', StubLoader)
11
20
  File.open(TEST_FILE, 'w') { |f| f.puts "Test data" }
21
+ Polyglot.register('eval', EvalLoader)
22
+ File.open(TEST_REQUIRES_FILE, 'w') { |f| f.puts "require 'nonexistent_file'" }
12
23
  end
13
24
 
14
25
  def teardown
15
26
  File.delete(TEST_FILE)
27
+ File.delete(TEST_REQUIRES_FILE)
16
28
  end
17
29
 
18
30
  def test_load_by_absolute_path
19
31
  full_path = File.expand_path(TEST_FILE.sub(/.stub$/, ''))
20
32
  assert_nothing_raised { require full_path }
21
33
  end
34
+
35
+ def test_load_error
36
+ exception = assert_raise(LoadError) { require "nonexistent_file" }
37
+ assert_match(/nonexistent_file/, exception.message)
38
+ end
39
+
40
+ def test_load_error_inside_poly_file
41
+ exception = assert_raise(LoadError) { require TEST_REQUIRES_FILE.sub(/.eval$/, '') }
42
+ assert_match(/nonexistent_file/, exception.message)
43
+ end
22
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyglot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-21 00:00:00 +10:00
12
+ date: 2009-08-17 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.8.0
23
+ version: 2.3.2
24
24
  version:
25
25
  description: Allows custom language loaders for specified file extensions to be hooked into require
26
26
  email: cjheath@rubyforge.org
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements: []
67
67
 
68
68
  rubyforge_project: polyglot
69
- rubygems_version: 1.3.4
69
+ rubygems_version: 1.3.5
70
70
  signing_key:
71
71
  specification_version: 3
72
72
  summary: Allows custom language loaders for specified file extensions to be hooked into require