camcorder 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +7 -5
- data/lib/camcorder/recorder.rb +15 -19
- data/lib/camcorder/recording.rb +45 -0
- data/lib/camcorder/version.rb +1 -1
- data/spec/camcorder/proxy_spec.rb +7 -0
- data/spec/camcorder/recorder_spec.rb +22 -3
- data/spec/fixtures/haz_errorz.yml +5 -0
- data/spec/fixtures/should_exist.yml +3 -1
- data/spec/recordings/Camcorder/constructor_interception/_new/should_return_a_proxy.yml +6 -4
- data/spec/recordings/Camcorder/constructor_interception/with_multiple_classes/_new/should_return_proxies.yml +12 -8
- data/spec/recordings/Camcorder_Proxy/_methods_with_side_effects/should_re-record_for_each_invocation.yml +6 -2
- data/spec/recordings/Camcorder_Proxy/when_recording_exists/should_not_call_methods_on_actual_instance.yml +6 -4
- data/spec/recordings/Camcorder_Proxy/when_recording_exists/should_re-raise_recorded_errors.yml +5 -0
- data/spec/support/test_object.rb +4 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6593d537d37f4630e5e39874ae2431c22bf955
|
4
|
+
data.tar.gz: 69afb405dd9c9d6171fba3e4ccf5502c8e352d44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b4d58e302d98fd9374afa2aeae275d73509c6ac32b18f63b8919d6343f85fd015a0f1abb72764e678d70ffafa88bbc86dc2e270bb3891afd216fd7a79517abf
|
7
|
+
data.tar.gz: 4268ffb55fee733246ce27cc38578ae35f26f03f3f504c7f484fb369ee3f7b4bd35559a40200859bdb696c807396bc8f5f354f84109c35236bfb0b6ee7444533
|
data/README.md
CHANGED
@@ -50,21 +50,23 @@ imap.disconnect
|
|
50
50
|
|
51
51
|
Add this line to your application's Gemfile:
|
52
52
|
|
53
|
-
|
53
|
+
```ruby
|
54
|
+
gem 'camcorder'
|
55
|
+
```
|
54
56
|
|
55
57
|
And then execute:
|
56
58
|
|
57
|
-
|
59
|
+
bundle
|
58
60
|
|
59
61
|
Or install it yourself as:
|
60
62
|
|
61
|
-
|
63
|
+
gem install camcorder
|
62
64
|
|
63
65
|
## Usage with Rspec
|
64
66
|
|
65
67
|
In your `spec_helper.rb` file:
|
66
68
|
|
67
|
-
```
|
69
|
+
```ruby
|
68
70
|
require 'camcorder/rspec'
|
69
71
|
|
70
72
|
Camcorder.configuration.recordings_dir = 'spec/recordings'
|
@@ -72,7 +74,7 @@ Camcorder.configuration.recordings_dir = 'spec/recordings'
|
|
72
74
|
|
73
75
|
## Contributing
|
74
76
|
|
75
|
-
1. Fork it ( http://github.com
|
77
|
+
1. Fork it ( http://github.com/ghempton/camcorder/fork )
|
76
78
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
79
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
80
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/camcorder/recorder.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'camcorder/recording'
|
2
3
|
|
3
4
|
module Camcorder
|
4
5
|
|
@@ -16,6 +17,7 @@ module Camcorder
|
|
16
17
|
def transaction(&block)
|
17
18
|
start
|
18
19
|
yield
|
20
|
+
ensure
|
19
21
|
commit
|
20
22
|
end
|
21
23
|
|
@@ -38,34 +40,28 @@ module Camcorder
|
|
38
40
|
def record(key, &block)
|
39
41
|
if @replaying
|
40
42
|
if recordings.has_key?(key)
|
41
|
-
recordings[key]
|
43
|
+
recordings[key].replay
|
42
44
|
else
|
43
45
|
raise PlaybackError.new(key)
|
44
46
|
end
|
45
47
|
else
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
begin
|
49
|
+
recording = Recording.new
|
50
|
+
result = recording.record(&block)
|
51
|
+
ensure
|
52
|
+
@changed = true
|
53
|
+
if recordings.has_key?(key)
|
54
|
+
if recordings[key] != recording
|
55
|
+
raise RecordingError(key)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
recordings[key] = recording
|
51
59
|
end
|
52
|
-
|
53
|
-
# Make sure we store a copy of the result so future destructive mutations
|
54
|
-
# do not change this value
|
55
|
-
recordings[key] = deep_clone(result)
|
60
|
+
result
|
56
61
|
end
|
57
|
-
result
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
61
|
-
def deep_clone(value)
|
62
|
-
YAML.load(YAML.dump(value))
|
63
|
-
end
|
64
|
-
|
65
|
-
def deep_equals(a, b)
|
66
|
-
YAML.dump(a) == YAML.dump(b)
|
67
|
-
end
|
68
|
-
|
69
65
|
end
|
70
66
|
|
71
67
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Camcorder
|
2
|
+
|
3
|
+
class Recording
|
4
|
+
|
5
|
+
attr_reader :value
|
6
|
+
attr_reader :behavior
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
@value = nil
|
10
|
+
@behavior = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def record(&block)
|
14
|
+
res = yield
|
15
|
+
# Make sure we store a copy of the result so future destructive mutations
|
16
|
+
# do not change this value
|
17
|
+
@value = deep_clone(res)
|
18
|
+
@behavior = :return
|
19
|
+
res
|
20
|
+
rescue Exception => e
|
21
|
+
@value = e
|
22
|
+
@behavior = :raise
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
|
26
|
+
def replay
|
27
|
+
case @behavior
|
28
|
+
when :return
|
29
|
+
return @value
|
30
|
+
when :raise
|
31
|
+
raise @value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def deep_clone(value)
|
36
|
+
YAML.load(YAML.dump(value))
|
37
|
+
end
|
38
|
+
|
39
|
+
def ==(other)
|
40
|
+
YAML.dump(self) == YAML.dump(other)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/camcorder/version.rb
CHANGED
@@ -14,6 +14,13 @@ describe Camcorder::Proxy do
|
|
14
14
|
|
15
15
|
end
|
16
16
|
|
17
|
+
it 'should re-raise recorded errors' do
|
18
|
+
|
19
|
+
expect_any_instance_of(TestObject).to_not receive(:broke_method)
|
20
|
+
expect{subject.broke_method}.to raise_error(StandardError)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
17
24
|
end
|
18
25
|
|
19
26
|
context 'when recording does not exist' do
|
@@ -16,7 +16,9 @@ describe Camcorder::Recorder do
|
|
16
16
|
it 'should return recorded value' do
|
17
17
|
subject.transaction do
|
18
18
|
result = subject.record 'key' do
|
19
|
-
|
19
|
+
# Manually recorded
|
20
|
+
'dis be da result'
|
21
|
+
#raise 'should not get here'
|
20
22
|
end
|
21
23
|
expect(result).to eq('dis be da result')
|
22
24
|
end
|
@@ -25,11 +27,28 @@ describe Camcorder::Recorder do
|
|
25
27
|
it 'should error on unknown key' do
|
26
28
|
expect {
|
27
29
|
subject.transaction do
|
28
|
-
|
30
|
+
subject.record 'another-key' do
|
29
31
|
raise 'should not get here'
|
30
32
|
end
|
31
33
|
end
|
32
|
-
}.to raise_error
|
34
|
+
}.to raise_error(Camcorder::PlaybackError)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when block raises' do
|
40
|
+
|
41
|
+
let(:filename) { 'spec/fixtures/haz_errorz.yml'}
|
42
|
+
|
43
|
+
it 'should reraise from recording' do
|
44
|
+
expect {
|
45
|
+
subject.transaction do
|
46
|
+
subject.record 'key-with-error' do
|
47
|
+
# Manually recorded
|
48
|
+
raise StandardError.new('errorz')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
}.to raise_error(StandardError)
|
33
52
|
end
|
34
53
|
|
35
54
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
---
|
2
|
-
TestObject2-simple_method-4de0fd48a5b0c805e290ecc39c85f9e7:
|
3
|
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
|
7
|
-
|
8
|
-
-
|
9
|
-
|
2
|
+
TestObject2-simple_method-4de0fd48a5b0c805e290ecc39c85f9e7: !ruby/object:Camcorder::Recording
|
3
|
+
value:
|
4
|
+
- 1
|
5
|
+
- 2
|
6
|
+
- 3
|
7
|
+
behavior: :return
|
8
|
+
TestObject-simple_method-cdc941172e4d28939f6513e81222285c: !ruby/object:Camcorder::Recording
|
9
|
+
value:
|
10
|
+
- A
|
11
|
+
- B
|
12
|
+
- C
|
13
|
+
behavior: :return
|
@@ -1,3 +1,7 @@
|
|
1
1
|
---
|
2
|
-
TestObject-method_with_side_effects-663f267dd7915410d1fce869a1bb0039:
|
3
|
-
|
2
|
+
TestObject-method_with_side_effects-663f267dd7915410d1fce869a1bb0039: !ruby/object:Camcorder::Recording
|
3
|
+
value: 1
|
4
|
+
behavior: :return
|
5
|
+
TestObject-method_with_side_effects-4ad0eb78b76e60e313f8d7b40194d3fc: !ruby/object:Camcorder::Recording
|
6
|
+
value: 2
|
7
|
+
behavior: :return
|
data/spec/support/test_object.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camcorder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gordon L. Hempton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,19 @@ files:
|
|
56
56
|
- lib/camcorder/errors.rb
|
57
57
|
- lib/camcorder/proxy.rb
|
58
58
|
- lib/camcorder/recorder.rb
|
59
|
+
- lib/camcorder/recording.rb
|
59
60
|
- lib/camcorder/rspec.rb
|
60
61
|
- lib/camcorder/version.rb
|
61
62
|
- spec/camcorder/proxy_spec.rb
|
62
63
|
- spec/camcorder/recorder_spec.rb
|
63
64
|
- spec/camcorder_spec.rb
|
65
|
+
- spec/fixtures/haz_errorz.yml
|
64
66
|
- spec/fixtures/should_exist.yml
|
65
67
|
- spec/recordings/Camcorder/constructor_interception/_new/should_return_a_proxy.yml
|
66
68
|
- spec/recordings/Camcorder/constructor_interception/with_multiple_classes/_new/should_return_proxies.yml
|
67
69
|
- spec/recordings/Camcorder_Proxy/_methods_with_side_effects/should_re-record_for_each_invocation.yml
|
68
70
|
- spec/recordings/Camcorder_Proxy/when_recording_exists/should_not_call_methods_on_actual_instance.yml
|
71
|
+
- spec/recordings/Camcorder_Proxy/when_recording_exists/should_re-raise_recorded_errors.yml
|
69
72
|
- spec/spec_helper.rb
|
70
73
|
- spec/support/test_object.rb
|
71
74
|
- spec/support/test_object2.rb
|
@@ -97,11 +100,13 @@ test_files:
|
|
97
100
|
- spec/camcorder/proxy_spec.rb
|
98
101
|
- spec/camcorder/recorder_spec.rb
|
99
102
|
- spec/camcorder_spec.rb
|
103
|
+
- spec/fixtures/haz_errorz.yml
|
100
104
|
- spec/fixtures/should_exist.yml
|
101
105
|
- spec/recordings/Camcorder/constructor_interception/_new/should_return_a_proxy.yml
|
102
106
|
- spec/recordings/Camcorder/constructor_interception/with_multiple_classes/_new/should_return_proxies.yml
|
103
107
|
- spec/recordings/Camcorder_Proxy/_methods_with_side_effects/should_re-record_for_each_invocation.yml
|
104
108
|
- spec/recordings/Camcorder_Proxy/when_recording_exists/should_not_call_methods_on_actual_instance.yml
|
109
|
+
- spec/recordings/Camcorder_Proxy/when_recording_exists/should_re-raise_recorded_errors.yml
|
105
110
|
- spec/spec_helper.rb
|
106
111
|
- spec/support/test_object.rb
|
107
112
|
- spec/support/test_object2.rb
|