Fixtures are not loaded while running controller spec

Hi,

I am running controller spec and it gives me result as 0 examples, 0
failures.

I checked into the database and i saw that fixtures are not loaded.

Following are the details of my controller file.

require File.expand_path(File.dirname(FILE) + ‘/…/spec_helper’)
def valid_bb_post_attributes
{
:body => “test description”,
:title => “test”
}
end
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

My bb_posts.ml file contains

bb_post1:
id: 1
body: body_description
title: test

bb_post2:
id: 2
body: aasasaskajs
title: wwwww

Similarly my users.yml contains

amit:
id: 6
login: amit
email: [email protected]

kiran:
id : 7
login: kiran
email: [email protected]

I dont know what is wrong.
Please suggest :slight_smile:

On Thu, Jun 11, 2009 at 11:50 AM, Amit K.[email protected]
wrote:

require File.expand_path(File.dirname(FILE) + ‘/…/spec_helper’)
if @user
id: 1
amit:
I dont know what is wrong.
Please suggest :slight_smile:

Make sure that the fixtures are in the same place that is declared in
spec/spec_helper.rb.

On Thu, Jun 11, 2009 at 9:50 AM, Amit K.[email protected]
wrote:

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 :slight_smile:

Pat

David C. wrote:

On Thu, Jun 11, 2009 at 11:50 AM, Amit K.[email protected]
wrote:

� require File.expand_path(File.dirname(FILE) + ‘/…/spec_helper’)
� �if @user
�id: 1
amit:
I dont know what is wrong.
Please suggest :slight_smile:

Make sure that the fixtures are in the same place that is declared in
spec/spec_helper.rb.

My fixtures are under spec/fixtures directory.

Earlier it were working fine.But suddenly i dont know what went wrong.
Also i checked that if i comment fixtures line then the specs are
running fine.

Again when i uncomment the fixtures line then it is not working and
fixtures are not getting loaded.

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 :slight_smile:

Pat

Thanks a lot Pat.It worked.
And fixtures were also loaded successfully.