Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Configuration revamped inc. renaming drivers to adapters

  • Loading branch information...
commit 0b762c7b2c277d3c5b57483fb1c417502784680e 1 parent 3d2bc5c
@cavalle authored
Showing with 275 additions and 249 deletions.
  1. +2 −1  .gitignore
  2. +6 −8 README.md
  3. +1 −10 lib/eventwire.rb
  4. +11 −0 lib/eventwire/adapters.rb
  5. +1 −1  lib/eventwire/{drivers → adapters}/amqp.rb
  6. +1 −1  lib/eventwire/{drivers → adapters}/bunny.rb
  7. +2 −2 lib/eventwire/{drivers → adapters}/in_process.rb
  8. +1 −1  lib/eventwire/{drivers → adapters}/mongo.rb
  9. +1 −1  lib/eventwire/{drivers → adapters}/redis.rb
  10. +19 −28 lib/eventwire/configuration.rb
  11. +0 −11 lib/eventwire/drivers.rb
  12. +15 −8 lib/eventwire/middleware/error_handler.rb
  13. +12 −8 lib/eventwire/middleware/logger.rb
  14. +1 −1  lib/eventwire/subscriber.rb
  15. +6 −5 spec/acceptance/project_management_spec.rb
  16. +2 −2 spec/integration/{drivers/drivers_helper.rb → adapters/adapters_helper.rb}
  17. +6 −0 spec/integration/adapters/amqp_spec.rb
  18. +6 −0 spec/integration/adapters/bunny_spec.rb
  19. +5 −0 spec/integration/adapters/in_process_spec.rb
  20. +6 −0 spec/integration/adapters/mongo_spec.rb
  21. +6 −0 spec/integration/adapters/redis_spec.rb
  22. +0 −6 spec/integration/drivers/amqp_spec.rb
  23. +0 −6 spec/integration/drivers/bunny_spec.rb
  24. +0 −5 spec/integration/drivers/in_process_spec.rb
  25. +0 −6 spec/integration/drivers/mongo_spec.rb
  26. +0 −6 spec/integration/drivers/redis_spec.rb
  27. +1 −1  spec/spec_helper.rb
  28. +34 −0 spec/support/adapters.rb
  29. +0 −34 spec/support/drivers.rb
  30. +11 −1 spec/support/helpers.rb
  31. +105 −20 spec/unit/configuration_spec.rb
  32. +0 −59 spec/unit/eventwire_spec.rb
  33. +4 −4 spec/unit/middleware/error_handler_spec.rb
  34. +2 −2 spec/unit/middleware/logger_spec.rb
  35. +5 −7 spec/unit/publisher_spec.rb
  36. +3 −4 spec/unit/subscriber_spec.rb
