Amit Kulkarni
2009-Jun-11 16:50 UTC
[rspec-users] 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: amit at test.com kiran: id : 7 login: kiran email: kiran at test.com I dont know what is wrong. Please suggest :-) -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2009-Jun-11 16:58 UTC
[rspec-users] Fixtures are not loaded while running controller spec
On Thu, Jun 11, 2009 at 11:50 AM, Amit Kulkarni<lists at ruby-forum.com> wrote:> 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: amit at test.com > > kiran: > ?id : 7 > ?login: kiran > ?email: kiran at test.com > > > I dont know what is wrong. > Please suggest :-)Make sure that the fixtures are in the same place that is declared in spec/spec_helper.rb.
Pat Maddox
2009-Jun-12 00:09 UTC
[rspec-users] Fixtures are not loaded while running controller spec
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 > ?endWhy 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
Amit Kulkarni
2009-Jun-12 06:10 UTC
[rspec-users] Fixtures are not loaded while running controller spec
David Chelimsky wrote:> On Thu, Jun 11, 2009 at 11:50 AM, Amit Kulkarni<lists at ruby-forum.com> > wrote: >> ? require File.expand_path(File.dirname(__FILE__) + ''/../spec_helper'') >> ? ?if @user >> ?id: 1 >> amit: >> I dont know what is wrong. >> Please suggest :-) > > 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. -- Posted via http://www.ruby-forum.com/.
Amit Kulkarni
2009-Jun-12 06:33 UTC
[rspec-users] Fixtures are not loaded while running controller spec
> 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 :) > > PatThanks a lot Pat.It worked. And fixtures were also loaded successfully. -- Posted via http://www.ruby-forum.com/.