camcorder 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/camcorder/configuration.rb +7 -5
- data/lib/camcorder/recorder.rb +13 -2
- data/lib/camcorder/version.rb +1 -1
- data/spec/camcorder/recorder_spec.rb +61 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7103fb50fcbc4807446de2a20603dd46b9106243
|
4
|
+
data.tar.gz: 39f797f45138310163a948b6348e08eee8233231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12bb3b00c04e8492b20901726a3046f324b67156ce6dfbeac7c467dea335e7089b7117a8259540524ed715027439e02e94c4e87c727674fe32060debab2e9e9b
|
7
|
+
data.tar.gz: 5891884aa8bc345319b0ea368672997ed15b8d824bf4b81f7ea9fde811e36a149b7e9c02c67617dc9af6403998f98bd3a6a916be742e81940f2b0c191f15527c
|
data/lib/camcorder/recorder.rb
CHANGED
@@ -8,10 +8,11 @@ module Camcorder
|
|
8
8
|
attr_reader :recordings
|
9
9
|
attr_reader :filename
|
10
10
|
|
11
|
-
def initialize(filename)
|
11
|
+
def initialize(filename, verify_recordings: Camcorder.config.verify_recordings)
|
12
12
|
@filename = filename
|
13
13
|
@recordings = {}
|
14
14
|
@changed = false
|
15
|
+
@verify_recordings = verify_recordings
|
15
16
|
end
|
16
17
|
|
17
18
|
def transaction(&block)
|
@@ -51,7 +52,7 @@ module Camcorder
|
|
51
52
|
ensure
|
52
53
|
@changed = true
|
53
54
|
if recordings.has_key?(key)
|
54
|
-
|
55
|
+
unless verify_recordings(recordings[key], recording)
|
55
56
|
raise RecordingError.new(key)
|
56
57
|
end
|
57
58
|
else
|
@@ -62,6 +63,16 @@ module Camcorder
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
66
|
+
def verify_recordings(a, b)
|
67
|
+
if @verify_recordings.is_a?(Proc)
|
68
|
+
@verify_recordings.call(a, b)
|
69
|
+
elsif @verify_recordings
|
70
|
+
a == b
|
71
|
+
else
|
72
|
+
true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
65
76
|
end
|
66
77
|
|
67
78
|
end
|
data/lib/camcorder/version.rb
CHANGED
@@ -24,6 +24,67 @@ describe Camcorder::Recorder do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
context 'when recordings with same key return different results' do
|
28
|
+
|
29
|
+
after { File.delete(filename) }
|
30
|
+
|
31
|
+
let(:filename) { 'spec/fixtures/bad_verification.yml'}
|
32
|
+
|
33
|
+
it 'raises' do
|
34
|
+
expect {
|
35
|
+
subject.transaction do
|
36
|
+
subject.record 'key' do
|
37
|
+
'dis be da result'
|
38
|
+
end
|
39
|
+
subject.record 'key' do
|
40
|
+
'dis be a diff result'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
}.to raise_error(Camcorder::RecordingError)
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when verify_recordings: false' do
|
47
|
+
|
48
|
+
before { Camcorder.config.verify_recordings = false }
|
49
|
+
after { Camcorder.config.verify_recordings = true }
|
50
|
+
|
51
|
+
it 'does not raise' do
|
52
|
+
expect {
|
53
|
+
subject.transaction do
|
54
|
+
subject.record 'key' do
|
55
|
+
'dis be da result'
|
56
|
+
end
|
57
|
+
subject.record 'key' do
|
58
|
+
'dis be a diff result'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
}.to_not raise_error
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
context 'when verify_recordigs is a proc' do
|
68
|
+
before { Camcorder.config.verify_recordings = -> (a,b) { a.value[0..3] == b.value[0..3] } }
|
69
|
+
after { Camcorder.config.verify_recordings = true }
|
70
|
+
|
71
|
+
it 'does not raise' do
|
72
|
+
expect {
|
73
|
+
subject.transaction do
|
74
|
+
subject.record 'key' do
|
75
|
+
'dis be da result'
|
76
|
+
end
|
77
|
+
subject.record 'key' do
|
78
|
+
'dis be a diff result'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
}.to_not raise_error
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
27
88
|
it 'should error on unknown key' do
|
28
89
|
expect {
|
29
90
|
subject.transaction do
|