Sha256: bd242d83fb68ad856a36722ab46199d0b0686ee7ca5331aff55c69abd6ec7ca9

Contents?: true

Size: 1.55 KB

Versions: 6

Compression:

Stored size: 1.55 KB

Contents

require 'gush'
require 'pry'
require 'sidekiq/testing'

Sidekiq::Testing.fake!
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")

class TestWorkflow < Gush::Workflow
  def configure
    run Prepare

    run NormalizeJob

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

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

class Redis
  def publish(*)
  end
end

REDIS_URL = "redis://localhost:6379/12"

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

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

  config.before(:each) do
    Gush.configure do |config|
      config.redis_url = REDIS_URL
      config.environment = 'test'
      config.gushfile = GUSHFILE
    end
  end


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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gush-0.2.2 spec/spec_helper.rb
gush-0.2.1 spec/spec_helper.rb
gush-0.2.0 spec/spec_helper.rb
gush-0.1.2 spec/spec_helper.rb
gush-0.1.1 spec/spec_helper.rb
gush-0.1 spec/spec_helper.rb