spec/spec_helper.rb in datadog-notifications-0.6.7 vs spec/spec_helper.rb in datadog-notifications-0.7.0
- old
+ new
@@ -17,66 +17,45 @@
t.string :title
end
class Post < ActiveRecord::Base
end
-### Active-job test preparation
+### ActiveJob test preparation
ActiveJob::Base.queue_adapter = :inline
-class NoopJob < ActiveJob::Base
- self.queue_name = 'test:queue'
- def perform; end
-end
-### Mocks
+### Configuration
-module Mock
- class Reporter < Datadog::Notifications::Reporter
- def timing(stat, _millis, **opts)
- super(stat, 333, **opts)
- end
-
- def send_stat(message)
- messages.push message
- end
-
+RSpec.configure do |c|
+ helpers = Module.new do
def messages
@messages ||= []
end
end
- class Instrumentable
- def initialize(**opts)
- @opts = opts
- end
+ c.include helpers
+ c.before do
+ # clear existing messages
+ messages.clear
- def perform
- ActiveSupport::Notifications.instrument('mock.start', @opts)
- ActiveSupport::Notifications.instrument('mock.perform', @opts) do |payload|
- payload[:status] = 200
- end
+ # collect messages
+ reporter = Datadog::Notifications.instance.send(:reporter)
+ forwarder = reporter.send(:forwarder)
+ allow(forwarder).to receive(:send_message) do |msg|
+ @messages.push(msg)
end
- end
-end
-### Configuration
-
-RSpec.configure do |c|
- helpers = Module.new do
- def buffered
- Datadog::Notifications.instance.send(:reporter).messages
- end
+ # stub Time.now
+ allow(Time).to receive(:now).and_return(
+ Time.at(1616161616.161),
+ Time.at(1616161616.272),
+ Time.at(1616161616.948),
+ )
end
-
- c.include helpers
- c.before do
- buffered.clear
- end
end
Datadog::Notifications.configure do |c|
c.hostname = 'test.host'
- c.reporter = Mock::Reporter
c.tags = ['custom:tag']
c.use Datadog::Notifications::Plugins::ActiveRecord
c.use Datadog::Notifications::Plugins::ActiveJob
c.use Datadog::Notifications::Plugins::Grape,