I'm new to Ruby/Rails testing. It seems the Test::Unit method
assert defined? foo
nil is a value, so a variable who's value is nil is defined. Here's some repl output to demonstrate:
 pry(main)> a = nil => nil  pry(main)> defined? a => "local-variable"  pry(main)> defined? b => nil
You may be confused because accessing an undefined instance variable also returns
nil, but that's still not the same:
 pry(main)> defined? @b => nil  pry(main)> @b = nil => nil  pry(main)> defined? @b => "instance-variable"
Global variables (
$foo) work like instance variables in this respect, but accessing an uninitialized class variable (
One last thing: local variables are declared at parse time in Ruby, so if any branch of your method sets a local, that local is defined (and initialized to
nil) anywhere in the method (or block).