trecs 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +13 -5
- data/Gemfile.lock +3 -1
- data/bin/trecs +27 -47
- data/bin/trecs_record +23 -27
- data/lib/trecs/frame.rb +37 -0
- data/lib/trecs/player.rb +1 -1
- data/lib/trecs/readers/json_reader.rb +18 -11
- data/lib/trecs/recorder.rb +23 -15
- data/lib/trecs/recording_strategies/config_strategy.rb +31 -0
- data/lib/trecs/recording_strategies/file_frames_strategy.rb +30 -0
- data/lib/trecs/recording_strategies/hash_strategy.rb +4 -0
- data/lib/trecs/recording_strategies/ttyrec_strategy.rb +1 -37
- data/lib/trecs/sources/tgz_source.rb +106 -0
- data/lib/trecs/version.rb +1 -1
- data/lib/trecs/writers/json_writer.rb +28 -9
- data/spec/trecs/frame_spec.rb +68 -0
- data/spec/trecs/player_spec.rb +1 -1
- data/spec/trecs/readers/json_reader_spec.rb +1 -1
- data/spec/trecs/readers/yaml_store_reader_spec.rb +1 -1
- data/spec/trecs/recorder_spec.rb +48 -29
- data/spec/trecs/recording_strategies/config_strategy_spec.rb +129 -0
- data/spec/trecs/recording_strategies/file_frames_strategy_spec.rb +10 -0
- data/spec/trecs/recording_strategies/shell_command_strategy_spec.rb +1 -1
- data/spec/trecs/sources/tgz_source_spec.rb +8 -0
- data/spec/trecs/writers/json_writer_spec.rb +8 -0
- data/trecs.gemspec +1 -0
- metadata +48 -25
- data/old_specs/player_spec.rb +0 -198
- data/old_specs/recorders/zip_file_recorder_spec.rb +0 -64
- data/old_specs/timestamps_spec.rb +0 -44
- data/old_specs/trecs_message_spec.rb +0 -125
- data/old_specs/trecs_spec.rb +0 -115
@@ -1,64 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "zip"
|
3
|
-
|
4
|
-
require "recorders/zip_file_recorder"
|
5
|
-
require "players/zip_file_player"
|
6
|
-
|
7
|
-
module TRecs
|
8
|
-
describe ZipFileRecorder do
|
9
|
-
class DummyRecordingStrategy
|
10
|
-
attr_accessor :recorder
|
11
|
-
|
12
|
-
def initialize(options={})
|
13
|
-
#@recorder = options.fetch(:recorder)
|
14
|
-
end
|
15
|
-
|
16
|
-
def perform
|
17
|
-
recorder.current_frame(time: 0, content: "zero")
|
18
|
-
recorder.current_frame(time: 1, content: "one")
|
19
|
-
recorder.current_frame(time: 2, content: "two")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class DummyZipFileRecorder < ZipFileRecorder
|
24
|
-
def initialize(options)
|
25
|
-
@recording_strategy = DummyRecordingStrategy.new(recorder: self)
|
26
|
-
super
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "expects a file name" do
|
31
|
-
expect {
|
32
|
-
Recorder.new( persistence_strategy: ZipFileRecorder.new, recording_strategy: DummyRecordingStrategy.new) }.to raise_error
|
33
|
-
end
|
34
|
-
|
35
|
-
it "generates a .trecs compressed file" do
|
36
|
-
file_name = "tmp/i_should_exist.trecs"
|
37
|
-
recorder = Recorder.new(
|
38
|
-
persistence_strategy: ZipFileRecorder.new(file_name: file_name),
|
39
|
-
recording_strategy: DummyRecordingStrategy.new)
|
40
|
-
|
41
|
-
recorder.record
|
42
|
-
|
43
|
-
File.exists?(file_name).should be_truthy
|
44
|
-
expect { Zip::File.open(file_name) }.not_to raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
it "has the correct frames" do
|
48
|
-
file_name = "tmp/zero_one_two.trecs"
|
49
|
-
recorder = Recorder.new(
|
50
|
-
persistence_strategy: ZipFileRecorder.new(file_name: file_name),
|
51
|
-
recording_strategy: DummyRecordingStrategy.new)
|
52
|
-
|
53
|
-
recorder.record
|
54
|
-
|
55
|
-
player = ZipFilePlayer.new(file_name: file_name)
|
56
|
-
|
57
|
-
player.timestamps.should == [0, 1, 2]
|
58
|
-
player.get_frame(0).should == "zero"
|
59
|
-
player.get_frame(1).should == "one"
|
60
|
-
player.get_frame(2).should == "two"
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "timestamps"
|
3
|
-
|
4
|
-
describe Timestamps do
|
5
|
-
context "invalid inputs" do
|
6
|
-
it "returns 0 with invalid imputs" do
|
7
|
-
ts = Timestamps.new([0, 10, 20, 30])
|
8
|
-
[-1, :a, "hola", Object.new].each do |input|
|
9
|
-
ts.time_at(input).should == 0
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "empty collection" do
|
15
|
-
it "returns 0 at 0" do
|
16
|
-
ts = Timestamps.new([])
|
17
|
-
ts.time_at(0).should == 0
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns 0 at > 0" do
|
21
|
-
ts = Timestamps.new([])
|
22
|
-
ts.time_at(10).should == 0
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with timestamps and valid imputs" do
|
27
|
-
let(:subject) { Timestamps.new([0, 10, 20]) }
|
28
|
-
|
29
|
-
it "returns the exact time" do
|
30
|
-
subject.time_at(0).should == 0
|
31
|
-
subject.time_at(10).should == 10
|
32
|
-
subject.time_at(20).should == 20
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns the previous valid time if no exact time in the collection" do
|
36
|
-
subject.time_at(5).should == 0
|
37
|
-
subject.time_at(15).should == 10
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns the last time when passing a time greater than the greater time" do
|
41
|
-
subject.time_at(25).should == 20
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "fileutils"
|
3
|
-
require 'zip'
|
4
|
-
|
5
|
-
describe "T-Recs" do
|
6
|
-
include FileUtils
|
7
|
-
|
8
|
-
define :have_frames do |expected|
|
9
|
-
match do |actual|
|
10
|
-
actual = actual.split("\e[H\e[2J\n").select { |f|
|
11
|
-
(/\S/ === f)
|
12
|
-
}.map(&:chomp)
|
13
|
-
expected = Array(expected)
|
14
|
-
actual == expected
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:trecs_root) { File.expand_path("../..", __FILE__) }
|
19
|
-
let(:bin) { "#{trecs_root}/bin" }
|
20
|
-
let(:exe) { "#{bin}/trecs_message" }
|
21
|
-
let(:play_exe) { "#{bin}/trecs" }
|
22
|
-
|
23
|
-
let(:project_dir) { create_dir("#{trecs_root}/tmp") }
|
24
|
-
|
25
|
-
def trecs(*args, &block)
|
26
|
-
command = [exe]
|
27
|
-
.concat(args.map(&:to_s))
|
28
|
-
.concat(["2>&1"])
|
29
|
-
.join(" ")
|
30
|
-
IO.popen(command) do |output|
|
31
|
-
yield output.read if block_given?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def play(*args, &block)
|
36
|
-
command = [play_exe]
|
37
|
-
.concat(args.map(&:to_s))
|
38
|
-
.concat(["testing", "2>&1"])
|
39
|
-
.join(" ")
|
40
|
-
IO.popen(command) do |output|
|
41
|
-
yield output.read if block_given?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "trecs_message command" do
|
46
|
-
after do
|
47
|
-
rm file_name if file_name
|
48
|
-
end
|
49
|
-
|
50
|
-
specify "is in place and executes" do
|
51
|
-
expect { trecs }.not_to raise_exception
|
52
|
-
trecs do |output|
|
53
|
-
output.should_not match /error/i
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it "expects a file name" do
|
58
|
-
trecs do |output|
|
59
|
-
output.should have_frames "Please give a file name"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "generates a .trecs compressed file" do
|
64
|
-
file_name "i_should_exist"
|
65
|
-
trecs("-f", file_name, "--message", "a")
|
66
|
-
|
67
|
-
File.exists?(file_name).should be_truthy
|
68
|
-
expect { Zip::File.open(file_name) }.not_to raise_error
|
69
|
-
end
|
70
|
-
|
71
|
-
context "recording" do
|
72
|
-
it "records a one letter message screencast" do
|
73
|
-
file_name "a"
|
74
|
-
|
75
|
-
trecs("-f", file_name, "--message", "a")
|
76
|
-
|
77
|
-
play("-f", file_name) do |output|
|
78
|
-
output.should have_frames "a"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
it "records a two letters message screencast" do
|
83
|
-
file_name "ab"
|
84
|
-
|
85
|
-
trecs("-f", file_name, "--message", "ab")
|
86
|
-
|
87
|
-
play("-f", file_name) do |output|
|
88
|
-
output.should have_frames ["a", "ab"]
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it "records a three letters message screencast" do
|
93
|
-
file_name "abc"
|
94
|
-
|
95
|
-
trecs("-f", file_name, "--message", "abc")
|
96
|
-
|
97
|
-
play("-f", file_name) do |output|
|
98
|
-
output.should have_frames ["a", "ab", "abc"]
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "timestamps" do
|
104
|
-
it "uses 100 ms by default" do
|
105
|
-
file_name "abcd"
|
106
|
-
|
107
|
-
trecs("-f", file_name, "-m", "abcd")
|
108
|
-
|
109
|
-
play("-f", file_name, "--timestamps") do |output|
|
110
|
-
output.should have_frames "[0, 100, 200, 300]"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
it "accepts a step parameter" do
|
115
|
-
file_name "abc"
|
116
|
-
|
117
|
-
trecs("-f", file_name, "-m", "abcd", "-s", "250")
|
118
|
-
|
119
|
-
play("-f", file_name, "--timestamps") do |output|
|
120
|
-
output.should have_frames "[0, 250, 500, 750]"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
data/old_specs/trecs_spec.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "fileutils"
|
3
|
-
require 'zip'
|
4
|
-
require 'rspec/expectations'
|
5
|
-
|
6
|
-
describe "T-Recs" do
|
7
|
-
define :have_frames do |expected|
|
8
|
-
match do |actual|
|
9
|
-
actual = actual.split("\e[H\e[2J\n").select { |f|
|
10
|
-
(/\S/ === f)
|
11
|
-
}.map(&:chomp)
|
12
|
-
expected = Array(expected)
|
13
|
-
actual == expected
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
after do
|
18
|
-
rm file_name if file_name
|
19
|
-
end
|
20
|
-
|
21
|
-
include FileUtils
|
22
|
-
|
23
|
-
let(:trecs_root) { File.expand_path("../..", __FILE__) }
|
24
|
-
let(:bin) { "#{trecs_root}/bin" }
|
25
|
-
let(:exe) { "#{bin}/trecs" }
|
26
|
-
|
27
|
-
let(:project_dir) { create_dir("#{trecs_root}/tmp") }
|
28
|
-
|
29
|
-
def trecs(*args, &block)
|
30
|
-
command = [exe]
|
31
|
-
.concat(args.map(&:to_s))
|
32
|
-
.concat(["--testing"])
|
33
|
-
.join(" ")
|
34
|
-
IO.popen(command) do |output|
|
35
|
-
yield output.read if block_given?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def create_recording(options={})
|
40
|
-
file_name = options.fetch(:file_name) { "" }
|
41
|
-
unless File.exist?(file_name)
|
42
|
-
recording_dir = "#{File.dirname(file_name)}/frames"
|
43
|
-
rm_rf recording_dir
|
44
|
-
mkdir_p recording_dir
|
45
|
-
rm file_name if File.exists? file_name
|
46
|
-
|
47
|
-
yield recording_dir
|
48
|
-
|
49
|
-
files_to_record = Dir.glob("#{recording_dir}/*")
|
50
|
-
|
51
|
-
Zip::File.open(file_name, Zip::File::CREATE) do |trecs_file|
|
52
|
-
files_to_record.each do |file_to_rec|
|
53
|
-
dest_file_name = File.basename(file_to_rec)
|
54
|
-
trecs_file.add(dest_file_name, file_to_rec)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
rm_rf Dir.glob("#{recording_dir}")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def create_frame(options={})
|
62
|
-
file_name = options.fetch(:file_name) { "" }
|
63
|
-
content = options.fetch(:content) { "" }
|
64
|
-
time = options.fetch(:time) { 0 }
|
65
|
-
|
66
|
-
File.open("#{project_dir}/frames/#{time.to_i}", File::WRONLY|File::CREAT) do |f|
|
67
|
-
f << content
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "trecs command" do
|
72
|
-
it "is in place and executes" do
|
73
|
-
expect { trecs }.not_to raise_exception
|
74
|
-
end
|
75
|
-
|
76
|
-
it "returns an error whe project doesn't exist" do
|
77
|
-
non_existent = "path/to/a/non/existing/file.trecs"
|
78
|
-
|
79
|
-
trecs("-f", non_existent) do |output|
|
80
|
-
output.should have_frames "File #{non_existent} does not exist."
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "Player" do
|
85
|
-
|
86
|
-
context "playing a recording" do
|
87
|
-
|
88
|
-
it "plays a recording" do
|
89
|
-
file_name "multiple_frames"
|
90
|
-
|
91
|
-
create_recording(file_name: file_name) do
|
92
|
-
create_frame(time: 0, content: "FIRST FRAME")
|
93
|
-
create_frame(time: 100, content: "FRAME AT 100")
|
94
|
-
create_frame(time: 200, content: "FRAME AT 200")
|
95
|
-
create_frame(time: 301, content: "FRAME AT 301")
|
96
|
-
create_frame(time: 499, content: "FRAME AT 499")
|
97
|
-
create_frame(time: 599, content: "FRAME AT 599")
|
98
|
-
end
|
99
|
-
|
100
|
-
trecs("-f", file_name) do |output|
|
101
|
-
output.should have_frames [
|
102
|
-
"FIRST FRAME",
|
103
|
-
"FRAME AT 100",
|
104
|
-
"FRAME AT 200",
|
105
|
-
"FRAME AT 200",
|
106
|
-
"FRAME AT 301",
|
107
|
-
"FRAME AT 499",
|
108
|
-
"FRAME AT 599",
|
109
|
-
]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|