camcorder 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +79 -0
- data/Rakefile +1 -0
- data/camcorder.gemspec +23 -0
- data/lib/camcorder.rb +76 -0
- data/lib/camcorder/configuration.rb +13 -0
- data/lib/camcorder/errors.rb +51 -0
- data/lib/camcorder/proxy.rb +76 -0
- data/lib/camcorder/recorder.rb +71 -0
- data/lib/camcorder/rspec.rb +24 -0
- data/lib/camcorder/version.rb +3 -0
- data/spec/camcorder/proxy_spec.rb +56 -0
- data/spec/camcorder/recorder_spec.rb +61 -0
- data/spec/camcorder_spec.rb +54 -0
- data/spec/fixtures/should_exist.yml +2 -0
- data/spec/recordings/Camcorder/constructor_interception/_new/should_return_a_proxy.yml +5 -0
- data/spec/recordings/Camcorder/constructor_interception/with_multiple_classes/_new/should_return_proxies.yml +9 -0
- data/spec/recordings/Camcorder_Proxy/_methods_with_side_effects/should_re-record_for_each_invocation.yml +3 -0
- data/spec/recordings/Camcorder_Proxy/when_recording_exists/should_not_call_methods_on_actual_instance.yml +5 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/test_object.rb +17 -0
- data/spec/support/test_object2.rb +11 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de005ffb4a08afb00954a1998d9258193f3bbb73
|
4
|
+
data.tar.gz: 4d9d1e6af8707afc904d62cd8605ce40734ef1dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94cef4dab926fa7768e79a1c9c50003368b2ce14aa2c4a5757d8a2d5f467c9cbbd871bc7aa94fd43bd80f88ae8ac0fe47d335fb929123cbaae53c06695fa6505
|
7
|
+
data.tar.gz: ca4ed1520d25bcc8eba17733a289c76d563f48a564e3e4f08af4d441028f41be32f5ac8796672e96bdb17316aecee38dd82ee4512150929194fb8052e770556f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gordon L. Hempton
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Camcorder
|
2
|
+
|
3
|
+
Need to have VCR-like functionality for more than just http? Wait no more. This gem allows you to record arbitrary method invocations from arbitrary objects.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'camcorder'
|
7
|
+
|
8
|
+
imap = Camcorder::Proxy.new(Net::IMAP, imap_host, imap_port, imap_ssl, nil, false)
|
9
|
+
imap.login(username, decrypted_password)
|
10
|
+
imap.search(query)
|
11
|
+
imap.disconnect
|
12
|
+
```
|
13
|
+
|
14
|
+
The above code will create an actual `Net::IMAP` object the first time around. Subsequent invocations will not, instead using recorded values.
|
15
|
+
|
16
|
+
For convenience, Camcorder provides a way to intercept the constructor for a class:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'camcorder'
|
20
|
+
|
21
|
+
Camcorder.intercept_constructor(Net::IMAP)
|
22
|
+
|
23
|
+
imap = Net::IMAP.new(imap_host, imap_port, imap_ssl, nil, false)
|
24
|
+
imap.login(username, decrypted_password)
|
25
|
+
imap.search(query)
|
26
|
+
imap.disconnect
|
27
|
+
```
|
28
|
+
|
29
|
+
## Side Effects
|
30
|
+
|
31
|
+
By default, Camcorder matches up a method invocation to a recording based on the passed in arguments. Methods with side effects need to be explicitly noted:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'camcorder'
|
35
|
+
|
36
|
+
Camcorder.intercept_constructor(Net::IMAP) do
|
37
|
+
methods_with_side_effects :examine, :select
|
38
|
+
end
|
39
|
+
|
40
|
+
imap = Net::IMAP.new(imap_host, imap_port, imap_ssl, nil, false)
|
41
|
+
imap.login(username, decrypted_password)
|
42
|
+
imap.select('INBOX')
|
43
|
+
imap.search(query)
|
44
|
+
imap.select('Sent Items') # will cause the `search` call below to return a different value
|
45
|
+
imap.search(query)
|
46
|
+
imap.disconnect
|
47
|
+
```
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
Add this line to your application's Gemfile:
|
52
|
+
|
53
|
+
gem 'camcorder'
|
54
|
+
|
55
|
+
And then execute:
|
56
|
+
|
57
|
+
$ bundle
|
58
|
+
|
59
|
+
Or install it yourself as:
|
60
|
+
|
61
|
+
$ gem install camcorder
|
62
|
+
|
63
|
+
## Usage with Rspec
|
64
|
+
|
65
|
+
In your `spec_helper.rb` file:
|
66
|
+
|
67
|
+
```
|
68
|
+
require 'camcorder/rspec'
|
69
|
+
|
70
|
+
Camcorder.configuration.recordings_dir = 'spec/recordings'
|
71
|
+
```
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it ( http://github.com/<my-github-username>/camcorder/fork )
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/camcorder.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'camcorder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "camcorder"
|
8
|
+
spec.version = Camcorder::VERSION
|
9
|
+
spec.authors = ["Gordon L. Hempton"]
|
10
|
+
spec.email = ["ghempton@gmail.com"]
|
11
|
+
spec.summary = "VCR-like recording for arbitrary method invocations."
|
12
|
+
spec.description = "VCR-like recording for arbitrary method invocations."
|
13
|
+
spec.homepage = "https://github.com/ghempton/camcorder"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/camcorder.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "camcorder/version"
|
2
|
+
require 'camcorder/errors'
|
3
|
+
require 'camcorder/proxy'
|
4
|
+
require 'camcorder/recorder'
|
5
|
+
require 'camcorder/configuration'
|
6
|
+
|
7
|
+
#
|
8
|
+
# Provides similar functionality as the VCR gem but works on arbitrary objects.
|
9
|
+
# This is useful for things like Net::IMAP and Net::SMTP which cannot be
|
10
|
+
# captured by VCR.
|
11
|
+
#
|
12
|
+
module Camcorder
|
13
|
+
|
14
|
+
def self.default_recorder
|
15
|
+
@default_recorder
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.default_recorder=(value)
|
19
|
+
@default_recorder = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config
|
23
|
+
@config ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Creates a proxy subclass for the particular class
|
28
|
+
#
|
29
|
+
def self.proxy_class(klass, recorder=nil, &block)
|
30
|
+
Class.new(Proxy) do
|
31
|
+
class << self
|
32
|
+
attr_reader :klass
|
33
|
+
attr_reader :recorder
|
34
|
+
end
|
35
|
+
@klass = klass
|
36
|
+
@recorder = recorder
|
37
|
+
def initialize(*args)
|
38
|
+
recorder = self.class.recorder || Camcorder.default_recorder
|
39
|
+
super(recorder, self.class.klass, *args)
|
40
|
+
end
|
41
|
+
self.class_eval &block if block
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Rewrites the `new` method on the passed in class to always return proxies.
|
47
|
+
#
|
48
|
+
def self.intercept_constructor(klass, recorder=nil, &block)
|
49
|
+
proxy_class = self.proxy_class(klass, recorder) do
|
50
|
+
def _initialize
|
51
|
+
@instance ||= klass._new(*@init_args)
|
52
|
+
end
|
53
|
+
self.class_eval &block if block
|
54
|
+
end
|
55
|
+
|
56
|
+
klass.class_eval do
|
57
|
+
@proxy_class = proxy_class
|
58
|
+
class << self
|
59
|
+
alias_method :_new, :new
|
60
|
+
def new(*args)
|
61
|
+
@proxy_class.new(*args)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.deintercept_constructor(klass)
|
68
|
+
klass.class_eval do
|
69
|
+
class << self
|
70
|
+
alias_method :new, :_new
|
71
|
+
remove_method :_new
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Camcorder
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class RecordingError < Error
|
6
|
+
attr_reader :key
|
7
|
+
def initialize(key)
|
8
|
+
@key = key
|
9
|
+
end
|
10
|
+
def message
|
11
|
+
"Recording for key #{key} has changed"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ProxyRecordingError < Error
|
16
|
+
attr_reader :klass, :name, :args, :side_effects
|
17
|
+
def initialize(klass, name, args, side_effects)
|
18
|
+
@klass = klass
|
19
|
+
@name = name
|
20
|
+
@args = args
|
21
|
+
@side_effects = side_effects
|
22
|
+
end
|
23
|
+
def message
|
24
|
+
"Recording for #{klass}.#{name} with args: #{args} and side_effects=#{side_effects} has changed. Consider using using `methods_with_side_effects`."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class PlaybackError < Error
|
29
|
+
attr_reader :key
|
30
|
+
def initialize(key)
|
31
|
+
@key = key
|
32
|
+
end
|
33
|
+
def message
|
34
|
+
"Cannot find key '#{key}' for playback"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class ProxyPlaybackError < Error
|
39
|
+
attr_reader :klass, :name, :args, :side_effects
|
40
|
+
def initialize(klass, name, args, side_effects)
|
41
|
+
@klass = klass
|
42
|
+
@name = name
|
43
|
+
@args = args
|
44
|
+
@side_effects = side_effects
|
45
|
+
end
|
46
|
+
def message
|
47
|
+
"Cannot find recording for #{klass}.#{name} with args: #{args} and side_effects=#{side_effects}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Camcorder
|
2
|
+
|
3
|
+
#
|
4
|
+
# Proxy which records all external methods
|
5
|
+
#
|
6
|
+
class Proxy
|
7
|
+
|
8
|
+
attr_reader :klass
|
9
|
+
attr_reader :instance
|
10
|
+
attr_reader :recorder
|
11
|
+
attr_reader :side_effects
|
12
|
+
|
13
|
+
def initialize(recorder, klass, *args)
|
14
|
+
@klass = klass
|
15
|
+
@init_args = args
|
16
|
+
@recorder = recorder
|
17
|
+
_add_side_effects(@init_args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def _initialize
|
21
|
+
@instance ||= klass.new(*@init_args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def _add_side_effects(args)
|
25
|
+
@side_effects = _hash_with_side_effects(args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def _hash_args(args)
|
29
|
+
Digest::MD5.hexdigest(YAML.dump(args))
|
30
|
+
end
|
31
|
+
|
32
|
+
def _hash_with_side_effects(args)
|
33
|
+
if side_effects
|
34
|
+
args = args + [side_effects]
|
35
|
+
end
|
36
|
+
_hash_args(args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def _record(name, args, &block)
|
40
|
+
hash = _hash_with_side_effects(args)
|
41
|
+
key = "#{klass.name}-#{name}-#{hash}"
|
42
|
+
recorder.record key do
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
rescue PlaybackError => e
|
46
|
+
raise ProxyPlaybackError.new(klass, name, args, side_effects)
|
47
|
+
rescue RecordingError => e
|
48
|
+
raise ProxyRecordingError.new(klass, name, args, side_effects)
|
49
|
+
end
|
50
|
+
|
51
|
+
def method_missing(name, *args)
|
52
|
+
_record(name, args) do
|
53
|
+
_initialize.send name, *args
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def respond_to?(name)
|
58
|
+
super || _initialize.respond_to?(name)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# These methods have "side effects" and will cause subsequent invocations of
|
63
|
+
# all methods to be re-recorded.
|
64
|
+
#
|
65
|
+
def self.methods_with_side_effects(*names)
|
66
|
+
names.each do |name|
|
67
|
+
define_method name do |*args|
|
68
|
+
_add_side_effects(args)
|
69
|
+
method_missing(name, *args)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Camcorder
|
4
|
+
|
5
|
+
class Recorder
|
6
|
+
|
7
|
+
attr_reader :recordings
|
8
|
+
attr_reader :filename
|
9
|
+
|
10
|
+
def initialize(filename)
|
11
|
+
@filename = filename
|
12
|
+
@recordings = {}
|
13
|
+
@changed = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def transaction(&block)
|
17
|
+
start
|
18
|
+
yield
|
19
|
+
commit
|
20
|
+
end
|
21
|
+
|
22
|
+
def start
|
23
|
+
if File.exists?(filename)
|
24
|
+
@recordings = YAML.load_file(filename)
|
25
|
+
@replaying = true
|
26
|
+
else
|
27
|
+
@recordings = {}
|
28
|
+
@replaying = false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def commit
|
33
|
+
return unless @changed
|
34
|
+
FileUtils.mkdir_p File.dirname(filename)
|
35
|
+
File.open(filename, 'w') {|f| YAML.dump(recordings, f) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def record(key, &block)
|
39
|
+
if @replaying
|
40
|
+
if recordings.has_key?(key)
|
41
|
+
recordings[key]
|
42
|
+
else
|
43
|
+
raise PlaybackError.new(key)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
result = yield
|
47
|
+
@changed = true
|
48
|
+
if recordings.has_key?(key)
|
49
|
+
if !deep_equals(recordings[key], result)
|
50
|
+
raise RecordingError(key)
|
51
|
+
end
|
52
|
+
else
|
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)
|
56
|
+
end
|
57
|
+
result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
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
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# Setup the camcorder before every test
|
3
|
+
#
|
4
|
+
RSpec.configure do |config|
|
5
|
+
|
6
|
+
recording_name_for = lambda do |metadata|
|
7
|
+
description = metadata[:description]
|
8
|
+
|
9
|
+
if example_group = metadata[:example_group]
|
10
|
+
[recording_name_for[example_group], description].reject{|d| !d || d == ''}.join('/')
|
11
|
+
else
|
12
|
+
description
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
config.around(:each) do |example|
|
17
|
+
name = recording_name_for[example.metadata].gsub(/[^\w\-\/]+/, '_')
|
18
|
+
filename = File.join(Camcorder.config.recordings_dir, "#{name}.yml")
|
19
|
+
Camcorder.default_recorder = Camcorder::Recorder.new(filename)
|
20
|
+
Camcorder.default_recorder.transaction do
|
21
|
+
example.run
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Camcorder::Proxy do
|
5
|
+
|
6
|
+
subject{ Camcorder::Proxy.new(Camcorder.default_recorder, TestObject) }
|
7
|
+
|
8
|
+
context 'when recording exists' do
|
9
|
+
|
10
|
+
it 'should not call methods on actual instance' do
|
11
|
+
|
12
|
+
expect_any_instance_of(TestObject).to_not receive(:simple_method)
|
13
|
+
expect(subject.simple_method).to eql(['A', 'B', 'C'])
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when recording does not exist' do
|
20
|
+
|
21
|
+
after(:all) do
|
22
|
+
File.delete('spec/recordings/Camcorder_Proxy/when_recording_does_not_exist/should_call_methods_on_actual_instance_and_record.yml')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should call methods on actual instance and record' do
|
26
|
+
|
27
|
+
expect_any_instance_of(TestObject).to receive(:simple_method).and_call_original
|
28
|
+
expect(subject.simple_method).to eql(['A', 'B', 'C'])
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe '.methods_with_side_effects' do
|
36
|
+
|
37
|
+
subject {
|
38
|
+
Class.new(Camcorder::Proxy) do
|
39
|
+
methods_with_side_effects :method_with_side_effects
|
40
|
+
end.new(Camcorder.default_recorder, TestObject)
|
41
|
+
}
|
42
|
+
|
43
|
+
it 'should re-record for each invocation' do
|
44
|
+
|
45
|
+
a = subject.method_with_side_effects
|
46
|
+
b = subject.method_with_side_effects
|
47
|
+
expect(a).to_not eq(b)
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Camcorder::Recorder do
|
5
|
+
|
6
|
+
subject{ Camcorder::Recorder.new(filename) }
|
7
|
+
|
8
|
+
describe '.transaction' do
|
9
|
+
|
10
|
+
let(:key) { 'key' }
|
11
|
+
|
12
|
+
context 'when recording exists' do
|
13
|
+
|
14
|
+
let(:filename) { 'spec/fixtures/should_exist.yml'}
|
15
|
+
|
16
|
+
it 'should return recorded value' do
|
17
|
+
subject.transaction do
|
18
|
+
result = subject.record 'key' do
|
19
|
+
raise 'should not get here'
|
20
|
+
end
|
21
|
+
expect(result).to eq('dis be da result')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should error on unknown key' do
|
26
|
+
expect {
|
27
|
+
subject.transaction do
|
28
|
+
result = subject.record 'another-key' do
|
29
|
+
raise 'should not get here'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
}.to raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when no recording exists' do
|
38
|
+
|
39
|
+
let(:filename) { 'spec/fixtures/should_not_exist.yml'}
|
40
|
+
|
41
|
+
after do
|
42
|
+
File.delete(filename)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should create recording' do
|
46
|
+
|
47
|
+
expect(File.exists?(filename)).to be_false
|
48
|
+
subject.transaction do
|
49
|
+
subject.record 'key' do
|
50
|
+
'dis be da result'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
expect(File.exists?(filename)).to be_true
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Camcorder do
|
4
|
+
|
5
|
+
describe 'constructor interception' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
Camcorder.intercept_constructor(TestObject)
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Camcorder.deintercept_constructor(TestObject)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.new' do
|
16
|
+
|
17
|
+
it 'should return a proxy' do
|
18
|
+
obj = TestObject.new
|
19
|
+
expect(obj).to be_a(Camcorder::Proxy)
|
20
|
+
expect(obj.simple_method).to eql(['A', 'B', 'C'])
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with multiple classes' do
|
26
|
+
|
27
|
+
before do
|
28
|
+
Camcorder.intercept_constructor(TestObject2)
|
29
|
+
end
|
30
|
+
|
31
|
+
after do
|
32
|
+
Camcorder.deintercept_constructor(TestObject2)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.new' do
|
36
|
+
|
37
|
+
it 'should return proxies' do
|
38
|
+
obj = TestObject.new
|
39
|
+
obj2 = TestObject2.new(2)
|
40
|
+
|
41
|
+
expect(obj2).to be_a(Camcorder::Proxy)
|
42
|
+
expect(obj2.simple_method).to eql([1, 2, 3])
|
43
|
+
|
44
|
+
expect(obj).to be_a(Camcorder::Proxy)
|
45
|
+
expect(obj.simple_method).to eql(['A', 'B', 'C'])
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: camcorder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gordon L. Hempton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: VCR-like recording for arbitrary method invocations.
|
42
|
+
email:
|
43
|
+
- ghempton@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- camcorder.gemspec
|
54
|
+
- lib/camcorder.rb
|
55
|
+
- lib/camcorder/configuration.rb
|
56
|
+
- lib/camcorder/errors.rb
|
57
|
+
- lib/camcorder/proxy.rb
|
58
|
+
- lib/camcorder/recorder.rb
|
59
|
+
- lib/camcorder/rspec.rb
|
60
|
+
- lib/camcorder/version.rb
|
61
|
+
- spec/camcorder/proxy_spec.rb
|
62
|
+
- spec/camcorder/recorder_spec.rb
|
63
|
+
- spec/camcorder_spec.rb
|
64
|
+
- spec/fixtures/should_exist.yml
|
65
|
+
- spec/recordings/Camcorder/constructor_interception/_new/should_return_a_proxy.yml
|
66
|
+
- spec/recordings/Camcorder/constructor_interception/with_multiple_classes/_new/should_return_proxies.yml
|
67
|
+
- spec/recordings/Camcorder_Proxy/_methods_with_side_effects/should_re-record_for_each_invocation.yml
|
68
|
+
- spec/recordings/Camcorder_Proxy/when_recording_exists/should_not_call_methods_on_actual_instance.yml
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- spec/support/test_object.rb
|
71
|
+
- spec/support/test_object2.rb
|
72
|
+
homepage: https://github.com/ghempton/camcorder
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.0
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: VCR-like recording for arbitrary method invocations.
|
96
|
+
test_files:
|
97
|
+
- spec/camcorder/proxy_spec.rb
|
98
|
+
- spec/camcorder/recorder_spec.rb
|
99
|
+
- spec/camcorder_spec.rb
|
100
|
+
- spec/fixtures/should_exist.yml
|
101
|
+
- spec/recordings/Camcorder/constructor_interception/_new/should_return_a_proxy.yml
|
102
|
+
- spec/recordings/Camcorder/constructor_interception/with_multiple_classes/_new/should_return_proxies.yml
|
103
|
+
- spec/recordings/Camcorder_Proxy/_methods_with_side_effects/should_re-record_for_each_invocation.yml
|
104
|
+
- spec/recordings/Camcorder_Proxy/when_recording_exists/should_not_call_methods_on_actual_instance.yml
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/support/test_object.rb
|
107
|
+
- spec/support/test_object2.rb
|