[rspec-users] Fixtures are not loaded while running controller spec
Pat Maddox
pat.maddox at gmail.com
Thu Jun 11 20:09:57 EDT 2009
On Thu, Jun 11, 2009 at 9:50 AM, Amit Kulkarni<lists at ruby-forum.com> wrote:
> describe BbPostsController do
> context "test" do
> fixtures :bb_posts, :users
> @user = User.find_by_login("amit")
> if @user
> it "should create post" do
> post = create_post
> post.should be_valid
> end
> end
> end
Why do you have that if there? That's gotta be screwing you up. So
the way Rails tests work, the fixtures don't get loaded until an
example is run. In your code, you're trying to find a user that
probably doesn't exist due to there being no fixtures loaded yet. So
why are you doing that find and subsequent if? Try changing it to:
describe BbPostsController do
context "test" do
fixtures :bb_posts, :users
it "should create post" do
User.find_by_login("amit").should_not be_nil
post = create_post
post.should be_valid
end
end
end
(that's an odd spec but let's try to get your fixtures loading first :)
Pat
More information about the rspec-users
mailing list