spec/spec_helper.rb in gush-0.0.1 vs spec/spec_helper.rb in gush-0.1

- old
+ new

@@ -1,36 +1,23 @@ require 'gush' require 'pry' require 'sidekiq/testing' -require 'bbq/spawn' +Sidekiq::Testing.fake! Sidekiq::Logging.logger = nil -class Prepare < Gush::Job; end +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 @@ -38,40 +25,50 @@ run FetchSecondJob, after: Prepare, before: NormalizeJob end end -module GushHelpers - REDIS_URL = "redis://localhost:33333/" +class Redis + def publish(*) + end +end +REDIS_URL = "redis://localhost:6379/12" + +module GushHelpers def redis @redis ||= Redis.new(url: REDIS_URL) end +end - def client - @client ||= Gush::Client.new(Gush::Configuration.new(gushfile: GUSHFILE, redis_url: REDIS_URL)) +RSpec::Matchers.define :have_jobs do |flow, jobs| + match do |actual| + expected = jobs.map do |job| + hash_including("args" => include(flow, job)) + end + expect(Gush::Worker.jobs).to match_array(expected) end + + failure_message do |actual| + "expected queue to have #{jobs}, but instead has: #{actual.jobs.map{ |j| j["args"][1]}}" + 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 + config.before(:each) do + Gush.configure do |config| + config.redis_url = REDIS_URL + config.environment = 'test' + config.gushfile = GUSHFILE + end end - config.after(:suite) do - orchestrator.stop - end config.after(:each) do Sidekiq::Worker.clear_all redis.flushdb end