stable 1.0.0 → 1.1.0
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/lib/stable/spec.rb +3 -0
- data/lib/stable.rb +4 -30
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6eaeeb526166f78e5d039f97e943f3dae2541b869728ce3888778e0d72be922
|
4
|
+
data.tar.gz: b7edd805344ecd2eead6e6cbef78abacdde918eef4c9219a252f24d0aa76f9b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c0197b7316ed87668a74ce881317454924cfee6467976fd662901dea25daf8ee338cfe455c0a8133c96ab2d8639d2109223d8de20fc699b4b09c6e8e45e65df
|
7
|
+
data.tar.gz: 95bba0dd950234f2f1115b25cfd0197b0bec71474930d0302d113a7e2113d260c09578e1d66f2c7b59e5f6db51bd3f6b2bd48bffcb98b60d16829a0912a63e1f
|
data/lib/stable/spec.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module Stable
|
5
|
+
# a spec is a recording of a single method call, including the inputs and
|
6
|
+
# outputs. it's a self-contained, serializable representation of a method's
|
7
|
+
# behavior at a specific point in time.
|
5
8
|
class Spec
|
6
9
|
attr_reader :class_name, :method_name, :args, :result, :error, :timestamp
|
7
10
|
|
data/lib/stable.rb
CHANGED
@@ -1,30 +1,5 @@
|
|
1
|
-
# stable is a library for recording and replaying method calls.
|
2
|
-
#
|
3
|
-
# keeping the stability/notification system that unit tests provide.
|
4
|
-
#
|
5
|
-
# usage:
|
6
|
-
#
|
7
|
-
# require 'stable'
|
8
|
-
#
|
9
|
-
# # stable uses an IO-like object to write the captured inputs/outputs.
|
10
|
-
# # if you don't set this, the default it to print the interaction records to
|
11
|
-
# # $stdout, so you could also pipe the result to another place.
|
12
|
-
# Stable.storage = File.open('captured_calls.jsonl', 'a')
|
13
|
-
#
|
14
|
-
# # wrap a method on a given class
|
15
|
-
# Stable.capture(MyClass, :my_method)
|
16
|
-
#
|
17
|
-
# # enable runtime input/output capture
|
18
|
-
# Stable.enable!
|
19
|
-
#
|
20
|
-
# MyClass.my_metehod # this will be captures by stable
|
21
|
-
#
|
22
|
-
# # disable input/output capture
|
23
|
-
# Stable.disable!
|
24
|
-
#
|
25
|
-
# # replay captured calls, which gives you a unit test-list pass/fail
|
26
|
-
# record = JSON.parse(File.read('captured_calls.jsonl').lines.first)
|
27
|
-
# Stable.replay(record)
|
1
|
+
# `stable` is a library for recording and replaying method calls.
|
2
|
+
# See README.md for detailed usage instructions.
|
28
3
|
require_relative 'stable/spec'
|
29
4
|
|
30
5
|
module Stable
|
@@ -49,7 +24,7 @@ module Stable
|
|
49
24
|
@storage || raise("Stable.storage must be set to an IO-like object")
|
50
25
|
end
|
51
26
|
|
52
|
-
def
|
27
|
+
def record(klass, method_name)
|
53
28
|
original_method = klass.instance_method(method_name)
|
54
29
|
wrapper_module = Module.new do
|
55
30
|
define_method(method_name) do |*args, &block|
|
@@ -86,7 +61,7 @@ module Stable
|
|
86
61
|
klass.prepend(wrapper_module)
|
87
62
|
end
|
88
63
|
|
89
|
-
def
|
64
|
+
def verify(record_hash)
|
90
65
|
spec = Spec.from_jsonl(record_hash.to_json)
|
91
66
|
klass = Object.const_get(spec.class_name)
|
92
67
|
instance = klass.new
|
@@ -121,4 +96,3 @@ module Stable
|
|
121
96
|
end
|
122
97
|
end
|
123
98
|
end
|
124
|
-
|