Rob Aldred
2009-Aug-14 11:04 UTC
[rspec-users] Fixtures not loading when running full test suite
Hi, I''ve been trying to work this out for a while, im convinced its some local db configuration specific to my machine. When running `rake spec` 14 of my test fail all of them in the user_spec generated by restful auth. The error for all the failing tests is: ActiveRecord::RecordNotFound Couldn''t find User with ID=1 Iv put some debugger lines and at the start of some of the tests it would appear that the users fixture is not being loaded when running the full suite If I run the specific test with the spec binary `spec spec/modes/user_spec.rb` all the fixtures are loaded and pass as expected. Further more, the error is only apparent when using mysql for the test db... When I use sqlite for the test db the tests pass when running the whole suite and the specific test... Weird... I''d like to know if anyone else has experienced this and if anyone has any pointers as to why the fixtures are not loaded when using mysql as the test db. Many thanks Rob -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090814/60b8e00a/attachment.html>
Scott Taylor
2009-Aug-14 16:18 UTC
[rspec-users] Fixtures not loading when running full test suite
On Aug 14, 2009, at 7:04 AM, Rob Aldred wrote:> Hi, I''ve been trying to work this out for a while, im convinced its > some local db configuration specific to my machine. > > When running `rake spec` 14 of my test fail all of them in the > user_spec generated by restful auth. > The error for all the failing tests is: > > ActiveRecord::RecordNotFound > Couldn''t find User with ID=1 > > Iv put some debugger lines and at the start of some of the tests it > would appear that the users fixture is not being loaded when running > the full suite > If I run the specific test with the spec binary `spec spec/modes/ > user_spec.rb` all the fixtures are loaded and pass as expected. > > Further more, the error is only apparent when using mysql for the > test db... > When I use sqlite for the test db the tests pass when running the > whole suite and the specific test... > > Weird... I''d like to know if anyone else has experienced this and if > anyone has any pointers as to why the fixtures are not loaded when > using mysql as the test db.Gist a copy of your spec_helper.rb I''d also run rake db:test:prepare and inspect the test database - making sure the fixtures are getting loaded properly. Just to note - running ./script/spec <a-spec-file.rb> won''t recreate the test database. You might also want to inspect that your fixtures are valid with a project like this (some code I''ve poached): http://github.com/smtlaissezfaire/validate_fixtures/tree/master Scott> > Many thanks > Rob > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Doug Bryant
2011-Jan-27 20:05 UTC
[rspec-users] Fixtures not loading when running full test suite
I''m currently running into the same issue and can find very little about it on the interwebs - i.e. an individual test run with `script/spec` works fine but the same test without any code changes fails when run as part of the suite via `rake spec` This issue seemed to start out of the blue. Some background and details... Fixtures don''t seem to be loading properly when run as part of the suite. When my Driver model tries to save, it runs a validation testing that the zip code entered is valid (i.e. exists in the ZipsTerritory rating table). I have the :zips_territories fixture declared in the tests with enough data in the fixture for the test to pass. The spec runs fine when executed with `script/spec` but fails when run as part of the test suite `rake spec`. The zips_territory fixture is declared properly and in before(:each) in the tests, a driver is created with FactoryGirl via a call like Factory.create(:driver). The callstack indicates the test is failing while FactoryGirl is trying to create the model. Also, for a given developer, the same set of tests fail due to this issue consistently, but the tests which fail differ across different developers. These tests had been running fine as a suite for almost two years. In trying to debug this, I stumbled across some interesting behavior. If in the before(:each) filter on the failing tests, I printed out a log message which ultimately executed "ZipsTerritory.count". After I did this, the tests would pass as part of a suite. Needing a quick fix and not having time to debug the issue further, I just did the following in the spec_helper.rb file... config.before(:each) do Rails.logger.warn "ZipsTerritory.count == #{ZipsTerritory.count}" end This worked fine for about a week before the issue popped back up again. I can''t think of anything which changed in the codebase which would have triggered this problem. The app has been running rails 2.3.8 for several months. We had been using rspec 1.3.0 and rspec-rails 1.3.2 for several months. (sidenote: rspec 1.3.1 & rspec-rails 1.3.3 seem to have some sort of other bug which fails to properly call a method on a child class and somehow gets delegated to the parent class - not present in 1.3.0 & 1.3.2 rspec/rspec-rails). I''ve tried several version of FactoryGirl and all of those seem to trigger the issue too. My spec_helper.rb is: https://gist.github.com/0d3ea01ffe4a15f4b2b3 Does anything stand out? Has anybody else experienced this? Any ideas? Thanks, Doug On Fri, Aug 14, 2009 at 6:04 AM, Rob Aldred <rob.aldred at setfiremedia.com>wrote:> Hi, I''ve been trying to work this out for a while, im convinced its some > local db configuration specific to my machine. > > When running `rake spec` 14 of my test fail all of them in the user_spec > generated by restful auth. > The error for all the failing tests is: > > ActiveRecord::RecordNotFound > Couldn''t find User with ID=1 > > Iv put some debugger lines and at the start of some of the tests it would > appear that the users fixture is not being loaded when running the full > suite > If I run the specific test with the spec > binary `spec spec/modes/user_spec.rb` all the fixtures are loaded and pass as expected. > > Further more, the error is only apparent when using mysql for the test > db... > When I use sqlite for the test db the tests pass when running the whole > suite and the specific test... > > Weird... I''d like to know if anyone else has experienced this and if anyone > has any pointers > as to why the fixtures are not loaded when using mysql as the test db. > > Many thanks > Rob > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110127/0d84d44c/attachment.html>
David Chelimsky
2011-Jan-28 05:22 UTC
[rspec-users] Fixtures not loading when running full test suite
On Thu, Jan 27, 2011 at 2:05 PM, Doug Bryant <doug+rspecuser at netinlet.com> wrote:> I''m currently running into the same issue and can find very little about it > on the interwebs - i.e. an individual test run with `script/spec` works fine > but the same test without any code changes fails when run as part of the > suite via `rake spec` > This issue seemed to start out of the blue. ?Some background and details... > Fixtures don''t seem to be loading properly when run as part of the suite. > When my Driver model tries to save, it runs a validation testing that the > zip code entered is valid (i.e. exists in the ZipsTerritory rating table). > ?I have the :zips_territories fixture declared in the tests with enough data > in the fixture for the test to pass. ?The spec runs fine when executed with > `script/spec` but fails when run as part of the test suite `rake spec`. ?The > zips_territory fixture is declared properly and in before(:each) in the > tests, a driver is created with FactoryGirl via a call > like?Factory.create(:driver). ?The callstack indicates the test is failing > while FactoryGirl is trying to create the model. ?Also, for a given > developer, the same set of tests fail due to this issue consistently, but > the tests which fail differ across different developers. > These tests had been running fine as a suite for almost two years. > In trying to debug this, I stumbled across some interesting behavior. ?If in > the before(:each) filter on the failing tests, ?I printed out a log message > which ultimately executed "ZipsTerritory.count". ? After I did this, the > tests would pass as part of a suite. ?Needing a quick fix and not having > time to debug the issue further, I just did the following in the > spec_helper.rb file... >> >> ?? config.before(:each) do >> >> ?? ? Rails.logger.warn "ZipsTerritory.count == #{ZipsTerritory.count}" >> >> ?? end > > This worked fine for about a week before the issue popped back up again. > I can''t think of anything which changed in the codebase which would have > triggered this problem. ?The app has been running rails 2.3.8 for several > months. ?We had been using rspec 1.3.0 and rspec-rails 1.3.2 for several > months. ?(sidenote: rspec 1.3.1 & rspec-rails 1.3.3 seem to have some sort > of other bug which fails to properly call a method on a child class and > somehow gets delegated to the parent class - not present in 1.3.0 & 1.3.2 > rspec/rspec-rails).Example please?> I''ve tried several version of FactoryGirl and all of > those seem to trigger the issue too. > My spec_helper.rb is:?https://gist.github.com/0d3ea01ffe4a15f4b2b3 > Does anything stand out? ?Has anybody else experienced this? ?Any ideas? > Thanks, DougI made one comment on the gist, but I think it''s unrelated. You say nothing changed that you _think_ would cause this, but something must have changes somewhere. What _did_ change? Any new gems or upgraded gems in the environment?> On Fri, Aug 14, 2009 at 6:04 AM, Rob Aldred <rob.aldred at setfiremedia.com> > wrote: >> >> Hi, I''ve been trying to work this out for a while, im convinced its some >> local db configuration specific to my machine. >> When running `rake spec` 14 of my test fail all of them in the user_spec >> generated by restful auth. >> The error for all the failing tests is: >> ActiveRecord::RecordNotFound >> Couldn''t find User with ID=1 >> Iv put some debugger lines and at the start of some of the tests it would >> appear that the users fixture is not being loaded when running the full >> suite >> If I run the specific test with the spec >> binary?`spec?spec/modes/user_spec.rb`?all?the?fixtures?are?loaded?and?pass?as?expected. >> Further more, the error is only apparent when using mysql for the test >> db... >> When I use sqlite for the test db the tests pass when running the whole >> suite and the specific test... >> Weird... I''d like to know if anyone else has experienced this and if >> anyone has any pointers >> as?to?why?the?fixtures?are?not?loaded?when?using?mysql?as?the?test?db. >> Many?thanks >> Rob >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Andrew Premdas
2011-Jan-28 22:34 UTC
[rspec-users] Fixtures not loading when running full test suite
On 14 August 2009 12:04, Rob Aldred <rob.aldred at setfiremedia.com> wrote:> Hi, I''ve been trying to work this out for a while, im convinced its some > local db configuration specific to my machine. > > When running `rake spec` 14 of my test fail all of them in the user_spec > generated by restful auth. > The error for all the failing tests is: > > ActiveRecord::RecordNotFound > Couldn''t find User with ID=1 > > Iv put some debugger lines and at the start of some of the tests it would > appear that the users fixture is not being loaded when running the full > suite > If I run the specific test with the spec > binary `spec spec/modes/user_spec.rb` all the fixtures are loaded and pass as expected. > > Further more, the error is only apparent when using mysql for the test > db... > When I use sqlite for the test db the tests pass when running the whole > suite and the specific test... > > Weird... I''d like to know if anyone else has experienced this and if anyone > has any pointers > as to why the fixtures are not loaded when using mysql as the test db. > > Many thanks > Rob > >Could this be something to do with mysql not resetting its numbering between tests, so it is actually loading a user, but not with ID=1. I''m pretty sure I''ve seen that behaviour in the past. All best Andrew _______________________________________________> rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110128/68cad1e1/attachment-0001.html>