Commits

Michael Granger committed 39f3367

Make wordnet re-use the error it raised when it was required if it couldn't be loaded

Comments (0)

Files changed (2)

lib/linguistics/en/wordnet.rb

 module Linguistics::EN::WordNet
 
 	@has_wordnet  = false
-	@error		  = nil
+	@wn_error     = nil
 	@lexicon      = nil
 
 	# Load WordNet if possible, saving the error that occurs if anything goes wrong.
 		require 'wordnet'
 		@has_wordnet = true
 	rescue LoadError => err
-		@error = err
+		@wn_error = err
 	end
 
 
 
 		### If #has_wordnet? returns +false+, this can be called to fetch the
 		### exception which was raised when WordNet was loaded.
-		def error ; @error; end
+		def wordnet_error ; @wn_error; end
 
 	end # module SingletonMethods
 	extend SingletonMethods
 	### The instance of the WordNet::Lexicon used for all Linguistics WordNet
 	### functions.
 	def self::lexicon
-		if @error
-			raise NotImplementedError,
-				"WordNet functions are not loaded: %s" %
-				@error.message
-		end
-
+		raise self.wordnet_error unless self.has_wordnet?
 		@lexicon ||= WordNet::Lexicon::new
 	end
 

spec/linguistics/en/wordnet_spec.rb

 				@had_wordnet = true
 				error = LoadError.new( "no such file to load -- wordnet" )
 				Linguistics::EN::WordNet.instance_variable_set( :@has_wordnet, false )
-				Linguistics::EN::WordNet.instance_variable_set( :@error, error )
+				Linguistics::EN::WordNet.instance_variable_set( :@wn_error, error )
 			end
 		end
 
 		after( :all ) do
 			if @had_wordnet
 				Linguistics::EN::WordNet.instance_variable_set( :@has_wordnet, true )
-				Linguistics::EN::WordNet.instance_variable_set( :@error, nil )
+				Linguistics::EN::WordNet.instance_variable_set( :@wn_error, nil )
 			end
 		end
 
-		it "raises an NotImplementedError when you try to use wordnet functionality" do
+		it "raises the appropriate LoadError when you try to use wordnet functionality" do
 			expect {
 				"persimmon".en.synset
-			}.to raise_error( NotImplementedError, /not loaded/i )
+			}.to raise_error( LoadError, %r{wordnet}i )
 		end
 
 	end