When I run specs individually: ruby /path/to/spec.rb it will pass. However, its more likely to fail when I run rake spec Does anyone know why that is, am I doing something wrong? TIA, Luke -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jul-09 08:23 UTC
Re: Specs run individually pass, but fail on rake spec?
We had trouble like that, when for example we had forgotten to declare fixtures in a file where we used them. In this case it can happen, that the test runs, if the fixture was loaded before in another file, but failed in other cases, depending on how the test was started. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Also, if your test db gets full of dirty data (data from pasts tests that was not deleted) then the order which you run your tests might affect the outcome. Always be sure to delete all data that you save in your tests, especially when dealing with models that have validates_uniqueness_of :... before :each do Model.delete_all JoinModels.delete_all Other.delete_all end On Jul 9, 9:23 am, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote:> We had trouble like that, when for example we had > forgotten to declare fixtures in a file where we used them. > In this case it can happen, that the test runs, if the fixture > was loaded before in another file, but failed in other cases, > depending on how the test was started.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-09 10:03 UTC
Re: Specs run individually pass, but fail on rake spec?
On 9 Jul 2008, at 10:09, Wolas! wrote:> > Also, if your test db gets full of dirty data (data from pasts tests > that was not deleted) then the order which you run your tests might > affect the outcome. Always be sure to delete all data that you save in > your tests, especially when dealing with models that have > validates_uniqueness_of :... > > before :each do > Model.delete_all > JoinModels.delete_all > Other.delete_all > endI don''t know much about rspec, but if it''s at least vaguely sensible it will be doing the same thing as the rails test::unit stuff which wraps tests in a transaction so that you don''t need cleanup like that (although this will of course break if you break the transaction (eg by using MyISAM tables in mysql) or executing a statement that causes an implicit commit. More generally anything that makes a state change that is not rolled back can cause this sort of failure (eg changing class variables) Fred> > > On Jul 9, 9:23 am, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote: >> We had trouble like that, when for example we had >> forgotten to declare fixtures in a file where we used them. >> In this case it can happen, that the test runs, if the fixture >> was loaded before in another file, but failed in other cases, >> depending on how the test was started. > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---