Hi folks, I''ve got a couple of tests which definitely pass when I run them using: ruby test/unit/section_collection_test.rb But if I use: rake test_units Two of the tests fail. Is there a difference between these two situations? I assume that they are both using the test runtime environment? Here''s the code in question: --TEST----------------------------------------------- def test_move_forward_on_head_swaps_head_for_tail_where_there_are_two_items @collection.load_all_sections assert_equal(1, Section.find(2).position) assert_equal(2, Section.find(1).position) assert @collection.move_forward(Section.find(2)) assert_equal(1, Section.find(1).position) assert_equal(2, Section.find(2).position) end --------------------------------------------------------- --Method under test----------------------------- def move_forward(section_to_move) i = @sections.index(section_to_move) if (i != nil and i+1 != @sections.length) this_section = @sections[i] next_section = @sections[i+1] next_position = next_section.position next_section.position = @sections[i].position return false unless next_section.save this_section.position = next_position return false unless this_section.save end true end --------------------------------------------------------- --Fixture being loaded-------------------------- last_section: id: 1 position: 2 heading: ''last section'' text: ''some text'' first_section: id: 2 position: 1 heading: ''first section'' text: ''some text'' --------------------------------------------------------- thanks, Craig -- Craig Ambrose Web Elements http://www.portallus.com/people/craigambrose/
On 6/9/05, Craig Ambrose <craiga-aW5oDkNkUadaA94nB1n4cRCuuivNXqWP@public.gmane.org> wrote:> > Hi folks, > > I''ve got a couple of tests which definitely pass when I run them using: > ruby test/unit/section_collection_test.rb > > But if I use: > rake test_units > > Two of the tests fail. Is there a difference between these two situations? I > assume that they are both using the test runtime environment?Anytime that''s happened to me, I just have to add a fixture or two that I left out. Ideally, tests shouldn''t depend on anything else, and should work the same whether run through rake, individually by file with ruby, or with a single method. If your database is inconsistent, make sure you have all the fixtures for models that you''re using. -- rick http://techno-weenie.net
Add them to where? The reason I''m confused is that I thought running tests from command line ruby, and running them from rake, was exactly the same. My fixture is already loaded in my test class, otherwise how would the tests pass when using command line ruby? Does anyone know of any ways in which running tests via rails differs for just using ruby? Test helper gets called either way, and it does all the work. The wierd thing is, only two of my tests fail via rake, while other ones (using the same fixture) work fine. Craig On Fri, 10 Jun 2005 1:18 am, Rick Olson wrote:> Anytime that''s happened to me, I just have to add a fixture or two > that I left out. Ideally, tests shouldn''t depend on anything else, > and should work the same whether run through rake, individually by > file with ruby, or with a single method. If your database is > inconsistent, make sure you have all the fixtures for models that > you''re using.-- Craig Ambrose Web Elements http://www.portallus.com/people/craigambrose/
On Thursday 09 June 2005 07:42 pm, Craig Ambrose wrote:> Add them to where? The reason I''m confused is that I thought running tests > from command line ruby, and running them from rake, was exactly the same. > My fixture is already loaded in my test class, otherwise how would the > tests pass when using command line ruby? > > Does anyone know of any ways in which running tests via rails differs for > just using ruby? > > Test helper gets called either way, and it does all the work. The wierd > thing is, only two of my tests fail via rake, while other ones (using the > same fixture) work fine. > > CraigOddly enough, I''m having a similar problem. When I run it via rake, a method I''ve added to Test::Unit::TestCase is not found, but when I run the tests directly they''re just fine. I''m quite surprised. David