module RabbitFeed::TestingSupport

Attributes

published_events[RW]

Public Instance Methods

capture_published_events(rspec_config) click to toggle source
# File lib/rabbit_feed/testing_support.rb, line 17
def capture_published_events(rspec_config)
  rspec_config.before :each do
    TestingSupport.capture_published_events_in_context(self)
  end
end
capture_published_events_in_context(context) click to toggle source
# File lib/rabbit_feed/testing_support.rb, line 23
def capture_published_events_in_context(context)
  TestingSupport.published_events = []
  mock_connection = context.double(:rabbitmq_connection)
  context.allow(RabbitFeed::ProducerConnection).to context.receive(:instance).and_return(mock_connection)
  context.allow(mock_connection).to context.receive(:publish) do |serialized_event, _routing_key|
    TestingSupport.published_events << (Event.deserialize serialized_event)
  end
end
include_support(rspec_config) click to toggle source
# File lib/rabbit_feed/testing_support.rb, line 32
def include_support(rspec_config)
  rspec_config.include(RabbitFeed::TestingSupport::TestingHelpers)
end
setup(rspec_config) click to toggle source
# File lib/rabbit_feed/testing_support.rb, line 10
def setup(rspec_config)
  require 'rabbit_feed/testing_support/rspec_matchers/publish_event'
  RabbitFeed.environment ||= 'test'
  capture_published_events rspec_config
  include_support rspec_config
end