Sha256: 8d72d00968df0bde79abbb2a1f778ff88c1d50af2d5fb7af8de64241d9dde649
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
require File.dirname(__FILE__) + '/test_helper' require File.dirname(__FILE__) + '/../lib/sweatshop' class SweatshopTest < Test::Unit::TestCase Sweatshop.workers = [] class HelloWorker < Sweatshop::Worker def hello(name) "Hi, #{name}" end end class GroupedWorker < Sweatshop::Worker queue_group :foo end should "group workers" do assert_equal [HelloWorker, GroupedWorker], Sweatshop.workers_in_group(:all) assert_equal [HelloWorker], Sweatshop.workers_in_group(:default) assert_equal [GroupedWorker], Sweatshop.workers_in_group(:foo) end should "synch call" do worker = HelloWorker.new assert_equal "Hi, Amos", worker.hello('Amos') end should "assign a uid" do Sweatshop.logger = :silent Sweatshop.config['enable'] = false uid = HelloWorker.async_hello('Amos') assert_not_nil uid end should "have before task" do HelloWorker.before_task do "hello" end assert_equal "hello", HelloWorker.before_task.call end should "have after task" do HelloWorker.after_task do "goodbye" end assert_equal "goodbye", HelloWorker.after_task.call end should "exception handler" do Sweatshop.logger = :silent exception = nil HelloWorker.on_exception do |e| exception = e end HelloWorker.do_task(nil) assert_equal NoMethodError, exception.class end should "chain before tasks" do MESSAGES = [] class BaseWorker < Sweatshop::Worker before_task do |task| MESSAGES << 'base' end end class SubWorker < BaseWorker before_task do |task| MESSAGES << 'sub' end end SubWorker.call_before_task('foo') assert_equal ['base', 'sub'], MESSAGES Sweatshop.workers.delete(BaseWorker) Sweatshop.workers.delete(SubWorker) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sweatshop-1.5.2 | test/test_sweatshop.rb |
sweatshop-1.5.1 | test/test_sweatshop.rb |
sweatshop-1.5.0 | test/test_sweatshop.rb |