Google

Friday, May 16, 2008

keeping 1 assertion per testcases in RoR

I'm rewriting badly written unit test at the office.

first, using MVC for RoR, unit test mirrors models/, checking the validity of what goes into database and data types allowed. and much of what's handled in controllers/ go to functional tests. Then there are view tests that often goes into unit/ and some of full regressions in scenario based that goes into integration tests area.

the ones i had to rewrite, there were much of controllers validations, for example. and, each testcases with like two dozen assert this and assert that. so how can you tell when you run 12 testcases and out of 75 assertions 3 fails? how to you analyze and how do you put it in matrix? and, how do you know if assertion failure triggers cascade affect for the rest of assertions in testcase or not?

as tedious as it may seem, do setup and teardown repeatedly, and put one assertion per testcase. say if you put assertion for an account's email existing, in next testcase where you use same account, make a note either to yourself or on the comments that email existance check is already done and that you move on the format of the email. not if it's used for login or not, but just enter different possible email addresses, like with non-alphanumeric characters, or in localized address, or ones entered without domain, or ones that are very long.

i like the one i careated for account testing, which still has whole lot more roon to add, by the way, and i'm excited to add more testcases here, and also to build whole suite of'em ground up!


require File.dirname(__FILE__) + '/../../test_helper'

require 'test/unit'

class AccountTest < Test::Unit::TestCase
def setup
super
@account = create_testacct
end

def teardown
acct_cleanup
end

def test_new_acct_have_a_unique_username
@account = create_testacct

assert_not_nil @account.unique_username

acct_cleanup
end

def test_cannot_create_acct_with_email_not_having_domainname
assert_raise(ArgumentError,"accttest is not a valid email address.") do
@account = Account.create_by_email("accttest")
end
end

def test_cannot_create_acct_with_email_not_having_domainname2
assert_raise(ArgumentError,"accttest is not a valid email address.") do
@account = Account.create_by_email("accttest@")
end
end

def test_cannot_create_acct_with_email_having_bad_domain
assert_raise(ArgumentError,"accttest is not a valid email address.") do
@account = Account.create_by_email("accttest@testdomain")
end
end

def test_cannot_create_acct_with_email_having_only_domainname
assert_raise(ArgumentError,"accttest is not a valid email address.") do
@account = Account.create_by_email("@testdomain.com")
end
end

def test_new_acct_not_activated
@account = create_testacct
set_default_password

assert !(@account.activated?)

acct_cleanup
end

def test_activate_method_makes_new_acct_active_acct
@account = create_and_activate_testacct

assert @account.activated?

acct_cleanup
end

def test_activate_acct_without_password_fails_with_correct_error
@account = create_testacct

assert_raises(Error::HumanReadable, "You must set a password before we can activate your account!") do
@account.activate()
end

acct_cleanup
end

def test_cannot_create_acct_with_existing_email_address
@account = create_and_activate_testacct
assert_raise(AccountModule::AccountExistsError,
"There is already an account with this email address, please try a different one.") do
@account2 = create_and_activate_testacct
end

acct_cleanup
end

private
def create_testacct
@account = Account.create_by_email("accttest@localhost")
@account.save!

return @account
end

def set_default_password
@account.password = "test123"
end

def create_and_activate_testacct
@account = create_testacct
set_default_password
@account.activate()
@account.save

return @account
end

def acct_cleanup
@account.destroy
end
end

Google

Tuesday, January 15, 2008

macbook air, small enough for me?

macworld 2008 keynote announced 'macbook air'.

macworld has historically been apples' new product announcement platform, announcing iPhone, iPod, ..., all the popular commodities that many teens and 20-somethings wouldn't know how to live without.

I got my Sony Vaio X505 back in 2005, for christmas, and have been happy with it's light weight. having been leisurely shopping for replacement for my Vaio X505, I had my eyes peeled watching the keynote via online video and reading the spec from apple's website. 3lbs? it's definitely much lighter than conventional macbook or macbook pro. and, of course, it's from apple, afterall.

still 3lbs? that means my bag would be heavier by 1+ lbs.

hmm... i'll have to wait and see. anyone rushing out to buy macbook air yet?

Google

Wednesday, December 26, 2007

