Wednesday, 15 June 2011

ruby on rails - How do I test the behavior executed by "whenever?" -



ruby on rails - How do I test the behavior executed by "whenever?" -

i'm using whenever schedule task in rails, , find way test behavior beingness executed.

is there way trigger event in test (like rspec) can create assertions results? executed task class method works because i've tested manually in rails console, there way trigger event behavior happens , can assert works same way within config/schedule.rb?

the "whenever event"

the thing changes in whenever wraps (ie, cron) compared regular spec run scheme environment, , more environment variables.

you can see commands whenever install in cron using executable :

$ whenever

cron start raw environment. if check crontab content (using crontab -e) you'll see on top variables set. can set additional variables, there. illustration :

shell="/bin/bash" path="/sbin:/bin:/usr/sbin:/usr/bin" mailto="your_user" home="/home/your_user" rails_env="production"

you should not need those, though, because whenever uses nice trick : calls commands using /bin/bash -l -c. ensures uses login shell, loads ~/.bashrc file. variable exported in bashrc file accessible within cron execution.

also note distributions (like gentoo) have check in skel bashrc file quit if shell not interactive (so have set environment variables before if needed in cron).

tests similar env

to reply testing, not idea. there's nil related codebase here, related scheme (similarly, don't test version of postgres or imagemagick installed on scheme in specs).

you can simulate, debugging sake, happens in cron while invoking rspec doing such :

env - home=/home/<your_user>/ /bin/bash -l -c 'rspec spec/'

this ensure environment emptied (env -), set home minimal env, phone call login shell whenever commands do.

ruby-on-rails ruby rspec cron whenever

No comments:

Post a Comment