test_wiretap 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 +8 -8
- data/README.rdoc +32 -0
- data/test/test_wiretap_spec.rb +92 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmEzNzNhYzZhODg5MjdiNGE1ODU2YmE1ZDdkZWU3MmNiZjgwZDMxMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGM5ZTMzNjhmY2Q1NWZmZjAzN2FmMmJhZTQ0MTNlZjFjMTJhY2I4NA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mjk2ZGQzODYwN2M2YmM1MzliMmJkNDM0N2NmNWNhM2MzZTFjNDZjY2EyMzI5
|
10
|
+
YWY0OTBhZjgyNmRiYWZiOTlmOWUzNGE0ZDJlNGEwMTNkMzQwMGJmNDNkNmQ0
|
11
|
+
ZmQ5MjVjZjA4YmFkODcyN2VkNzMxYWUzZjBlMjgyMGJjZmNhOTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODAzNTExYzcyY2E5YTlmZmNkMWZjZWY0OTgwNDcwYzRlNDFhYTU4ZDVkZTI2
|
14
|
+
ZjMxNzgxZjU3NGY0YzlkZjNkNDQ0ZTZlYzIyYThjZTQ4NjUyMzlhNTBlYzEw
|
15
|
+
MmZmNWYzOWVjODgzYWI2MThlZTg1Zjc5NmMxMDE4MmQ0MGQwZTY=
|
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= Wiretap Testing Utility
|
2
|
+
|
3
|
+
Use Wiretap to audit method calls of ruby objects during testing. (Inspired by Perl's Test::Wiretap)
|
4
|
+
|
5
|
+
== Simple Example
|
6
|
+
|
7
|
+
class Kittens
|
8
|
+
def so_cute!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
k = Kittens.new
|
12
|
+
wt_k = Wiretap.new(k, 'so_cute!')
|
13
|
+
k.so_cute!
|
14
|
+
wt_k.called == 1
|
15
|
+
|
16
|
+
See test_wiretap_spec.rb for more ways to use Wiretap.
|
17
|
+
|
18
|
+
== Copyright
|
19
|
+
|
20
|
+
Copyright 2013, 2014 Agari Data, Inc.
|
21
|
+
|
22
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
23
|
+
you may not use this software except in compliance with the License.
|
24
|
+
You may obtain a copy of the License at
|
25
|
+
|
26
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
27
|
+
|
28
|
+
Unless required by applicable law or agreed to in writing, software
|
29
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
30
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
31
|
+
See the License for the specific language governing permissions and
|
32
|
+
limitations under the License.
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require './wiretap_object'
|
2
|
+
|
3
|
+
class Foo
|
4
|
+
attr_accessor :number
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@number = 2
|
8
|
+
end
|
9
|
+
|
10
|
+
# def work(var1, var2='space man', **var4)
|
11
|
+
def work(var1, var2='space man', *var3)
|
12
|
+
@number *= 2
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.greet_planet(planet)
|
16
|
+
"Hello #{planet}!"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Wiretap do
|
22
|
+
it "can track call count" do
|
23
|
+
foo = Foo.new
|
24
|
+
|
25
|
+
wt = Wiretap.new(foo, :work)
|
26
|
+
expect(wt.called).to eq(0)
|
27
|
+
foo.work(nil)
|
28
|
+
expect(wt.called).to eq(1)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can track agruments" do
|
32
|
+
foo = Foo.new
|
33
|
+
|
34
|
+
wt = Wiretap.new(foo, :work)
|
35
|
+
args = ['Today', 'was a', :good => 'day']
|
36
|
+
foo.work(*args)
|
37
|
+
expect(wt.arguments[0]).to match_array(args)
|
38
|
+
foo.work(nil)
|
39
|
+
expect(wt.arguments[1]).to match_array([nil])
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can track return value" do
|
43
|
+
foo = Foo.new
|
44
|
+
|
45
|
+
wt = Wiretap.new(foo, :work)
|
46
|
+
rv = foo.work(nil)
|
47
|
+
expect(wt.return_value[0]).to eq(4)
|
48
|
+
expect(rv).to eq(4)
|
49
|
+
|
50
|
+
rv = foo.work(nil)
|
51
|
+
expect(wt.return_value[1]).to eq(8)
|
52
|
+
expect(rv).to eq(8)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can replace the called method" do
|
56
|
+
foo = Foo.new
|
57
|
+
|
58
|
+
test_value = 9999
|
59
|
+
bar = Proc.new { test_value }
|
60
|
+
|
61
|
+
wt = Wiretap.new(foo, 'work', method: bar)
|
62
|
+
rv = foo.work(nil)
|
63
|
+
expect(foo.number).to eq(2)
|
64
|
+
expect(wt.return_value[0]).to eq(test_value)
|
65
|
+
expect(rv).to eq(test_value)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can call pre and post methods" do
|
69
|
+
foo = Foo.new
|
70
|
+
|
71
|
+
pre_was_called = false
|
72
|
+
pre_m = Proc.new { pre_was_called = true }
|
73
|
+
|
74
|
+
post_was_called = false
|
75
|
+
post_m = Proc.new { post_was_called = true }
|
76
|
+
|
77
|
+
wt = Wiretap.new(foo, 'work', pre_method: pre_m, post_method: post_m)
|
78
|
+
foo.work(nil)
|
79
|
+
expect(pre_was_called).to be(true)
|
80
|
+
expect(post_was_called).to be(true)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can wiretap class methods" do
|
84
|
+
wt_gp = Wiretap.new(Foo, :greet_planet)
|
85
|
+
|
86
|
+
Foo.greet_planet('world')
|
87
|
+
|
88
|
+
expect(wt_gp.called).to eq(1)
|
89
|
+
expect(wt_gp.arguments[0]).to match_array(['world'])
|
90
|
+
expect(wt_gp.return_value[0]).to eq('Hello world!')
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_wiretap
|
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
|
- Stephen Cattaneo
|
@@ -30,7 +30,9 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- README.rdoc
|
33
34
|
- lib/test_wiretap.rb
|
35
|
+
- test/test_wiretap_spec.rb
|
34
36
|
homepage: http://rubygems.org/gems/test_wiretap
|
35
37
|
licenses:
|
36
38
|
- Apache License, Version 2.0
|