Heinz Strunk
2011-Oct-15 16:17 UTC
Cannot run server/rake/spork/rspec or anything due to some failed tests
Hey, I ran into a very weird problem and after trying to solve it for like 3 hours now and Google not willing to help me I have to ask you guys. I''m currently writing some Spec tests which fail because of some missing seed data. So rspec spec/ fails with: /Users/pbartels/Sites/brothelking/app/models/character.rb:175:in `create_fund'': Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id (RuntimeError) Well, fine I said so I''ll just run rake db:seed RAILS_ENV=test to seed the database: rake aborted! Validation failed: Name has already been taken ... /Users/pbartels/Sites/ror_project/spec/factories/reports.rb:132:in `block in <top (required)>'' ... What the heck''s got rake to do in the spec directory? I get the exact same error when I start spork or rails s When I run RAILS_ENV=test rake db:fixtures:load I also get "Called id for nil..." which doesn''t make sense to me? In conclusion: Whatever I start/run it all fails inside some spec file and I have absolutely no idea why everything is going into the spec folder anyway?! I don''t even know where to start pasting files here so if anyone wants to see any file, please tell me. I am kinda desperate now. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2011-Oct-15 16:47 UTC
Re: Cannot run server/rake/spork/rspec or anything due to some failed tests
I just tried to run rake db:migrate:reset and I got a different error but still some spec involved: ** Invoke db:migrate:reset (first_time) ** Invoke db:drop (first_time) ** Invoke db:load_config (first_time) ** Invoke rails_env (first_time) ** Execute rails_env ** Execute db:load_config ** Execute db:drop ** Invoke db:create (first_time) ** Invoke db:load_config ** Execute db:create brothelking_test already exists ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! Mysql2::Error: Table ''ror_project_development.comments'' doesn''t exist: SHOW FIELDS FROM `comments ... /Users/user/Sites/ror_project/spec/factories/activity_reports.rb:21:in `block in <top (required)>'' ... /Users/user/Sites/ror_project/config/environment.rb:5:in `<top (required)>'' -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Leonardo Mateo
2011-Oct-15 17:29 UTC
Re: Re: Cannot run server/rake/spork/rspec or anything due to some failed tests
On Sat, Oct 15, 2011 at 1:47 PM, Heinz Strunk <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I just tried to run rake db:migrate:reset and I got a different error > but still some spec involved: > > ** Invoke db:migrate:reset (first_time) > ** Invoke db:drop (first_time) > ** Invoke db:load_config (first_time) > ** Invoke rails_env (first_time) > ** Execute rails_env > ** Execute db:load_config > ** Execute db:drop > ** Invoke db:create (first_time) > ** Invoke db:load_config > ** Execute db:create > brothelking_test already exists > ** Invoke db:migrate (first_time) > ** Invoke environment (first_time) > ** Execute environment > rake aborted! > Mysql2::Error: Table ''ror_project_development.comments'' doesn''t exist: > SHOW FIELDS FROM `comments > ... > /Users/user/Sites/ror_project/spec/factories/activity_reports.rb:21:in > `block in <top (required)>'' > ... > /Users/user/Sites/ror_project/config/environment.rb:5:in `<top > (required)>'' >I think you''ve ran into several errors and, at this point your environment is corrupted. Try first to sanitize your test environment. If possible, recreate your development database from scratch (drop it and create it again), then run your migrations again to make sure you have them all migrated. Do not seed the database unless you need something for the application to start properly. After you have your pristine development database, run: rake db:test:prepare, which will clone your dev database into your test database, so you will have the same database structure on both, development and test environment. Then start running your specs. Try running ''rake spec'', instead of ''rspec spec/'' since rake spec takes care of the db:test:prepare, so it might be redundant now, but once you get the habit of running this way, you make sure your data env is clean when your tests start. NOTE: Do not seed the test database, that''s not a good practice, since your tests scenarios need to be properly isolated to be reliable, you want to make sure of cleanning the sensitive data and mock up the data you need just before running the specific test scenario and not before. Hope it helps. Cheers! -- Leonardo Mateo. There''s no place like ~ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Oct-15 22:48 UTC
Re: Cannot run server/rake/spork/rspec or anything due to some failed tests
On Oct 15, 5:17 pm, Heinz Strunk <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey, > > I ran into a very weird problem and after trying to solve it for like 3 > hours now and Google not willing to help me I have to ask you guys. > > I''m currently writing some Spec tests which fail because of some missing > seed data. So rspec spec/ fails with: > /Users/pbartels/Sites/brothelking/app/models/character.rb:175:in > `create_fund'': Called id for nil, which would mistakenly be 4 -- if you > really wanted the id of nil, use object_id (RuntimeError) > > Well, fine I said so I''ll just run rake db:seed RAILS_ENV=test to seed > the database: > rake aborted! > Validation failed: Name has already been taken > ... > /Users/pbartels/Sites/ror_project/spec/factories/reports.rb:132:in > `block in <top (required)>'' > ... > > What the heck''s got rake to do in the spec directory?Have you tried reading the rest of the stack trace? It should show you who is invoking the code at fault. Fred I get the exact> same error when I start spork or rails s > When I run RAILS_ENV=test rake db:fixtures:load I also get "Called id > for nil..." which doesn''t make sense to me? > > In conclusion: Whatever I start/run it all fails inside some spec file > and I have absolutely no idea why everything is going into the spec > folder anyway?! > > I don''t even know where to start pasting files here so if anyone wants > to see any file, please tell me. I am kinda desperate now. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.