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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stable/spec.rb +3 -0
  3. data/lib/stable.rb +4 -30
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5d2929b75b7c0dbf556f482bd3b4eeb852cfebff63fd26e4debd66c1c6980e3
4
- data.tar.gz: fad79c07ad6849822bf0d73ff71ab104d4d4876efa6d6f146239ec7faa31a69b
3
+ metadata.gz: e6eaeeb526166f78e5d039f97e943f3dae2541b869728ce3888778e0d72be922
4
+ data.tar.gz: b7edd805344ecd2eead6e6cbef78abacdde918eef4c9219a252f24d0aa76f9b8
5
5
  SHA512:
6
- metadata.gz: c2de06eb210c9f700779a3d07b131695749e7f6ad1e8d3d70d5d701bf7204b2a6834d3c0411d86be0c9bb7fbf81aab3a8d56603e259c8cca5cb1fd3ed9c72883
7
- data.tar.gz: 38511e64502515d0b24578c4d056a289ce3f65837a3e54b249b04b77714148a15e668f033b1746e1958206c51b4ee13995dde283d88642995916dc10802f0718
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. the idea of
2
- # this is to reduce the amount of manual unit tests you need to write, while
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 capture(klass, method_name)
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 replay(record_hash)
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
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt