features/support/test_runner.rb in message-driver-0.1.0 vs features/support/test_runner.rb in message-driver-0.2.0.rc1

- old
+ new

@@ -1,43 +1,66 @@ -require 'message_driver' - class TestRunner - include MessageDriver::MessagePublisher + include MessageDriver::Client include RSpec::Matchers attr_accessor :raised_error + attr_accessor :current_feature_file - def config_broker(src) - instance_eval(src) + def run_config_code(src) + instance_eval(src, current_feature_file) end def run_test_code(src) begin - instance_eval(src) - rescue Exception => e + instance_eval(src, current_feature_file) + rescue => e @raised_error = e end end - def fetch_messages(destination) + def fetch_messages(destination_name) + destination = fetch_destination(destination_name) + pause_if_needed + result = [] + begin + msg = destination.pop_message + result << msg unless msg.nil? + end until msg.nil? + result + end + + def purge_destination(destination_name) + destination = fetch_destination(destination_name) + if destination.respond_to? :purge + destination.purge + else + fetch_messages(destination) + end + end + + def fetch_destination(destination) case destination when String, Symbol - fetch_messages(MessageDriver::Broker.find_destination(destination)) + MessageDriver::Broker.find_destination(destination) when MessageDriver::Destination::Base - result = [] - begin - msg = destination.pop_message - result << msg unless msg.nil? - end until msg.nil? - result + destination else - raise "didn't understand destination #{destination}" + raise "didn't understand destination #{destination.inspect}" end end def publish_table_to_destination(destination, table) table.hashes.each do |msg| destination.publish(msg[:body], msg[:headers]||{}, msg[:properties]||{}) + end + end + + def pause_if_needed(seconds=0.1) + seconds *= 10 if ENV['CI'] == 'true' + case BrokerConfig.current_adapter + when :in_memory + else + sleep seconds end end end module KnowsMyTestRunner