Skip to content

Commit c29bf88

Browse files
committed
Start work on recording datasets.
See #22 for discussion. The idea is to record a set of events that can be used to functionally test everything past `Shark::Agency` in the stack (i.e., middlewares). This will probably be replaced with preference to factories before too long, though, since they give better control over every detail of an object, making unit tests more granular without having to scan for a desired series of events.
1 parent dc33fe8 commit c29bf88

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Data files are bound to grow very large, and there's no need to track them
2+
data/*

Rakefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rubygems'
2+
require 'bundler'
3+
Bundler.setup(:test)
4+
5+
task :record do
6+
ruby 'test/record.rb'
7+
end

test/record.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'pstore'
2+
3+
require_relative '../agency'
4+
require_relative '../config/citybus'
5+
6+
Shark::Object.configure{}
7+
8+
STORAGE = PStore.new('data/events.log')
9+
# Running this task will recreate the event log from scratch
10+
STORAGE.transaction{ STORAGE.delete :eventlog }
11+
12+
13+
# Create an agency instance and overwrite `call` to intercept all events that
14+
# it receives (from ObjectManagers) and record them appropriately.
15+
mock_agency = Shark::Agency.new
16+
def mock_agency.call event
17+
# Record the given event into persistant storage, along with a timestamp for
18+
# remember it's position in an order of events.
19+
time = Time.now
20+
(STORAGE[:eventlog] ||= {})[time] = event.to_h
21+
puts "Recorded #{event.topic}##{event.type} at #{time}"
22+
end
23+
24+
STORAGE.transaction do
25+
mock_agency.run
26+
sleep(4)
27+
end

0 commit comments

Comments
 (0)