Rspec-rails doesn't seem to find my models
- by sa125
Hi - I'm trying out rspec, and immediately hit a wall when it doesn't seem to load db records I know exist. Here's my fairly simple spec (no tests yet).
require File.expand_path(File.dirname(__FILE__) + '../spec_helper')
describe SomeModel do
before :each do
@user1 = User.find(1)
@user2 = User.find(2)
end
it "should do something fancy"
end
I get an ActiveRecord::RecordNotFound exception, saying it couldn't find User w/ ID=1 or ID=2, which I know for a fact exist. I set both test and development databases to point to the same schema in database.yml, so this shouldn't be database mixup. I also ran script/generate rspec after installing the gems (rspec, rspec-rails), and gem.config both environment.rb and test.rb. Any idea what I'm missing? thanks.
EDIT
Seems I was running the tests with rake spec:models, which emptied the db and thus no records were found. When I used % spec spec/models/some_model_spec.rb, everything worked as expected.