View
3  .gitignore
@@ -5,4 +5,5 @@ pkg/*
doc/*
.yardoc
*.rdb
-.bin
+.bin
+*.swp
View
14 README.md
@@ -1,6 +1,5 @@
# Eventwire: Event Collaboration for the Masses[ ![Build Status](https://secure.travis-ci.org/cavalle/eventwire.png?branch=master)](http://travis-ci.org/cavalle/eventwire)
-
Eventwire is a generic and simple interface to various backends (AMQP, Redis, ZeroMQ, MongoDB) to help building event-driven systems
_**WARNING:** This gem is in a very early stage of development. No first version has been released yet. That means that some of things described in this file might not be implemented, and those which are, might not be production ready._
@@ -81,15 +80,14 @@ It provides two modules, `Eventwire::Publisher` and `Eventwire::Subscriber`, whi
See the code examples above.
-### Drivers
+### Adapters
-Committing to that simple generic interface, Eventwire includes various drivers for different backends. Developers can choose which one to use depending on what is available in their current infrastructure or what are their needs in terms of reliability, performance or scalability. Currently five drivers are provided:
+Committing to that simple generic interface, Eventwire includes various drivers for different backends. Developers can choose which one to use depending on what is available in their current infrastructure or what are their needs in terms of reliability, performance or scalability. Currently four drivers are provided:
-- `Eventwire::Driver::InProcess` (for testing and development mainly)
-- `Eventwire::Driver::AMQP` (default driver. Requires an AMQP server like RabbitMQ)
-- `Eventwire::Driver::Redis` (experimental. Requires a Redis server)
-- `Eventwire::Driver::Zero` (experimental. Uses ØMQ)
-- `Eventwire::Driver::Mongo` (experimental. Requires a MongoDB server)
+- `Eventwire::Adapter::InProcess` (for testing and development mainly)
+- `Eventwire::Adapter::AMQP` (default driver. Requires an AMQP server like RabbitMQ)
+- `Eventwire::Adapter::Redis` (experimental. Requires a Redis server)
+- `Eventwire::Adapter::Mongo` (experimental. Requires a MongoDB server)
### Workers
View
11 lib/eventwire.rb
@@ -2,7 +2,7 @@
require 'eventwire/configuration'
require 'eventwire/publisher'
require 'eventwire/subscriber'
-require 'eventwire/drivers'
+require 'eventwire/adapters'
require 'eventwire/middleware'
module Eventwire
@@ -18,7 +18,6 @@ def configuration
end
def driver
- configuration.decorate unless configuration.decorated?
configuration.driver
end
@@ -29,14 +28,6 @@ def logger
def namespace
configuration.namespace
end
-
- def middleware
- configuration.middleware
- end
-
- def error_handler
- configuration.on_error
- end
def start_worker
driver.start
View
11 lib/eventwire/adapters.rb
@@ -0,0 +1,11 @@
+require 'json'
+
+module Eventwire
+ module Adapters
+ autoload :InProcess, 'eventwire/adapters/in_process'
+ autoload :AMQP, 'eventwire/adapters/amqp'
+ autoload :Bunny, 'eventwire/adapters/bunny'
+ autoload :Redis, 'eventwire/adapters/redis'
+ autoload :Mongo, 'eventwire/adapters/mongo'
+ end
+end
View
2  lib/eventwire/drivers/amqp.rb → lib/eventwire/adapters/amqp.rb
@@ -1,7 +1,7 @@
require 'bunny'
require 'amqp'
-class Eventwire::Drivers::AMQP
+class Eventwire::Adapters::AMQP
def publish(event_name, event_data = nil)
Bunny.run do |mq|
mq.exchange(event_name.to_s, :type => :fanout).publish(event_data)
View
2  lib/eventwire/drivers/bunny.rb → lib/eventwire/adapters/bunny.rb
@@ -1,6 +1,6 @@
require 'bunny'
-class Eventwire::Drivers::Bunny
+class Eventwire::Adapters::Bunny
def publish(event_name, event_data = nil)
Bunny.run do |mq|
View
4 lib/eventwire/drivers/in_process.rb → lib/eventwire/adapters/in_process.rb
@@ -1,4 +1,4 @@
-class Eventwire::Drivers::InProcess
+class Eventwire::Adapters::InProcess
def initialize
@handlers = {}
end
@@ -20,4 +20,4 @@ def subscribe(event_name, handler_id, &handler)
def start; end
def stop; end
def purge; end
-end
+end
View
2  lib/eventwire/drivers/mongo.rb → lib/eventwire/adapters/mongo.rb
@@ -1,6 +1,6 @@
require 'mongo'
-class Eventwire::Drivers::Mongo
+class Eventwire::Adapters::Mongo
DB_NAME = 'broker'
def initialize
View
2  lib/eventwire/drivers/redis.rb → lib/eventwire/adapters/redis.rb
@@ -1,7 +1,7 @@
require 'redis'
require 'em-redis'
-class Eventwire::Drivers::Redis
+class Eventwire::Adapters::Redis
def initialize
@handlers = []
end
View
47 lib/eventwire/configuration.rb
@@ -1,46 +1,37 @@
module Eventwire
class Configuration
- attr_reader :driver, :error_handler
-
- attr_accessor :middleware, :namespace, :logger
+ attr_reader :middleware, :error_handler
+ attr_accessor :namespace, :logger
def initialize
- @driver = Drivers::InProcess.new
- @logger = Logger.new(nil)
- @error_handler = lambda{|ex| }
- @middleware = [[Eventwire::Middleware::ErrorHandler, {:error_handler => error_handler, :logger => logger}],
- [Eventwire::Middleware::Logger, {:logger => logger}],
- Eventwire::Middleware::JSONSerializer,
- Eventwire::Middleware::DataObjects]
- @decorated = false
+ @adapter = Adapters::AMQP.new
+ @logger = Logger.new($stdout)
+ @error_handler = lambda {|ex| }
+ @middleware = [
+ [ Eventwire::Middleware::ErrorHandler, self ],
+ [ Eventwire::Middleware::Logger, self ],
+ Eventwire::Middleware::JSONSerializer,
+ Eventwire::Middleware::DataObjects
+ ]
end
- def driver=(driver)
- klass = Drivers.const_get(driver.to_sym) if driver.respond_to?(:to_sym)
- @driver = klass ? klass.new : driver
+ def adapter=(adapter)
+ klass = Adapters.const_get(adapter.to_sym) if adapter.respond_to?(:to_sym)
+ @adapter = klass ? klass.new : adapter
end
def on_error(&block)
@error_handler = block
end
- def decorated?
- !!@decorated
- end
-
- def decorate
- @decorated = true
- @driver = middleware.inject(driver) do |driver, args|
- args = Array(args)
+ def driver
+ @middleware.inject(@adapter) do |driver, args|
+ args = Array(args).clone
klass = args.shift
- if args && args.any?
- klass.new(driver, *args)
- else
- klass.new(driver)
- end
+ klass.new(driver, *args)
end
end
end
-end
+end
View
11 lib/eventwire/drivers.rb
@@ -1,11 +0,0 @@
-require 'json'
-
-module Eventwire
- module Drivers
- autoload :InProcess, 'eventwire/drivers/in_process'
- autoload :AMQP, 'eventwire/drivers/amqp'
- autoload :Bunny, 'eventwire/drivers/bunny'
- autoload :Redis, 'eventwire/drivers/redis'
- autoload :Mongo, 'eventwire/drivers/mongo'
- end
-end
View
23 lib/eventwire/middleware/error_handler.rb
@@ -1,11 +1,9 @@
module Eventwire
module Middleware
class ErrorHandler < Base
-
- def initialize(app, options = {})
+ def initialize(app, config = nil)
super(app)
- @error_handler = options.delete(:error_handler) || lambda{|ex|}
- @logger = options.delete(:logger) || ::Logger.new(nil)
+ @config = config
end
def subscribe(event_name, handler_id, &handler)
@@ -13,12 +11,21 @@ def subscribe(event_name, handler_id, &handler)
begin
handler.call(data)
rescue Exception => ex
- @logger.error "\nAn error occurred: `#{ex.message}`\n#{ex.backtrace.join("\n")}\n"
- @error_handler.call(ex)
+ logger.error "\nAn error occurred: `#{ex.message}`\n#{ex.backtrace.join("\n")}\n"
+ error_handler.call(ex)
end
end
end
-
+
+ private
+
+ def error_handler
+ @config.error_handler
+ end
+
+ def logger
+ @config.logger
+ end
end
end
-end
+end
View
20 lib/eventwire/middleware/logger.rb
@@ -1,28 +1,32 @@
module Eventwire
module Middleware
class Logger < Base
-
- def initialize(app, options = {})
+ def initialize(app, config)
super(app)
- @logger = options.delete(:logger) || ::Logger.new(nil)
+ @config = config
end
def subscribe(event_name, handler_id, &handler)
@app.subscribe event_name, handler_id do |data|
begin
- @logger.info "Starting to process `#{event_name}` with handler `#{handler_id}` and data `#{data.inspect}`"
+ logger.info "Starting to process `#{event_name}` with handler `#{handler_id}` and data `#{data.inspect}`"
handler.call data
ensure
- @logger.info "End processing `#{event_name}`"
+ logger.info "End processing `#{event_name}`"
end
end
end
def publish(event_name, event_data = nil)
@app.publish event_name, event_data
- @logger.info "Event published `#{event_name}` with data `#{event_data.inspect}`"
+ logger.info "Event published `#{event_name}` with data `#{event_data.inspect}`"
end
-
+
+ private
+
+ def logger
+ @config.logger
+ end
end
end
-end
+end
View
2  lib/eventwire/subscriber.rb
@@ -36,4 +36,4 @@ def increment_handler_counter
end
end
end
-end
+end
View
11 spec/acceptance/project_management_spec.rb
@@ -3,15 +3,16 @@
describe 'Project Management System' do
- drivers = %w{InProcess AMQP Redis}
+ adapters = %w{InProcess AMQP Redis}
- drivers.each do |driver|
+ adapters.each do |adapter|
- with_driver driver do
+ with_adapter adapter do
before do
Eventwire.configure do |c|
- c.driver = driver
+ c.adapter = adapter
+ c.logger = Logger.new(nil)
end
load_environment
@@ -89,4 +90,4 @@ def purge
Eventwire.driver.purge
end
-end
+end
View
4 spec/integration/drivers/drivers_helper.rb → spec/integration/adapters/adapters_helper.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'timeout'
-shared_examples_for 'a driver with single-process support' do
+shared_examples_for 'a adapter with single-process support' do
def start_worker
@t = Thread.new { subject.start }
@@ -69,7 +69,7 @@ def start_worker
end
-shared_examples_for 'a driver with multi-process support' do
+shared_examples_for 'a adapter with multi-process support' do
before do
initialize_proccesses
View
6 spec/integration/adapters/amqp_spec.rb
@@ -0,0 +1,6 @@
+require 'integration/adapters/adapters_helper'
+
+describe_adapter Eventwire::Adapters::AMQP do
+ it_should_behave_like 'a adapter with single-process support'
+ it_should_behave_like 'a adapter with multi-process support'
+end
View
6 spec/integration/adapters/bunny_spec.rb
@@ -0,0 +1,6 @@
+require 'integration/adapters/adapters_helper'
+
+describe_adapter Eventwire::Adapters::Bunny do
+ it_should_behave_like 'a adapter with single-process support'
+ it_should_behave_like 'a adapter with multi-process support'
+end
View
5 spec/integration/adapters/in_process_spec.rb
@@ -0,0 +1,5 @@
+require 'integration/adapters/adapters_helper'
+
+describe_adapter Eventwire::Adapters::InProcess do
+ it_should_behave_like 'a adapter with single-process support'
+end
View
6 spec/integration/adapters/mongo_spec.rb
@@ -0,0 +1,6 @@
+require 'integration/adapters/adapters_helper'
+
+describe_adapter Eventwire::Adapters::Mongo do
+ it_should_behave_like 'a adapter with single-process support'
+ it_should_behave_like 'a adapter with multi-process support'
+end
View
6 spec/integration/adapters/redis_spec.rb
@@ -0,0 +1,6 @@
+require 'integration/adapters/adapters_helper'
+
+describe_adapter Eventwire::Adapters::Redis do
+ it_should_behave_like 'a adapter with single-process support'
+ it_should_behave_like 'a adapter with multi-process support'
+end
View
6 spec/integration/drivers/amqp_spec.rb
@@ -1,6 +0,0 @@
-require 'integration/drivers/drivers_helper'
-
-describe_driver Eventwire::Drivers::AMQP do
- it_should_behave_like 'a driver with single-process support'
- it_should_behave_like 'a driver with multi-process support'
-end
View
6 spec/integration/drivers/bunny_spec.rb
@@ -1,6 +0,0 @@
-require 'integration/drivers/drivers_helper'
-
-describe_driver Eventwire::Drivers::Bunny do
- it_should_behave_like 'a driver with single-process support'
- it_should_behave_like 'a driver with multi-process support'
-end
View
5 spec/integration/drivers/in_process_spec.rb
@@ -1,5 +0,0 @@
-require 'integration/drivers/drivers_helper'
-
-describe_driver Eventwire::Drivers::InProcess do
- it_should_behave_like 'a driver with single-process support'
-end
View
6 spec/integration/drivers/mongo_spec.rb
@@ -1,6 +0,0 @@
-require 'integration/drivers/drivers_helper'
-
-describe_driver Eventwire::Drivers::Mongo do
- it_should_behave_like 'a driver with single-process support'
- it_should_behave_like 'a driver with multi-process support'
-end
View
6 spec/integration/drivers/redis_spec.rb
@@ -1,6 +0,0 @@
-require 'integration/drivers/drivers_helper'
-
-describe_driver Eventwire::Drivers::Redis do
- it_should_behave_like 'a driver with single-process support'
- it_should_behave_like 'a driver with multi-process support'
-end
View
2  spec/spec_helper.rb
@@ -5,7 +5,7 @@
Bundler.require
-include Drivers
+include Adapters
def sleep(time)
factor = ENV['SLEEP_FACTOR'] || 1
View
34 spec/support/adapters.rb
@@ -0,0 +1,34 @@
+module Adapters
+ def describe_adapter(adapter_class, &block)
+ adapter = adapter_class.to_s.gsub(/^.*::/, '')
+ describe(adapter_class, &block) if should_be_tested?(adapter)
+ end
+
+ def with_adapter(adapter, &block)
+ if should_be_tested?(adapter)
+ context "using the #{adapter} adapter", &block
+ end
+ end
+
+ def should_be_tested?(adapter)
+ return true if selected.nil? && excluded.nil?
+ return selected?(adapter) if selected
+ return !excluded?(adapter) if excluded
+ end
+
+ def selected
+ ENV['ONLY'].split(',') if ENV['ONLY']
+ end
+
+ def excluded
+ ENV['EXCEPT'].split(',') if ENV['EXCEPT']
+ end
+
+ def selected?(adapter)
+ selected.include?(adapter)
+ end
+
+ def excluded?(adapter)
+ excluded.include?(adapter)
+ end
+end
View
34 spec/support/drivers.rb
@@ -1,34 +0,0 @@
-module Drivers
- def describe_driver(driver_class, &block)
- driver = driver_class.to_s.gsub(/^.*::/, '')
- describe(driver_class, &block) if should_be_tested?(driver)
- end
-
- def with_driver(driver, &block)
- if should_be_tested?(driver)
- context "using the #{driver} driver", &block
- end
- end
-
- def should_be_tested?(driver)
- return true if selected.nil? && excluded.nil?
- return selected?(driver) if selected
- return !excluded?(driver) if excluded
- end
-
- def selected
- ENV['ONLY'].split(',') if ENV['ONLY']
- end
-
- def excluded
- ENV['EXCEPT'].split(',') if ENV['EXCEPT']
- end
-
- def selected?(driver)
- selected.include?(driver)
- end
-
- def excluded?(driver)
- excluded.include?(driver)
- end
-end
View
12 spec/support/helpers.rb
@@ -19,4 +19,14 @@ def eventually(timeout = 1, &block)
# Expectations must keep being met for at least 0.5 secs
5.times { block.call; sleep 0.1 }
end
-end
+
+ def with_stdout(io)
+ original = $stdout
+ begin
+ $stdout = io
+ yield(io)
+ ensure
+ $stdout = original
+ end
+ end
+end
View
125 spec/unit/configuration_spec.rb
@@ -2,40 +2,125 @@
require 'spec_helper'
describe Eventwire::Configuration do
- describe 'defaults' do
- subject { Eventwire::Configuration.new }
+ describe 'driver' do
+ context 'without middleware' do
+ before do
+ subject.middleware.clear
+ end
- it 'driver is InProcess' do
- subject.driver.should be_an_instance_of(Eventwire::Drivers::InProcess)
- end
+ it 'returns a AMQP adapter if none is set' do
+ subject.driver.should be_instance_of(Eventwire::Adapters::AMQP)
+ end
+
+ it 'returns the adapter if one is set' do
+ adapter = Object.new
+ subject.adapter = adapter
+ subject.driver.should == adapter
+ end
- it 'logger is a Logger' do
- subject.logger.should be_an_instance_of(Logger)
+ it 'returns an instance of the adapter if its name is set' do
+ Eventwire::Adapters::AwesomeAdapter = Class.new
+ subject.adapter = :AwesomeAdapter
+ subject.driver.should be_an_instance_of(Eventwire::Adapters::AwesomeAdapter)
+ end
end
- it 'namespace is nil' do
- subject.namespace.should be_nil
+ context 'with middleware' do
+ it 'builds a driver decorating the adapter with one middleware' do
+ adapter = Object.new
+ middleware = Struct.new(:app)
+
+ subject.adapter = adapter
+ subject.middleware.replace [middleware]
+
+ subject.driver.should be_instance_of(middleware)
+ subject.driver.app.should == adapter
+ end
+
+ it 'builds a driver decorating the adapter with one middleware with options' do
+ middleware = Struct.new(:app, :options)
+ options = {}
+
+ subject.middleware.replace [[middleware, options]]
+
+ subject.driver.options.should == options
+ end
+
+ it 'builds a driver decorating the adapter with more than one middlewares' do
+ adapter = Object.new
+ middleware1 = Struct.new(:app)
+ middleware2 = Struct.new(:app)
+
+ subject.adapter = adapter
+ subject.middleware.replace [middleware1, middleware2]
+
+ subject.driver.should be_instance_of(middleware2)
+ subject.driver.app.should be_instance_of(middleware1)
+ subject.driver.app.app.should == adapter
+ end
end
end
- describe 'override' do
- subject { Eventwire::Configuration.new }
+ describe 'middleware' do
+ it 'contains ErrorHandler by default' do
+ subject.middleware.should include([Eventwire::Middleware::ErrorHandler, subject])
+ end
- it 'driver can be changed to other driver given a class of it' do
- driver = Object.new
+ it 'contains Logger by default' do
+ subject.middleware.should include([Eventwire::Middleware::Logger, subject])
+ end
- subject.driver = driver
+ it 'contains JSONSerializer by default' do
+ subject.middleware.should include(Eventwire::Middleware::JSONSerializer)
+ end
- subject.driver.should == driver
+ it 'contains DataObjects after Serializer by default' do
+ subject.middleware.should include(Eventwire::Middleware::DataObjects)
+ subject.middleware.index(Eventwire::Middleware::DataObjects).should be >
+ subject.middleware.index(Eventwire::Middleware::JSONSerializer)
+ end
+ end
+
+ describe 'logger' do
+ it 'returns a stdout logger by default' do
+ with_stdout(StringIO.new) do |io|
+ subject.logger.error 'hello'
+ io.string.should == "hello\n"
+ end
end
- it 'driver can be changed to other driver given its name' do
- Eventwire::Drivers::AwesomeDriver = Class.new
+ it 'returns a specified logger' do
+ logger = Object.new
+ subject.logger = logger
+ subject.logger.should == logger
+ end
+
+ it 'is used in the default logger middleware' do
+ logger = Object.new
+ subject.logger = logger
+ end
+ end
- subject.driver = :AwesomeDriver
+ describe 'namespace' do
+ it 'is not set by default' do
+ subject.namespace.should be_blank
+ end
- subject.driver.should be_an_instance_of(Eventwire::Drivers::AwesomeDriver)
+ it 'returns a specified logger' do
+ subject.namespace = 'MyAppName'
+ subject.namespace.should == 'MyAppName'
end
end
-end
+ describe 'error_handler' do
+ it 'returns a trivial lambda' do
+ subject.error_handler.should be_instance_of(Proc)
+ end
+
+ it 'returns a specified lambda' do
+ handler = lambda {|ex|}
+ subject.on_error &handler
+ subject.error_handler.should == handler
+ end
+ end
+end
View
59 spec/unit/eventwire_spec.rb
@@ -1,59 +0,0 @@
-# encoding: UTF-8
-require 'spec_helper'
-
-describe Eventwire do
-
- it 'decorates the driver with one middleware' do
- middleware = Struct.new(:app)
- driver = Object.new
-
- Eventwire.middleware.replace [middleware]
- Eventwire.configure do |config|
- config.driver = driver
- end
-
- Eventwire.driver.should be_an_instance_of(middleware)
- Eventwire.driver.app.should be(driver)
- end
-
- it 'decorates the driver with one middleware and its options' do
- middleware = Struct.new(:app, :options)
- driver = Object.new
- options = {:logger => Logger.new(nil)}
-
- Eventwire.middleware.replace [[middleware, options]]
- Eventwire.configure do |config|
- config.driver = driver
- end
-
- Eventwire.driver.should be_an_instance_of(middleware)
- Eventwire.driver.app.should be(driver)
- Eventwire.driver.options.should be(options)
- end
-
- it 'decorates the driver with more than one middlewares' do
- middleware1 = Struct.new(:app)
- middleware2 = Struct.new(:app)
- driver = Object.new
-
- Eventwire.middleware.replace [middleware1, middleware2]
- Eventwire.configure do |config|
- config.driver = driver
- end
-
- Eventwire.driver.should be_an_instance_of(middleware2)
- Eventwire.driver.app.should be_an_instance_of(middleware1)
- Eventwire.driver.app.app.should be(driver)
- end
-
- describe '#driver' do
- it 'decorates the driver when access to it' do
- Eventwire.configuration.should_not be_decorated
-
- Eventwire.driver
-
- Eventwire.configuration.should be_decorated
- end
- end
-
-end
View
8 spec/unit/middleware/error_handler_spec.rb
@@ -4,7 +4,7 @@
describe Eventwire::Middleware::ErrorHandler do
let(:app) { mock }
- subject { Eventwire::Middleware::ErrorHandler.new(app) }
+ subject { Eventwire::Middleware::ErrorHandler.new(app, stub(:error_handler => proc {}, :logger => Logger.new(nil))) }
describe 'subscribe' do
it 'should call app’s subscribe' do
@@ -24,7 +24,7 @@
end
context 'when error_handler is present' do
- subject { Eventwire::Middleware::ErrorHandler.new(app, :error_handler => lambda { |e| @error = e }) }
+ subject { Eventwire::Middleware::ErrorHandler.new(app, stub(:error_handler => lambda { |e| @error = e }, :logger => Logger.new(nil))) }
it 'should make the handler run the block' do
@error = nil
@@ -43,7 +43,7 @@
context 'when logger is present' do
let(:io) { StringIO.new }
- subject { Eventwire::Middleware::ErrorHandler.new(app, :logger => Logger.new(io)) }
+ subject { Eventwire::Middleware::ErrorHandler.new(app, stub(:logger => Logger.new(io), :error_handler => proc {})) }
it 'should make the handler log when an exception happens' do
app.stub :subscribe do |_, _, handler|
@@ -59,4 +59,4 @@
end
end
-end
+end
View
4 spec/unit/middleware/logger_spec.rb
@@ -5,7 +5,7 @@
let(:app) { mock }
let(:io) { StringIO.new }
- subject { Eventwire::Middleware::Logger.new(app, :logger => Logger.new(io)) }
+ subject { Eventwire::Middleware::Logger.new(app, stub(:logger => Logger.new(io))) }
describe 'subscribe' do
it 'should call app’s subscribe' do
@@ -61,4 +61,4 @@
end
-end
+end
View
12 spec/unit/publisher_spec.rb
@@ -7,25 +7,23 @@
before do
@driver = mock
- Eventwire.configure do |c|
- c.driver = @driver
- end
+ Eventwire.configuration.stub(:driver => @driver)
end
subject { class_including(Eventwire::Publisher).new }
- it 'should publish the event using the current driver' do
+ it 'should publish the event using the current adapter' do
@driver.should_receive(:publish).with(:task_created, anything)
subject.publish_event :task_created
end
- it 'should publish the event with its data using the current driver' do
- @driver.should_receive(:publish).with(:task_created, {:task_name => 'Cleaning'}.to_json)
+ it 'should publish the event with its data using the current adapter' do
+ @driver.should_receive(:publish).with(:task_created, {:task_name => 'Cleaning'})
subject.publish_event :task_created, :task_name => 'Cleaning'
end
end
-end
+end
View
7 spec/unit/subscriber_spec.rb
@@ -7,9 +7,8 @@
before do
@driver = mock
- Eventwire.configure do |c|
- c.driver = @driver
- end
+ Eventwire.configuration.stub(:driver => @driver)
+ Eventwire.configuration.logger = Logger.new(nil)
end
subject { class_including Eventwire::Subscriber }
@@ -96,4 +95,4 @@
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.