stable 1.4.0 → 1.5.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 +4 -4
- data/lib/stable/configuration.rb +11 -0
- data/lib/stable/spec.rb +16 -4
- data/lib/stable.rb +19 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04f5edbc2d167df3bc6a5057291e567562f2e07b6885140ec96f3cf87b601032
|
4
|
+
data.tar.gz: 6da1a393e4f367fe1fcb284198f4f0a31e70df9537a8d910c4901e6b863c60f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95eb8713130c459485d8024fb7c5cef3b80d5e973b81534ee1cc43c11d617e573b3dedec3256bc4aafd3510915baf77498d6f83c096a3fb8ce921e9fd733b78b
|
7
|
+
data.tar.gz: bb5156a92198985700e2624d47f9c34f84a2d608c4192a2672550a0111fceac1d12ba71fef6949787bb2cdcaf514581f313535a160f6664a6f2b17a989970fbd
|
data/lib/stable/spec.rb
CHANGED
@@ -54,11 +54,11 @@ module Stable
|
|
54
54
|
|
55
55
|
case status
|
56
56
|
when :passed
|
57
|
-
"#{desc} P #{call}"
|
57
|
+
"#{desc} #{_green('P')} #{call}"
|
58
58
|
when :passed_with_error
|
59
|
-
"#{desc} P (error) #{call}"
|
59
|
+
"#{desc} #{_green('P')} (error) #{call}"
|
60
60
|
when :failed
|
61
|
-
lines = ["#{desc} F #{call}"]
|
61
|
+
lines = ["#{desc} #{_red('F')} #{call}"]
|
62
62
|
if actual_error
|
63
63
|
if error
|
64
64
|
lines << " Expected error: #{error['class']}"
|
@@ -78,7 +78,7 @@ module Stable
|
|
78
78
|
end
|
79
79
|
lines.join("\n")
|
80
80
|
else
|
81
|
-
"#{desc} ? #{call}"
|
81
|
+
"#{desc} #{_yellow('?')} #{call}"
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -107,5 +107,17 @@ module Stable
|
|
107
107
|
uuid: data['uuid']
|
108
108
|
)
|
109
109
|
end
|
110
|
+
|
111
|
+
def _green(text)
|
112
|
+
"\e[32m#{text}\e[0m"
|
113
|
+
end
|
114
|
+
|
115
|
+
def _red(text)
|
116
|
+
"\e[31m#{text}\e[0m"
|
117
|
+
end
|
118
|
+
|
119
|
+
def _yellow(text)
|
120
|
+
"\e[33m#{text}\e[0m"
|
121
|
+
end
|
110
122
|
end
|
111
123
|
end
|
data/lib/stable.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
# `stable` is a library for recording and replaying method calls.
|
2
2
|
# See README.md for detailed usage instructions.
|
3
3
|
require_relative 'stable/spec'
|
4
|
+
require_relative 'stable/configuration'
|
4
5
|
|
5
6
|
module Stable
|
6
7
|
class << self
|
8
|
+
def configuration
|
9
|
+
@configuration ||= Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield(configuration)
|
14
|
+
end
|
15
|
+
|
7
16
|
def enable!
|
8
17
|
Thread.current[:stable_enabled] = true
|
9
18
|
end
|
@@ -13,7 +22,7 @@ module Stable
|
|
13
22
|
end
|
14
23
|
|
15
24
|
def enabled?
|
16
|
-
Thread.current[:stable_enabled] || false
|
25
|
+
Thread.current[:stable_enabled] || configuration.enabled || false
|
17
26
|
end
|
18
27
|
|
19
28
|
def storage=(io)
|
@@ -21,7 +30,7 @@ module Stable
|
|
21
30
|
end
|
22
31
|
|
23
32
|
def storage
|
24
|
-
@storage || raise("Stable.storage must be set to an IO-like object")
|
33
|
+
@storage ||= (configuration.storage_path && File.open(configuration.storage_path, 'a+')) || raise("Stable.storage must be set to an IO-like object")
|
25
34
|
end
|
26
35
|
|
27
36
|
# this method is a block-based way to enable and disable recording of
|
@@ -39,6 +48,8 @@ module Stable
|
|
39
48
|
yield if block_given?
|
40
49
|
ensure
|
41
50
|
disable!
|
51
|
+
storage.close if storage.respond_to?(:close)
|
52
|
+
@storage = nil
|
42
53
|
end
|
43
54
|
|
44
55
|
def watch(klass, method_name)
|
@@ -56,6 +67,7 @@ module Stable
|
|
56
67
|
)
|
57
68
|
unless Stable.send(:_spec_exists?, spec.signature)
|
58
69
|
Stable.storage.puts(spec.to_jsonl)
|
70
|
+
Stable.storage.flush
|
59
71
|
Stable.send(:_recorded_specs) << spec
|
60
72
|
end
|
61
73
|
result
|
@@ -72,6 +84,7 @@ module Stable
|
|
72
84
|
)
|
73
85
|
unless Stable.send(:_spec_exists?, spec.signature)
|
74
86
|
Stable.storage.puts(spec.to_jsonl)
|
87
|
+
Stable.storage.flush
|
75
88
|
Stable.send(:_recorded_specs) << spec
|
76
89
|
end
|
77
90
|
raise e
|
@@ -93,7 +106,10 @@ module Stable
|
|
93
106
|
def _recorded_specs
|
94
107
|
@_recorded_specs ||= begin
|
95
108
|
return [] unless storage.respond_to?(:path) && File.exist?(storage.path)
|
96
|
-
|
109
|
+
storage.rewind
|
110
|
+
specs = storage.each_line.map { |line| Spec.from_jsonl(line) }
|
111
|
+
storage.seek(0, IO::SEEK_END)
|
112
|
+
specs
|
97
113
|
end
|
98
114
|
end
|
99
115
|
|
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.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/stable.rb
|
20
|
+
- lib/stable/configuration.rb
|
20
21
|
- lib/stable/spec.rb
|
21
22
|
homepage: https://github.com/jefflunt/stable
|
22
23
|
licenses:
|