Skip to content

Commit

Permalink
Sketch out the structure for backends
Browse files Browse the repository at this point in the history
  • Loading branch information
ajvondrak committed Mar 4, 2021
1 parent a578df8 commit 478dab8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/minitrace.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "minitrace/version"
require "minitrace/backends"
require "minitrace/event"

# A minimalist tracing framework.
Expand Down
7 changes: 7 additions & 0 deletions lib/minitrace/backend.rb
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class Minitrace::Backend
def process(event)
raise NotImplementedError
end
end
7 changes: 7 additions & 0 deletions lib/minitrace/backends.rb
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require "minitrace/backend"

module Minitrace::Backends
autoload :Spy, "minitrace/backends/spy"
end
11 changes: 11 additions & 0 deletions lib/minitrace/backends/spy.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class Minitrace::Backends::Spy < Minitrace::Backend
def processed
@processed ||= []
end

def process(event)
processed << event
end
end
20 changes: 20 additions & 0 deletions test/lib/minitrace/backends/spy_test.rb
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require "test_helper"

class Minitrace::Backends::SpyTest < Minitest::Test
def test_process
spy = Minitrace::Backends::Spy.new

a = Minitrace::Event.new
spy.process(a)

b = Minitrace::Event.new
spy.process(b)

c = Minitrace::Event.new
spy.process(c)

assert { spy.processed == [a, b, c] }
end
end

0 comments on commit 478dab8

Please sign in to comment.