[Backgroundrb-devel] unit tests?

hemant gethemant at gmail.com
Thu Apr 5 19:00:56 EDT 2007


On 4/6/07, hemant <gethemant at gmail.com> wrote:
> On 4/5/07, Phlip <phlip2005 at gmail.com> wrote:
> > Ezra et al:
> >
> > I have this problem:
> >
> > http://rubyforge.org/pipermail/backgroundrb-devel/2006-December/000578.html
> >
> > Any progress on it? Or are unit tests simply impossible for now?
> >
>
> I did found a way to test my workers eventually, i thought of writting
> a nice blog entry about that, but well... ;)
>
> Here is how i do it:
>
>
> # mocker code:
> # RAILS_ROOT/test/mocks/test/backgroundrn_mocker.rb
>
> module BackgrounDRb
>   module Worker
>
>     class RailsBase
>       # class methods on the class
>       attr_accessor :logger
>       class << self
>         def register
>           return true
>         end
>       end
>
>       def ivar var
>         instance_variable_get :"@#{var}"
>       end
>     end
>   end
>
> end
>
>
>
> # RAILS_ROOT/test/unit/message_worker_test.rb
>
> require File.dirname(__FILE__) + '/../mocks/test/backgroundrb_mocker'
> require File.dirname(__FILE__) + '/../test_helper'
>
> rails_lib = "#{RAILS_ROOT}/lib"
> bdrb_worker = "#{RAILS_ROOT}/lib/workers"
> $:.unshift(File.dirname(__FILE__),rails_lib,bdrb_worker)
>
>
> require "mocha"
> require "edit_message_worker"
>
>
> class TestEditMessageWorker < Test::Unit::TestCase
>   def setup
>     @edit_worker = EditMessageWorker.new
>     @logger = mock
>     @logger.stubs(:info).returns(true)
>     @edit_worker.logger = @logger
>     @edit_worker.stubs(:exit).returns(true)
>   end
>   def test_do_work
>
>   end
> end
>

I have also patched bdrb to generate test cases for workers on above
lines. I think, it was simply too much to load entire bdrb to run our
puny tests, and hence i took the shortcut. Works for me.


More information about the Backgroundrb-devel mailing list