[rspec-users] Tests for my gem cannot find classes in gems lib directory ..

Anthony Broad-Crawford anthony at within3.com
Tue Apr 21 20:43:59 EDT 2009

I am writing a gem and using RSpec to drive my development.  However,  
whenever I describe a class within the gems lib I get an uninitialized  
constant error.  I am placing my folder structure, spec.rake and first  
spec below.  I feel I must be missing something obvious.   
Additionally, I did output the value of f in lib inclusion code and it  
is traversing the lib folder correctly and I can instantiate the class  
in my rake.spec.  Thanks for your time.

	+ lib
		- foo_spec.rb
		- spec.rake

my spec rake

require 'rubygems'
require 'spec'
require 'spec/rake/spectask'

Dir[File.expand_path("lib/**/*.rb")].each do |f|
   require f

Spec::Rake::SpecTask.new do |t|
   t.spec_files = FileList['spec/*_spec.rb']

and my spec

describe Foo do

The error I get

./spec/Foo_spec.rb:1: uninitialized constant Foo (NameError)
	from /Library/Ruby/Gems/1.8/gems/rspec-1.2.4/lib/spec/runner/ 
example_group_runner.rb:15:in `load'
	from /Library/Ruby/Gems/1.8/gems/rspec-1.2.4/lib/spec/runner/ 
example_group_runner.rb:15:in `load_files'
	from /Library/Ruby/Gems/1.8/gems/rspec-1.2.4/lib/spec/runner/ 
example_group_runner.rb:14:in `each'
	from /Library/Ruby/Gems/1.8/gems/rspec-1.2.4/lib/spec/runner/ 
example_group_runner.rb:14:in `load_files'
	from /Library/Ruby/Gems/1.8/gems/rspec-1.2.4/lib/spec/runner/ 
options.rb:99:in `run_examples'
	from /Library/Ruby/Gems/1.8/gems/rspec-1.2.4/lib/spec/runner/ 
command_line.rb:9:in `run'
	from /Library/Ruby/Gems/1.8/gems/rspec-1.2.4/bin/spec:4
rake aborted!
Command /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ 
ruby -I"/Library/Ruby/Gems/1.8/gems/rspec-1.2.4/lib"  "/Library/Ruby/ 
Gems/1.8/gems/rspec-1.2.4/bin/spec" "spec/foo_spec.rb"  failed

Thanks again!

More information about the rspec-users mailing list