Sha256: 0248c376131d349b902de999154a592aa03c46e15187c8e85658f0bb3d26d5d5

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'gush'
require 'pry'
require 'sidekiq/testing'
require 'bbq/spawn'

Sidekiq::Logging.logger = nil

class Prepare < Gush::Job;  end
class FetchFirstJob < Gush::Job; end
class FetchSecondJob < Gush::Job; end
class PersistFirstJob < Gush::Job; end
class PersistSecondJob < Gush::Job; end
class NormalizeJob < Gush::Job; end

GUSHFILE  = Pathname.new(__FILE__).parent.join("Gushfile.rb")

TestLogger = Struct.new(:jid, :name) do
  def <<(msg)
  end
end

class TestLoggerBuilder < Gush::LoggerBuilder
  def build
    TestLogger.new(jid, job.name)
  end
end

class TestWorkflow < Gush::Workflow
  def configure
    logger_builder TestLoggerBuilder

    run Prepare

    run NormalizeJob

    run FetchFirstJob,   after: Prepare
    run PersistFirstJob, after: FetchFirstJob, before: NormalizeJob

    run FetchSecondJob,  after: Prepare, before: NormalizeJob
  end
end

module GushHelpers
  REDIS_URL = "redis://localhost:33333/"

  def redis
    @redis ||= Redis.new(url: REDIS_URL)
  end

  def client
    @client ||= Gush::Client.new(Gush::Configuration.new(gushfile: GUSHFILE, redis_url: REDIS_URL))
  end
end

RSpec.configure do |config|
  config.include GushHelpers

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  orchestrator = Bbq::Spawn::Orchestrator.new

  config.before(:suite) do
    config_path = Pathname.pwd + "spec/redis.conf"
    executor = Bbq::Spawn::Executor.new("redis-server", config_path.to_path)
    orchestrator.coordinate(executor, host: '127.0.0.1', port: 33333)
    orchestrator.start
  end

  config.after(:suite) do
    orchestrator.stop
  end

  config.after(:each) do
    Sidekiq::Worker.clear_all
    redis.flushdb
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gush-0.0.1 spec/spec_helper.rb