Rake spec not using the rails environment

rakerspecrubyruby-on-rails

I'm attempting to use rspec in a rails project I've just upgraded to rails 2.3.2. I've installed rspec 1.2.6 and rspec-rails 1.2.6 as plugins in the app.

My problem is the specs don't have access to my app classes or any of the rails standard libraries.

First I had to specify the model class I want to test by using the full path from RAILS_ROOT but now as it loads the class I get the following

/app/models/person.rb:1: uninitialized constant ActiveRecord (NameError)
        from ./spec/models/person_spec.rb:1:in `require'
    from ./spec/models/person_spec.rb:1
    from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:15:in `load'
    from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:15:in `load_files'
    from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in `each'
    from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in `load_files'
    from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/options.rb:99:in `run_examples'
    from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/command_line.rb:9:in `run'
    from /Users/law/Projects/roster/vendor/plugins/rspec/bin/spec:4
rake aborted!

I am launching rspec by calling rake spec from the root of the application.

Any ideas on what might be missing in this situation?

Best Answer

you need indeed include the spec_helper.rb in every spec file you write....

You can run individual specs that way:

$ spec specs/models/person_spec.rb

instead of always running the whole spec suite