Linguistics / spec / linguistics / en / wordnet_spec.rb

The default branch has multiple heads

#!/usr/bin/env spec -cfs

BEGIN {
	require 'pathname'
	basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent

	libdir = basedir + "lib"

	$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
}

require 'rspec'
require 'spec/lib/helpers'

require 'linguistics'
require 'linguistics/en'
require 'linguistics/en/wordnet'


describe Linguistics::EN::WordNet do

	before( :all ) do
		setup_logging()
		Linguistics.use( :en )
	end

	after( :all ) do
		reset_logging()
	end


	it "adds EN::WordNet to the list of English language modules" do
		Linguistics::EN::MODULES.include?( Linguistics::EN::WordNet )
	end


	describe "on a system that has the 'wordnet' library installed" do

		before( :each ) do
			pending "installation of the wordnet library" unless
				Linguistics::EN.has_wordnet?
		end

		it "can create a WordNet::Synset from a word" do
			"jackal".en.synset.should be_a( WordNet::Synset )
		end

		it "can load all synsets for a word" do
			result = "appear".en.synsets
			result.should have( 7 ).members
			result.should include( WordNet::Synset[200422090] )
		end

	end


	describe "on a system that doesn't have the 'wordnet' library" do
		before( :all ) do
			# If the system *does* have wordnet support, pretend it doesn't.
			if Linguistics::EN.has_wordnet?
				@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 )
			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 )
			end
		end

		it "raises an NotImplementedError when you try to use wordnet functionality" do
			expect {
				"persimmon".en.synset
			}.to raise_error( NotImplementedError, /not loaded/i )
		end

	end

end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.