legacies remembered, through musical and through 'kennedy center honors'

Brian Wilson, Diana Ross, Steve Martin, Leon Fleisher and Martin Scorsese are honored during "Kennedy Center Honors" on CBS.

This reminded me of recent visit to "Jersey Boys", a musical based on 50-70's pop group 'Four Season'.

Less dramatic, maybe a little, than Jersey Boys, it was nice to see someone like Yo-yo-ma on the stage versing Leon Fleisher's life story, and funny to see someone re-acting Steve Martin's comedy. It seems like a lot of toughts were put in to organizing this, and many volunteered(?) to perform. A young aspiring pianist playing in tribute to Leon was also pretty mesmerizing and made me ashamed of my lazyness in practice.

Something that made me think, of these two occassions: value of talent! I usually don't believe in talent but more so on hard work. But would these great artists be great artists with perserverance alone? Maybe the passion, and that 1% that makes differences against other artists would be their god-given talent? If so, what would be my talent? Heh, ouch...

Maybe the vocab. 'talent' is some special quality not common in general public, like me, thus my justification for lacking talent. I'm a mediocre at drawing/painting, at music, at computers, at math, at finances, ...

maybe my talent is just being mediocre good at things? lol.

anyways, it's pretty amazing how some people can listen to a tune and can identify, play along and even improve what he/she heard.

I really enjoyed "Jersey Boys", and now I can appreciate 'Four Season's music with insight. And, now the "Kennedy Center Honours" helps me realize I shouldn't give up on a boring things like new year's resolution. If someone like Diana Ross was determined, and loved singing at age 15, and carried through all the black-and-white-TV era through 70s and 80s, ...

Don't need to be honored at Kennedy Center myself, but "wouldn't it be nice if ..." i had no regret with my life when I look back at what I have accomplished?

^^

Google

checkin out gentoo 2007


checkin out gentoo 2007
Originally uploaded by speattle
not so much by choice, but i got to learn to install and setup gentoo on intel based mac mini for ruby on rails app.

partitioning, installation, package installation with emerge, ..., it's been quite painful 4 days.

i had to use mac mini, because that was only hardware available to me, and duh, i started with 10.4 without boot camp. that was my stumbling block. once i grabbed leopard installation that came with bootcamp, partitioning got easier.

oh, also partition it as windows partition, then change it to linux using 'fdisk /dev/sda' when in gentoo shell.

i had downloaded gentoo 2007 livedvd but for some reason it didn't like looking up '/dev/sda' to kick off the installation.

after about 2-3 failed attempt and about 2 complete reinstall from mac os, i sorta got wised and attempted to chmod /dev/sda* from root as livedvd took me to X windows as gentoo user. That didn't help, but now i know not to panic, as i can sudo as gentoo user without password.

still with no success at install, i had to opt for minimial install cd, and as i've not done gentoo install before i'd be reading gentoo handbook and wouldn't know the instruction. now that i do understand, it's pretty easy instruction to follow; explaining the steps that followed by exact command line to enter.

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?full=1#book_part1_chap1 is bookmarked for me now, along with http://gentoo-wiki.com/HARDWARE_Apple_Mac_Mini.

i'm in the middle of adding packages via emerge now.

still am not familiar with raiserfs, but am glad to know gentoo can be loaded to mac mini.

although it didn't work out livedvd logging in as gentoo and taking me to X window desktop was nice. after following minimal install i'm logged in to shell for emerge update, and got to locate X window/desktop packages to install to get ack into the Desktop as nice/fancy as gentoo user's was when i booted from DVD.

oh, it was nice i made note about rEFit earlier in blog, i had to look it up when partitioning from Mac OS X.

Google

Monday, November 12, 2007

things to remember: network scanning tools, and painful ror select tags

i literally spent half day on using select_tag with options_for_select using ror.
ouch.

in theory
<%= select_tag 'table_name[field_name]', options_for_select([array of options list],'what is inserted in table table_name field field_name as value') %>

to get the select list showing up w/ prepopulated data.

why spend whole half day?

hmm... well, the field i am trying to pre-populate have mysql db table with type enum. i think that's why it's not working for the category i am building. works for 'os' which have data type as string works after a few try. should i add '.to_i' to get the enum map to the integer value of the list? how stupid it feels. continue on hacking.

