Hi Matthew,
Thats an interesting point about the databases. My impression is that
rake runs the equivalent of the rake task “clone_structure_to_test”
before running the tests. I’m not sure that the development schema in
db/development_structure.sql is involved, but I would be happy to be
corrected on this. [although I did just note that the
development_structure.sql file did appear to have been modified
following a rake test that I just tan]
I’ve managed to solve by first rake weirdness by adjusting the way a
conditional check was made - nothing to do with fixtures or the database
(see my other mail). Another weirdness seems to be that I can run these
sometimes failing tests fine with the rake loader, e.g.
d:/ruby/bin/ruby -Ilib;test
“d:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/rake_test_loader.rb”
“test/unit/stories_controller_test.rb”
but they fail when the whole battery of tests is included (I don’t have
to run rake to get the failure - just the above command line with the
rake_test_loader).
My latest weirdness comes from a template failing to receive a variable,
which it does fine as a single rake loaded item, but fails when all the
other tests are added.
I can even log the creation of the variable all the way to where the
mailer class assigns it, and it’s there all present and correct, except
when some threshold number of tests are added to rake:
- Error:
test_admin_preview_create(StoriesControllerTest):
ActionView::TemplateError: You have a nil object when you didn’t expect
it!
The error occured while evaluating nil.title
On line #1 of app/views/story_mailer/notify.rhtml
1: <%[email protected]%>
2: By: <%[email protected]_name%>
3: <%[email protected]%>
here’s the code that generates it:
def notify(controller,users,story,sent_at = Time.now)
@subject =
‘[’+CommunitySystem::CONFIG[:app_name]+’:story] '+ story.title
@body[‘story’] = story
logger.info 'notify_body_story: '+ @body[‘story’].inspect
@body[‘controller’] = controller
and here’s the logger output, showing the presence of the variable:
notify_body_story: #<Story:0x4b19370 @new_record=false,
@errors=#<ActiveRecord::Errors:0x4ae2260 @base=#<Story:0x4b19370 …>,
@errors={}>, @new_record_before_save=false, @attributes={“photo”=>nil,
“status”=>“approved”, “depttitle”=>“General”, “title”=>“what its about”,
“id”=>4, “caption”=>nil, “summary”=>“short but sweet”, “posted”=>Tue Feb
07 20:22:07 2006, “detail”=>“fine grained”, “authorid”=>1000006},
@story_comments=[]>
Now this works absolutely fine under all conditions, except if there are
more than about 12 tests being passed into the rake_loader. I’ve tested
previously and it doesn’t seem to matter which other tests they are,
just that once the number of incoming tests exceeds 11 or 12, then this
failure pops up.
Sorry to give you quite so much details, but I’m partly documenting this
to the list, because it is all so strange, and I’d like to think others
having the same problem will take some solace in that they are not
alone.
CHEERS> SAM