ls command in color mode sometime causes a problem to my eyes. Turn it off is simple, just put
unalias lsin .bash_profile or .bashrc (in case of Ubuntu Feisty)
ls command in color mode sometime causes a problem to my eyes. Turn it off is simple, just put
unalias lsin .bash_profile or .bashrc (in case of Ubuntu Feisty)
fixture_path is class attribute/variable of Test::Unit::TestCase so all subclasses of it share the same value.
require 'rubygems' require 'active_record' require 'active_record/fixtures' class TestFoo < Test::Unit::TestCase self.fixture_path='/u01/test/fixtures/foo' end TestFoo.fixture_path # "/u01/test/fixtures/foo" class TestBar < Test::Unit::TestCase self.fixture_path='/u01/test/fixtures/bar' end TestBar.new().fixture_path # "/u01/test/fixtures/bar" TestFoo.new().fixture_path # "/u01/test/fixtures/bar"Because the Test Unit framework, load all test classes, then run them, so
TestFoo.new().fixture_path get value of TestBar.new().fixture_path. The solution is simple, just define a method fixture_path in each test class (in upcoming version after ActiveRecord 1.15.3, the problem is fixed by change fixture_path to class instance variable see ticket 6672).
class TestFoo < Test::Unit::TestCase
def fixture_path
'/u01/test/fixtures/foo'
end
end
class TestBar < Test::Unit::TestCase
def fixture_path
'/u01/test/fixtures/bar'
end
end
TestBar.new().fixture_path # "/u01/test/fixtures/bar"
TestFoo.new().fixture_path # "/u01/test/fixtures/foo"
begin do_some_things() rescue #... print message, closing file/socket etc. endThere is a problem with this style. If there is error, we lost information where it happens because it is quite common that
do_some_things() again call methods of others classes located in different files and so all. backtrace of exception in every exception handling code
begin do_some_things() rescue => e require 'pp' pp e pp e.backtrace #... print message, closing file/socket etc. endThe
backtrace information will help us to identify bug during development and to analyze root cause of exception during operation.
first_name = 'huy' sir_name = 'le' name = first_name + ' ' + sir_name # huy leBut the above code suffers a problem, if one of concatenated variables is
nil, then it will not work. Checking nil is tedious and error prone, a simple solution of this problem is putting concatenated variables into an array, removing nil using compact and using join method to perform concatenation.
first_name= 'huy'
middle_name=nil
sir_name = 'le'
name = [first_name, middle_name, sir_name].compact.join(' ') # huy le
do ... end versus {...} to enclose Ruby block reminds me command/query separation OOP principle.