so far it works for:

<%= select_tag 'testtable[target_os]', options_for_select(["", "Windows", "OS X", "Linux"], @testtable.target_os) %>


and

<%= select_tag 'testtable[target_browser]', options_for_select(["", "Firefox", "IE", "Safari", "opera"], @testtable.target_browser) %>


with

@testtable = TestTable.find(params[:id])

in my controller's class method.

Oh, i also better not forget how to use ss and nmap.

'ss -l' in most cases and 'nmap -A -T4 hostname' tells me what ports i am using. not sure if it's weather or just banging my head of this select_tag, but it took me forever to remember these two. Actually I had to ask around for ss. What a monday...

Google

Thursday, November 01, 2007

chasing leopard, ..., caught up on rmagick at least.

when i first got into ror(ruby on rails) earlier this year getting the system configured w/ ruby, rails, gem, and rmagick in particular was a pain, on my fedora core desktop.
then came along ubuntu's easy install guide followed by fedora core(5, 6 and onward)'s easy to install, with all those '*-dev' packages that contain all the libraries.

rmagick, in short, is imagemagick/graphicsmagick package for ruby-on-rail that ror developers use a lot.

well, with my environment setup nicely, and not being a heavy mac user i only enjoyed stuffed animal leopard at local mac sotres and didn't bother with mac os update. getting a bit too old to be caught up in flurry of hypes.

well, derek is a cool guy and he waited on the line on last friday to get leopard copy, along with free t-shirt, and installed it. now it comes with ruby, rubygem and rails, but not with rmagick or mysql. when he had no success and couldn't get his work done (for having clean installed the whole system on his mac book), i got volunteered in this morning. i mean yesterday morning. i spent good 5hours solid chasing gtk, librsvg and imagemagick-devel that may or may not exist. with gtk, the dependencies were about as greek to me as the gtk package itself. requires pango then requires cairo, but it reality gtk requires pango with cairo support. and then there is question of incompatible pkgconfig. what do you mean pkgconfig is too old? leopard is been out less than a week....

anyhow, i can't let rmagick defeat me, so i picked up a leopard copy and spent good 2+ hrs getting it on my precious mac mini, the one with dual boot partition of fedora core 6. why 2+ hours? takes about 45minutes, and i did it twice, because i messed up playing with boot camp and few other configs. with the install my rEFI bootloader is blown away. my linux partition is still there, but no bootloader to let me start with linux partition. sob, sob, sob... since boot camp is only compatible with windows os, and i have no room nor wish to delete current linux partition and reinstall(i actually was using my inux partition right up to the point i started inserting leopard dvd in, for installation).

unlike earlier the day i actually searched for rmagick installation how to, and got lucky.

http://pastie.caboo.se/72596 actually works.

some of urls didn't work so i had to manually download it. but steps are golden. i skipped ruby, rubygem and rails. i also used 'sudo gem install rmagick' instead of doing tar source install.

but it works.

i did 'cd rails/test/; script/console; require 'RMagick' ' and it worked. only took me what about 2+ hours, and another hour to copy over the list of tar files and instruction for derek?

yay...

thanks Josh Goebel. you saved me my sanity.

now i still gotta figure out why readline doesn't compile and why mysql server doesn't start from boot.

worst of all, i gotta figure out my dual boot.

but now i can sleep, finally, at 4am, for having rmagick working on my new shiney leopard os.

and, i can see some cool desktop features on leopard. through my sleepy slanted eyes.

pkgs i needed:
* pcre-7.4
* lighttpd-1.4.18
* freetype-2.3.4
* libpng-1.2.22
* jpegsrc.v6b
* tiff-3.8.2
* libwmf-0.2.8.4
* lcms-1.17
* ImageMagick-6.3.6-4
* ghostscript-fonts-std-8.11 (when untar, goes to fonts dir instead of ghostscript-fonts dir)

