spec/spec_helper.rb in datadog-notifications-0.5.4 vs spec/spec_helper.rb in datadog-notifications-0.6.0
- old
+ new
@@ -8,11 +8,11 @@
require 'active_record'
require 'sqlite3'
### Active-record test preparation
-ActiveRecord::Base.configurations["test"] = { 'adapter' => 'sqlite3', 'database' => ':memory:' }
+ActiveRecord::Base.configurations['test'] = { 'adapter' => 'sqlite3', 'database' => ':memory:' }
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.create_table :posts do |t|
t.string :title
end
class Post < ActiveRecord::Base
@@ -24,22 +24,27 @@
class Reporter < Datadog::Notifications::Reporter
def timing(stat, _ms, opts={})
super(stat, 333, opts)
end
- def flush_buffer; end
- @should_batch = true
+ def send_stat(message)
+ messages.push message
+ end
+
+ def messages
+ @messages ||= []
+ end
end
class Instrumentable
def initialize(opts={})
@opts = opts
end
def perform
- ActiveSupport::Notifications.instrument("mock.start", @opts)
- ActiveSupport::Notifications.instrument("mock.perform", @opts) do |payload|
+ ActiveSupport::Notifications.instrument('mock.start', @opts)
+ ActiveSupport::Notifications.instrument('mock.perform', @opts) do |payload|
payload[:status] = 200
end
end
end
end
@@ -47,28 +52,28 @@
### Configuration
RSpec.configure do |c|
helpers = Module.new do
def buffered
- Datadog::Notifications.instance.send(:reporter).buffer
+ Datadog::Notifications.instance.send(:reporter).messages
end
end
c.include helpers
c.before do
buffered.clear
end
end
Datadog::Notifications.configure do |c|
- c.hostname = "test.host"
+ c.hostname = 'test.host'
c.reporter = Mock::Reporter
- c.tags = ["custom:tag"]
+ c.tags = ['custom:tag']
c.use Datadog::Notifications::Plugins::ActiveRecord
c.use Datadog::Notifications::Plugins::Grape,
- tags: ["more:tags"],
- metric_name: "api.request",
+ tags: ['more:tags'],
+ metric_name: 'api.request',
exception_handler: lambda {|e|
if e.message.include?('unauthorized')
401
else
Datadog::Notifications::Plugins::Grape.exception_status(e)