spec/spec_helper.rb in message_bus-2.1.6 vs spec/spec_helper.rb in message_bus-2.2.0.pre

- old
+ new

@@ -6,24 +6,36 @@ require 'minitest/autorun' require 'minitest/spec' backend = (ENV['MESSAGE_BUS_BACKEND'] || :redis).to_sym -MESSAGE_BUS_CONFIG = {:backend=>backend} +MESSAGE_BUS_CONFIG = { backend: backend } require "message_bus/backends/#{backend}" PUB_SUB_CLASS = MessageBus::BACKENDS.fetch(backend) -if backend == :postgres - MESSAGE_BUS_CONFIG.merge!(:backend_options=>{:user=>ENV['PGUSER'] || ENV['USER'], :dbname=>ENV['PGDATABASE'] || 'message_bus_test'}) +case backend +when :redis + MESSAGE_BUS_CONFIG.merge!(url: ENV['REDISURL']) +when :postgres + MESSAGE_BUS_CONFIG.merge!(backend_options: { host: ENV['PGHOST'], user: ENV['PGUSER'] || ENV['USER'], password: ENV['PGPASSWORD'], dbname: ENV['PGDATABASE'] || 'message_bus_test' }) end puts "Running with backend: #{backend}" -def wait_for(timeout_milliseconds=2000) +def wait_for(timeout_milliseconds = 2000) timeout = (timeout_milliseconds + 0.0) / 1000 finish = Time.now + timeout Thread.new do while Time.now < finish && !yield sleep(0.001) end end.join +end +def test_only(*backends) + backend = MESSAGE_BUS_CONFIG[:backend] + skip "Test doesn't apply to #{backend}" unless backends.include?(backend) +end + +def test_never(*backends) + backend = MESSAGE_BUS_CONFIG[:backend] + skip "Test doesn't apply to #{backend}" if backends.include?(backend) end