Module: RabbitFeed::TestingSupport

Extended by:
TestingSupport
Included in:
TestingSupport
Defined in:
lib/rabbit_feed/testing_support.rb,
lib/rabbit_feed/testing_support/testing_helpers.rb,
lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb,
lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb

Defined Under Namespace

Modules: RSpecMatchers, TestingHelpers Classes: TestRabbitFeedConsumer

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#published_eventsObject

Returns the value of attribute published_events.



9
10
11
# File 'lib/rabbit_feed/testing_support.rb', line 9

def published_events
  @published_events
end

Instance Method Details

#capture_published_events(rspec_config) ⇒ Object



17
18
19
20
21
# 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) ⇒ Object



23
24
25
26
27
28
29
30
# 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) ⇒ Object



32
33
34
35
# File 'lib/rabbit_feed/testing_support.rb', line 32

def include_support rspec_config
  rspec_config.include(RabbitFeed::TestingSupport::RSpecMatchers)
  rspec_config.include(RabbitFeed::TestingSupport::TestingHelpers)
end

#setup(rspec_config) ⇒ Object



11
12
13
14
15
# File 'lib/rabbit_feed/testing_support.rb', line 11

def setup rspec_config
  RabbitFeed.environment ||= 'test'
  capture_published_events rspec_config
  include_support rspec_config
end