method_call_recorder 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.
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +26 -0
- data/Rakefile +22 -0
- data/Readme.md +35 -0
- data/lib/method_call_recorder.rb +18 -0
- data/lib/method_call_recorder/version.rb +3 -0
- data/method_call_recorder.gemspec +12 -0
- data/spec/method_call_recorder_spec.rb +70 -0
- data/spec/spec_helper.rb +2 -0
- metadata +61 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
method_call_recorder (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rake (0.9.2)
|
11
|
+
rspec (2.6.0)
|
12
|
+
rspec-core (~> 2.6.0)
|
13
|
+
rspec-expectations (~> 2.6.0)
|
14
|
+
rspec-mocks (~> 2.6.0)
|
15
|
+
rspec-core (2.6.4)
|
16
|
+
rspec-expectations (2.6.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.6.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
method_call_recorder!
|
25
|
+
rake
|
26
|
+
rspec (~> 2)
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
task :default do
|
4
|
+
sh "rspec spec/"
|
5
|
+
end
|
6
|
+
|
7
|
+
# extracted from https://github.com/grosser/project_template
|
8
|
+
rule /^version:bump:.*/ do |t|
|
9
|
+
file = "lib/method_call_recorder/version.rb"
|
10
|
+
|
11
|
+
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
|
12
|
+
index = ["major", "minor", "patch"].index(t.name.split(':').last)
|
13
|
+
version_file = File.read(file)
|
14
|
+
old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
|
15
|
+
version_parts[index] = version_parts[index].to_i + 1
|
16
|
+
version_parts[2] = 0 if index < 2 # remove patch for minor
|
17
|
+
version_parts[1] = 0 if index < 1 # remove minor for major
|
18
|
+
new_version = version_parts * '.'
|
19
|
+
|
20
|
+
File.open(file,"w"){|f| f.write(version_file.sub(old_version, new_version)) }
|
21
|
+
sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
|
22
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Ruby: Record methods calls and replay them later
|
2
|
+
|
3
|
+
Install
|
4
|
+
=======
|
5
|
+
|
6
|
+
gem install method_call_recorder
|
7
|
+
|
8
|
+
Usage
|
9
|
+
=====
|
10
|
+
|
11
|
+
recorder = MethodCallRecorder.new
|
12
|
+
|
13
|
+
# nothing happens
|
14
|
+
recorder.foo
|
15
|
+
recorder.bar :abc
|
16
|
+
recorder.baz :xyz do |blob|
|
17
|
+
puts blob
|
18
|
+
end
|
19
|
+
|
20
|
+
puts recorder.recorded
|
21
|
+
|
22
|
+
# calls get made to subject
|
23
|
+
recorder.replay(subject)
|
24
|
+
|
25
|
+
|
26
|
+
TODO
|
27
|
+
====
|
28
|
+
- make it possible to record #recorded or #replay by using recorder.proxy for recording which inheroits from e.g. BlankObject
|
29
|
+
|
30
|
+
Author
|
31
|
+
======
|
32
|
+
[Michael Grosser](http://grosser.it)<br/>
|
33
|
+
michael@grosser.it<br/>
|
34
|
+
License: MIT<br/>
|
35
|
+
[](http://travis-ci.org/grosser/method_call_recorder)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "method_call_recorder/version"
|
2
|
+
|
3
|
+
class MethodCallRecorder
|
4
|
+
attr_accessor :recorded
|
5
|
+
def initialize
|
6
|
+
@recorded = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def replay(subject)
|
10
|
+
recorded.each do |name, args, block|
|
11
|
+
subject.send(name, *args, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(name, *args, &block)
|
16
|
+
@recorded << [name, args, block]
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
name = "method_call_recorder"
|
3
|
+
require "#{name}/version"
|
4
|
+
|
5
|
+
Gem::Specification.new name, MethodCallRecorder::VERSION do |s|
|
6
|
+
s.summary = "Ruby: Record methods calls and replay them later"
|
7
|
+
s.authors = ["Michael Grosser"]
|
8
|
+
s.email = "michael@grosser.it"
|
9
|
+
s.homepage = "http://github.com/grosser/#{name}"
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.license = "MIT"
|
12
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MethodCallRecorder do
|
4
|
+
let(:recorder){ MethodCallRecorder.new }
|
5
|
+
|
6
|
+
it "has a VERSION" do
|
7
|
+
MethodCallRecorder::VERSION.should =~ /^[\.\da-z]+$/
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#record" do
|
11
|
+
it "records simple call" do
|
12
|
+
recorder.foo
|
13
|
+
recorder.recorded.should == [[:foo, [], nil]]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "records call with arguments" do
|
17
|
+
recorder.foo 1, 2, :bar => 1
|
18
|
+
recorder.recorded.should == [[:foo, [1, 2, {:bar => 1}], nil]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "records call with block" do
|
22
|
+
recorder.foo 1 do
|
23
|
+
raise "FAIL"
|
24
|
+
end
|
25
|
+
recorder.recorded.size.should == 1
|
26
|
+
recorder.recorded.first.size.should == 3
|
27
|
+
recorder.recorded.first[0].should == :foo
|
28
|
+
recorder.recorded.first[1].should == [1]
|
29
|
+
recorder.recorded.first[2].should be_a(Proc)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "records multiple calls" do
|
33
|
+
recorder.foo
|
34
|
+
recorder.bar
|
35
|
+
recorder.foo
|
36
|
+
recorder.recorded.should == [
|
37
|
+
[:foo, [], nil],
|
38
|
+
[:bar, [], nil],
|
39
|
+
[:foo, [], nil]
|
40
|
+
]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#replay" do
|
45
|
+
it "can replay simple calls" do
|
46
|
+
recorder.foo
|
47
|
+
stub = stub()
|
48
|
+
stub.should_receive(:foo).with()
|
49
|
+
recorder.replay(stub)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can replay calls with args" do
|
53
|
+
recorder.foo 1, 2, :bar => 1
|
54
|
+
stub = stub()
|
55
|
+
stub.should_receive(:foo).with(1, 2, :bar => 1)
|
56
|
+
recorder.replay(stub)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can replay calls with blocks" do
|
60
|
+
arg = nil
|
61
|
+
recorder.foo do |blob|
|
62
|
+
arg = blob
|
63
|
+
end
|
64
|
+
stub = stub()
|
65
|
+
stub.should_receive(:foo).with().and_yield(1)
|
66
|
+
recorder.replay(stub)
|
67
|
+
arg.should == 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: method_call_recorder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Grosser
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: michael@grosser.it
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .travis.yml
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- Rakefile
|
24
|
+
- Readme.md
|
25
|
+
- lib/method_call_recorder.rb
|
26
|
+
- lib/method_call_recorder/version.rb
|
27
|
+
- method_call_recorder.gemspec
|
28
|
+
- spec/method_call_recorder_spec.rb
|
29
|
+
- spec/spec_helper.rb
|
30
|
+
homepage: http://github.com/grosser/method_call_recorder
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
hash: -2655653628880487495
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
hash: -2655653628880487495
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.24
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: ! 'Ruby: Record methods calls and replay them later'
|
61
|
+
test_files: []
|