steps from my home>Downloads folder terminal shell:
tar xvf pcre-7.4.tar
cd pcre-7.4
./configure --prefix=/usr/local CFLAGS=-01
make
make install
cd ..
tar xvf lighttpd-1.4.18.tar
cd lighttpd-1.4.18
./configure --prefix=/usr/local --with-pcre=/usr/local
make
make install
cd ..
tar zxvf freetype-2.3.4.tar.gz
cd freetype-2.3.4
./configure --prefix=/usr/local
make
make install
cd ..
tar xvf libpng-1.2.22.tar
cd libpng-1.2.22
./configure --prefix=/usr/local
make
make install
cd ..
tar xvf jpegsrc.v6b.tar
cd jpeg-6b/
ln -s `which glibtool` ./libtool
echo $MACOSX_DEPLOYMENT_TARGET
export MACOSX_DEPLOYMENT_TARGET=10.5
./configure --enable-shared --prefix=/usr/local
make
make install
cd ..
tar xvf tiff-3.8.2.tar
cd tiff-3.8.2
./configure --prefix=/usr/local
make
make install
cd ..
tar zxvf libwmf-0.2.8.4.tar.gz
cd libwmf-0.2.8.4
make clean
./configure
make
make install
cd ..
tar xvf lcms-1.17.tar
cd lcms-1.17
make clean
./configure
make
make install
cd ..
tar xvf ghostscript-fonts-std-8.11.tar
mkdir /usr/local/share/ghostscript
mkdir /usr/local/share/ghostscript/fonts
cp fonts/* /usr/local/share/ghostscript/fonts/.
tar xvf ImageMagick-6.3.6-4.tar
cd ImageMagick-6.3.6
export CPPFLAGS=/-I/usr/local/include
export CPPFLAGS=-I/usr/local/include
export LDFLAGS=-L/usr/local/lib
./configure --prefix=/usr/local --disable-static --with-modules --without-perl --with-quantum-depth=8 --with-gs-font-dir=/usr/local/share/ghostscript/fonts
make
make install
gem install RMagick

does it work? yes:
so far it looks okay on irb:
mac-mini:~ user$ cd rails/test/
mac-mini:test user$ script/console
Loading development environment.
>> require 'RMagick'
=> []
>>

Google

Thursday, October 04, 2007

with a trace or without a trace?

Without a trace new season began. Like 'Law and Order: Criminal Intent', it's got a lot of brain work and foot work. I am somewhat okay with CSI:NY with new york being the location, but don't like other CSI for their being too much of fancy and flash labs and equipment usually not available for cops. Not even in real life, let alone in fantasy. I've not yet caught up with '24' although the author is from nearby in Washington state. While watching new 'My Name is Earl', and 'Without a Trace' and hoping for someone to post streaming video of new 'Law and Order:Criminal Intent' i was on dealscatcher.com and saw this sudoku on toilet paper and had a hearty laugh. So write it on sudoku paper while you know what and use that paper? What if you don't finish solving the sudoku in time?

Google

Sunday, August 26, 2007

vnc server and vncviewer, side by side




after updating ubuntu on sony vaio x505 from edge to feisty, everything's hunky-dory. updating from edge to feisty, however, was ugly and messy. somehow the ide2 doesn't get recognized thus, update via CD-ROM was impossible, and had to do update over net, with a bit of cheatin'. anyhow, once feisty was on the machine and thus ruby was to latest available version of 1.8.4, i just followed http://wiki.rubyonrails.org/rails/pages/RailsOnUbuntu and rubygems and rails installation was easy. so was rmagick installation. i think people often forget to do 'apt-get install ruby1.8-dev' before 'gem install rmagick'. compared to having spent good day or two to ge t rmagick working by downloading .tar on fedora core, then something not working and try to download again using yum, and now having two downloads to deal with, ..., etc., it was less than 10minutes 1-line experience that's pretty pleasant. should i have started with yum install of rmagick in the first place? well, that's what we call a learning curve i guess. now i know better to get 'ruby*-dev' when installing 'ruby*' and now i know 'yum install rmagick' or 'apt-get install rmagick' can be relatively painless and easy.

this inspired me to make vnc working between my laptop and mac mini converted desktop with fedora core 6. i had the server setup but was keep getting connection issue from laptop when using 'vncview host:port'. duh me! i had to be told maybe vnc port is not open on the server? alas, when i fixed that, i'm on my mac mini's fedora core from my ubuntu laptop, right next to the server or a few blocks down the cafe.

it's fun making a good progress on things, and pretty inspiring.