[Backgroundrb-devel] unit tests?

hemant gethemant at gmail.com
Thu Apr 5 18:53:29 EDT 2007


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






-- 
gnufied
-----------
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.
http://people.inxsasia.com/~hemant


More information about the Backgroundrb-devel mailing list