Topic: Even stranger behaviour

OK, this one I can't work out either.

When I run the rake tasks for the separate types of test (i.e. rake test:units, rake test:functionals etc), I get 100% pass rates - no errors, no failures.

However, when I run the whole lot (i.e. rake test ), I get a truck load of errors!

Can anyone explain why? I think it must have something to do with the database set-ups, the errors are all data related (e.g. template variables are nil, that sort of thing)

Cheers,

Jason

Re: Even stranger behaviour

I'm guessing it has something to do with how the fixtures are being loaded. Make sure all of the necessary fixtures are loaded at the top of each test. If the tests are done in a slightly different order then it may cause dependency issues like you are seeing.

You may want to just load all the fixtures in test_helper, that way you don't have to worry about it.

Railscasts - Free Ruby on Rails Screencasts

Re: Even stranger behaviour

I've delved a bit further into this - the problems are confining themselves to integration tests now. I've set up my test_helper.rb as described in this.

# test_helper.rb
class ApplicationController::IntegrationTest
  fixtures :foo, :bar
end

class Test::Unit::TestCase
  # Transactional fixtures blah blah blah

  fixtures :foo, :bar
end


The part of the test which fails has to do with reading back an new row created in a database table earlier in the test - any test (assert_select on suitable generated HTML elements, assert TableName.exists?(id) etc) fails when I run rake test. The exact same test passes with flying colours, when I just run the integration tests with rake test:integration.

Has anyone else struck this? It's been driving me nuts for 2 days now.

Cheers

Jason

Re: Even stranger behaviour

Ah, found the error finally - It was being caused by me assuming a record id, then testing against that id, forgetting that MySQL will increment auto-increment columns between test sessions.