Rspec-rails doesn't seem to find my models

Posted by sa125 on Stack Overflow See other posts from Stack Overflow or by sa125
Published on 2010-04-26T07:23:39Z Indexed on 2010/04/26 7:53 UTC
Read the original article Hit count: 421

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rspec