fixtury 0.1.0.rc1 → 0.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/Gemfile.lock +1 -1
- data/lib/fixtury/definition.rb +18 -5
- data/lib/fixtury/execution_context.rb +8 -0
- data/lib/fixtury/store.rb +27 -14
- data/lib/fixtury/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a4447982d6e785c9158850f3d158b07e1226f6a05d85917d41307c5455d41d9
|
4
|
+
data.tar.gz: c7fac4726892a1851ca7b7f0d3ff8abfe2bbedf4d2706b2c3ae6443d6be863f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c5858894f02eb54b555df7ee182e81e3741cbd278e37bbd0a3250b9cfea62a00341d3ff95a75adb0d5f56cfd3abcdb036877bee28601b87ff060c3e9bf6f43c
|
7
|
+
data.tar.gz: 0e99678f39920cd68026905ddd202ea8b9f9648c3bef9e941e7fd084fb2daa1ed843b5d2839fc10cbf13f1cc27c224ac212d7cd01173b2f3f8692706cadde2cb
|
data/Gemfile.lock
CHANGED
data/lib/fixtury/definition.rb
CHANGED
@@ -25,6 +25,8 @@ module Fixtury
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def call(store: nil, execution_context: nil)
|
28
|
+
execution_context ||= ::Fixtury::ExecutionContext.new
|
29
|
+
|
28
30
|
maybe_set_store_context(store: store) do
|
29
31
|
value = run_callable(store: store, callable: callable, execution_context: execution_context, value: nil)
|
30
32
|
enhancements.each do |e|
|
@@ -45,8 +47,6 @@ module Fixtury
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def run_callable(store:, callable:, execution_context:, value:)
|
48
|
-
execution_context ||= self
|
49
|
-
|
50
50
|
args = []
|
51
51
|
args << value unless value.nil?
|
52
52
|
if callable.arity > args.length
|
@@ -55,11 +55,24 @@ module Fixtury
|
|
55
55
|
args << store
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
execution_context_hooks(execution_context) do
|
59
|
+
if args.length.positive?
|
60
|
+
execution_context.instance_exec(*args, &callable)
|
61
|
+
else
|
62
|
+
execution_context.instance_eval(&callable)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def execution_context_hooks(execution_context)
|
68
|
+
execution_context.before_fixture(self) if execution_context.respond_to?(:before_fixture)
|
69
|
+
value = if execution_context.respond_to?(:around_fixture)
|
70
|
+
execution_context.around_fixture(self) { yield }
|
60
71
|
else
|
61
|
-
|
72
|
+
yield
|
62
73
|
end
|
74
|
+
execution_context.after_fixture(self, value) if execution_context.respond_to?(:after_fixture)
|
75
|
+
value
|
63
76
|
end
|
64
77
|
|
65
78
|
end
|
data/lib/fixtury/store.rb
CHANGED
@@ -11,27 +11,36 @@ require "fixtury/reference"
|
|
11
11
|
module Fixtury
|
12
12
|
class Store
|
13
13
|
|
14
|
+
LOG_LEVELS = {
|
15
|
+
(LOG_LEVEL_NONE = :none) => 0,
|
16
|
+
(LOG_LEVEL_INFO = :info) => 1,
|
17
|
+
(LOG_LEVEL_DEBUG = :debug) => 2,
|
18
|
+
}.freeze
|
19
|
+
|
14
20
|
cattr_accessor :instance
|
15
21
|
|
16
22
|
attr_reader :filepath, :references, :ttl, :auto_refresh_expired
|
17
23
|
attr_reader :schema, :locator
|
18
|
-
attr_reader :
|
24
|
+
attr_reader :log_level
|
19
25
|
attr_reader :execution_context
|
20
26
|
|
21
27
|
def initialize(
|
22
28
|
filepath: nil,
|
23
29
|
locator: ::Fixtury::Locator.instance,
|
24
|
-
|
30
|
+
log_level: nil,
|
25
31
|
ttl: nil,
|
26
32
|
schema: nil,
|
33
|
+
execution_context: nil,
|
27
34
|
auto_refresh_expired: false
|
28
35
|
)
|
29
36
|
@schema = schema || ::Fixtury.schema
|
30
|
-
@
|
37
|
+
@log_level = log_level.nil? ? ENV["FIXTURY_LOG_LEVEL"] : log_level
|
38
|
+
@log_level ||= LOG_LEVEL_NONE
|
39
|
+
@log_level = @log_level.to_s.to_sym
|
31
40
|
@locator = locator
|
32
41
|
@filepath = filepath
|
33
42
|
@references = @filepath && ::File.file?(@filepath) ? ::YAML.load_file(@filepath) : {}
|
34
|
-
@execution_context = ::Fixtury::ExecutionContext.new
|
43
|
+
@execution_context = execution_context || ::Fixtury::ExecutionContext.new
|
35
44
|
@ttl = ttl ? ttl.to_i : ttl
|
36
45
|
@auto_refresh_expired = !!auto_refresh_expired
|
37
46
|
self.class.instance ||= self
|
@@ -54,7 +63,7 @@ module Fixtury
|
|
54
63
|
|
55
64
|
references.delete_if do |name, ref|
|
56
65
|
is_expired = ref_invalid?(ref)
|
57
|
-
log { "expiring #{name}" } if is_expired
|
66
|
+
log(level: LOG_LEVEL_INFO) { "expiring #{name}" } if is_expired
|
58
67
|
is_expired
|
59
68
|
end
|
60
69
|
end
|
@@ -76,7 +85,7 @@ module Fixtury
|
|
76
85
|
pattern = pattern[0...-1] if glob
|
77
86
|
references.delete_if do |key, _value|
|
78
87
|
hit = glob ? key.start_with?(pattern) : key == pattern
|
79
|
-
log(
|
88
|
+
log(level: LOG_LEVEL_INFO) { "clearing #{key}" } if hit
|
80
89
|
hit
|
81
90
|
end
|
82
91
|
dump_to_file
|
@@ -95,7 +104,7 @@ module Fixtury
|
|
95
104
|
full_name = dfn.name
|
96
105
|
ref = references[full_name]
|
97
106
|
result = ref&.real?
|
98
|
-
log { result ? "hit #{full_name}" : "miss #{full_name}" }
|
107
|
+
log(level: LOG_LEVEL_DEBUG) { result ? "hit #{full_name}" : "miss #{full_name}" }
|
99
108
|
result
|
100
109
|
end
|
101
110
|
|
@@ -109,7 +118,7 @@ module Fixtury
|
|
109
118
|
end
|
110
119
|
|
111
120
|
if ref && auto_refresh_expired && ref_invalid?(ref)
|
112
|
-
log { "refreshing #{full_name}" }
|
121
|
+
log(level: LOG_LEVEL_INFO) { "refreshing #{full_name}" }
|
113
122
|
clear_ref(full_name)
|
114
123
|
ref = nil
|
115
124
|
end
|
@@ -117,11 +126,11 @@ module Fixtury
|
|
117
126
|
value = nil
|
118
127
|
|
119
128
|
if ref
|
120
|
-
log { "hit #{full_name}" }
|
129
|
+
log(level: LOG_LEVEL_DEBUG) { "hit #{full_name}" }
|
121
130
|
value = load_ref(ref.value)
|
122
131
|
if value.nil?
|
123
132
|
clear_ref(full_name)
|
124
|
-
log { "missing #{full_name}" }
|
133
|
+
log(level: LOG_LEVEL_DEBUG) { "missing #{full_name}" }
|
125
134
|
end
|
126
135
|
end
|
127
136
|
|
@@ -131,7 +140,7 @@ module Fixtury
|
|
131
140
|
|
132
141
|
value = dfn.call(store: self, execution_context: execution_context)
|
133
142
|
|
134
|
-
log { "store #{full_name}" }
|
143
|
+
log(level: LOG_LEVEL_INFO) { "store #{full_name}" }
|
135
144
|
|
136
145
|
ref = dump_ref(full_name, value)
|
137
146
|
ref = ::Fixtury::Reference.new(full_name, ref)
|
@@ -160,10 +169,14 @@ module Fixtury
|
|
160
169
|
!locator.recognize?(ref.value)
|
161
170
|
end
|
162
171
|
|
163
|
-
def log(
|
164
|
-
|
172
|
+
def log(level: LOG_LEVEL_DEBUG, name: "store")
|
173
|
+
desired_level = LOG_LEVELS.fetch(log_level) { LOG_LEVEL_NONE }
|
174
|
+
return if desired_level == LOG_LEVEL_NONE
|
175
|
+
|
176
|
+
message_level = LOG_LEVELS.fetch(level) { LOG_LEVEL_DEBUG }
|
177
|
+
return unless desired_level >= message_level
|
165
178
|
|
166
|
-
puts "[fixtury
|
179
|
+
puts "[fixtury|#{name}] #{yield}"
|
167
180
|
end
|
168
181
|
|
169
182
|
end
|
data/lib/fixtury/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixtury
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autotest
|
@@ -191,9 +191,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
|
-
- - "
|
194
|
+
- - ">="
|
195
195
|
- !ruby/object:Gem::Version
|
196
|
-
version:
|
196
|
+
version: '0'
|
197
197
|
requirements: []
|
198
198
|
rubygems_version: 3.0.6
|
199
199
|
signing_key:
|