fixtury 0.1.0.alpha2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -10
- data/fixtury.gemspec +1 -1
- data/lib/fixtury.rb +0 -1
- data/lib/fixtury/definition.rb +19 -6
- data/lib/fixtury/locator.rb +6 -0
- data/lib/fixtury/schema.rb +1 -1
- data/lib/fixtury/store.rb +32 -20
- data/lib/fixtury/{hooks.rb → test_hooks.rb} +34 -2
- data/lib/fixtury/version.rb +1 -1
- metadata +7 -8
- data/lib/fixtury/execution_context.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43cad01d0dda49953fb41782235cb0786d60a0b84eb3d8e9f4145d6fa4268f04
|
4
|
+
data.tar.gz: 5f4347bcf7a8ef5b7c72d42802e260f7ecc1b0e8d3772f4681bbef2aa7e9a963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adc92b02ad90ae0afd4f4b10d146e26663d3dfd0d428f9739d9cfcf147dde7d2e09b05f84e956f116af62123477bc453f343ca3bda0a3bf17ae6d7edf61d7f35
|
7
|
+
data.tar.gz: 4a5720793e764bc4f366512b8d172b31d64b68c89abd86862d2d199f68bd36b590e706bba56c8fa5471d071c5d84e370c30de0b7bf93109df3476d75caf22dca
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fixtury (0.1.0
|
4
|
+
fixtury (0.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (6.0.1)
|
9
|
+
activesupport (6.0.3.1)
|
10
10
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
11
|
i18n (>= 0.7, < 2)
|
12
12
|
minitest (~> 5.1)
|
13
13
|
tzinfo (~> 1.1)
|
14
|
-
zeitwerk (~> 2.2)
|
14
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
15
15
|
ansi (1.5.0)
|
16
16
|
autotest (5.0.0)
|
17
17
|
minitest-autotest (~> 1.0)
|
18
18
|
builder (3.2.3)
|
19
19
|
byebug (11.0.1)
|
20
|
-
concurrent-ruby (1.1.
|
20
|
+
concurrent-ruby (1.1.6)
|
21
21
|
globalid (0.4.2)
|
22
22
|
activesupport (>= 4.2.0)
|
23
|
-
i18n (1.
|
23
|
+
i18n (1.8.2)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
metaclass (0.0.4)
|
26
26
|
minitest (5.13.0)
|
@@ -37,13 +37,13 @@ GEM
|
|
37
37
|
mocha (1.8.0)
|
38
38
|
metaclass (~> 0.0.1)
|
39
39
|
path_expander (1.1.0)
|
40
|
-
rake (
|
40
|
+
rake (13.0.1)
|
41
41
|
ruby-progressbar (1.10.1)
|
42
42
|
sqlite (1.0.2)
|
43
43
|
thread_safe (0.3.6)
|
44
|
-
tzinfo (1.2.
|
44
|
+
tzinfo (1.2.7)
|
45
45
|
thread_safe (~> 0.1)
|
46
|
-
zeitwerk (2.
|
46
|
+
zeitwerk (2.3.0)
|
47
47
|
|
48
48
|
PLATFORMS
|
49
49
|
ruby
|
@@ -57,8 +57,8 @@ DEPENDENCIES
|
|
57
57
|
minitest (~> 5.0)
|
58
58
|
minitest-reporters
|
59
59
|
mocha
|
60
|
-
rake (~>
|
60
|
+
rake (~> 13.0)
|
61
61
|
sqlite
|
62
62
|
|
63
63
|
BUNDLED WITH
|
64
|
-
2.
|
64
|
+
2.1.4
|
data/fixtury.gemspec
CHANGED
@@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency "minitest", "~> 5.0"
|
35
35
|
spec.add_development_dependency "minitest-reporters"
|
36
36
|
spec.add_development_dependency "mocha"
|
37
|
-
spec.add_development_dependency "rake", "~>
|
37
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
38
38
|
spec.add_development_dependency "sqlite"
|
39
39
|
end
|
data/lib/fixtury.rb
CHANGED
data/lib/fixtury/definition.rb
CHANGED
@@ -44,9 +44,7 @@ module Fixtury
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def run_callable(store:, callable:, execution_context
|
48
|
-
execution_context ||= self
|
49
|
-
|
47
|
+
def run_callable(store:, callable:, execution_context: nil, value:)
|
50
48
|
args = []
|
51
49
|
args << value unless value.nil?
|
52
50
|
if callable.arity > args.length
|
@@ -55,11 +53,26 @@ module Fixtury
|
|
55
53
|
args << store
|
56
54
|
end
|
57
55
|
|
58
|
-
|
59
|
-
|
56
|
+
provide_execution_context_hooks(execution_context) do |ctxt|
|
57
|
+
if args.length.positive?
|
58
|
+
ctxt.instance_exec(*args, &callable)
|
59
|
+
else
|
60
|
+
ctxt.instance_eval(&callable)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def provide_execution_context_hooks(execution_context)
|
66
|
+
return yield self unless execution_context
|
67
|
+
|
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 execution_context }
|
60
71
|
else
|
61
|
-
execution_context
|
72
|
+
yield execution_context
|
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/locator.rb
CHANGED
@@ -24,6 +24,12 @@ module Fixtury
|
|
24
24
|
@backend = backend
|
25
25
|
end
|
26
26
|
|
27
|
+
def recognize?(ref)
|
28
|
+
raise ArgumentError, "Unable to recognize a nil ref" if ref.nil?
|
29
|
+
|
30
|
+
backend.recognized_reference?(ref)
|
31
|
+
end
|
32
|
+
|
27
33
|
def load(ref)
|
28
34
|
raise ArgumentError, "Unable to load a nil ref" if ref.nil?
|
29
35
|
|
data/lib/fixtury/schema.rb
CHANGED
data/lib/fixtury/store.rb
CHANGED
@@ -5,33 +5,41 @@ require "singleton"
|
|
5
5
|
require "yaml"
|
6
6
|
require "fixtury/locator"
|
7
7
|
require "fixtury/errors/circular_dependency_error"
|
8
|
-
require "fixtury/execution_context"
|
9
8
|
require "fixtury/reference"
|
10
9
|
|
11
10
|
module Fixtury
|
12
11
|
class Store
|
13
12
|
|
13
|
+
LOG_LEVELS = {
|
14
|
+
(LOG_LEVEL_NONE = :none) => 0,
|
15
|
+
(LOG_LEVEL_INFO = :info) => 1,
|
16
|
+
(LOG_LEVEL_DEBUG = :debug) => 2,
|
17
|
+
}.freeze
|
18
|
+
|
14
19
|
cattr_accessor :instance
|
15
20
|
|
16
21
|
attr_reader :filepath, :references, :ttl, :auto_refresh_expired
|
17
22
|
attr_reader :schema, :locator
|
18
|
-
attr_reader :
|
23
|
+
attr_reader :log_level
|
19
24
|
attr_reader :execution_context
|
20
25
|
|
21
26
|
def initialize(
|
22
27
|
filepath: nil,
|
23
28
|
locator: ::Fixtury::Locator.instance,
|
24
|
-
|
29
|
+
log_level: nil,
|
25
30
|
ttl: nil,
|
26
31
|
schema: nil,
|
32
|
+
execution_context: nil,
|
27
33
|
auto_refresh_expired: false
|
28
34
|
)
|
29
35
|
@schema = schema || ::Fixtury.schema
|
30
|
-
@
|
36
|
+
@log_level = log_level.nil? ? ENV["FIXTURY_LOG_LEVEL"] : log_level
|
37
|
+
@log_level ||= LOG_LEVEL_NONE
|
38
|
+
@log_level = @log_level.to_s.to_sym
|
31
39
|
@locator = locator
|
32
40
|
@filepath = filepath
|
33
41
|
@references = @filepath && ::File.file?(@filepath) ? ::YAML.load_file(@filepath) : {}
|
34
|
-
@execution_context =
|
42
|
+
@execution_context = execution_context
|
35
43
|
@ttl = ttl ? ttl.to_i : ttl
|
36
44
|
@auto_refresh_expired = !!auto_refresh_expired
|
37
45
|
self.class.instance ||= self
|
@@ -53,8 +61,8 @@ module Fixtury
|
|
53
61
|
return unless ttl
|
54
62
|
|
55
63
|
references.delete_if do |name, ref|
|
56
|
-
is_expired =
|
57
|
-
log { "expiring #{name}" } if is_expired
|
64
|
+
is_expired = ref_invalid?(ref)
|
65
|
+
log(level: LOG_LEVEL_INFO) { "expiring #{name}" } if is_expired
|
58
66
|
is_expired
|
59
67
|
end
|
60
68
|
end
|
@@ -76,7 +84,7 @@ module Fixtury
|
|
76
84
|
pattern = pattern[0...-1] if glob
|
77
85
|
references.delete_if do |key, _value|
|
78
86
|
hit = glob ? key.start_with?(pattern) : key == pattern
|
79
|
-
log(
|
87
|
+
log(level: LOG_LEVEL_INFO) { "clearing #{key}" } if hit
|
80
88
|
hit
|
81
89
|
end
|
82
90
|
dump_to_file
|
@@ -95,7 +103,7 @@ module Fixtury
|
|
95
103
|
full_name = dfn.name
|
96
104
|
ref = references[full_name]
|
97
105
|
result = ref&.real?
|
98
|
-
log { result ? "hit #{full_name}" : "miss #{full_name}" }
|
106
|
+
log(level: LOG_LEVEL_DEBUG) { result ? "hit #{full_name}" : "miss #{full_name}" }
|
99
107
|
result
|
100
108
|
end
|
101
109
|
|
@@ -108,8 +116,8 @@ module Fixtury
|
|
108
116
|
raise ::Fixtury::Errors::CircularDependencyError, full_name
|
109
117
|
end
|
110
118
|
|
111
|
-
if ref && auto_refresh_expired &&
|
112
|
-
log { "refreshing #{full_name}" }
|
119
|
+
if ref && auto_refresh_expired && ref_invalid?(ref)
|
120
|
+
log(level: LOG_LEVEL_INFO) { "refreshing #{full_name}" }
|
113
121
|
clear_ref(full_name)
|
114
122
|
ref = nil
|
115
123
|
end
|
@@ -117,11 +125,11 @@ module Fixtury
|
|
117
125
|
value = nil
|
118
126
|
|
119
127
|
if ref
|
120
|
-
log { "hit #{full_name}" }
|
128
|
+
log(level: LOG_LEVEL_DEBUG) { "hit #{full_name}" }
|
121
129
|
value = load_ref(ref.value)
|
122
130
|
if value.nil?
|
123
131
|
clear_ref(full_name)
|
124
|
-
log { "missing #{full_name}" }
|
132
|
+
log(level: LOG_LEVEL_DEBUG) { "missing #{full_name}" }
|
125
133
|
end
|
126
134
|
end
|
127
135
|
|
@@ -131,7 +139,7 @@ module Fixtury
|
|
131
139
|
|
132
140
|
value = dfn.call(store: self, execution_context: execution_context)
|
133
141
|
|
134
|
-
log { "store #{full_name}" }
|
142
|
+
log(level: LOG_LEVEL_INFO) { "store #{full_name}" }
|
135
143
|
|
136
144
|
ref = dump_ref(full_name, value)
|
137
145
|
ref = ::Fixtury::Reference.new(full_name, ref)
|
@@ -154,16 +162,20 @@ module Fixtury
|
|
154
162
|
references.delete(name)
|
155
163
|
end
|
156
164
|
|
157
|
-
def
|
158
|
-
return
|
165
|
+
def ref_invalid?(ref)
|
166
|
+
return true if ttl && ref.created_at < (Time.now.to_i - ttl)
|
159
167
|
|
160
|
-
|
168
|
+
!locator.recognize?(ref.value)
|
161
169
|
end
|
162
170
|
|
163
|
-
def log(
|
164
|
-
|
171
|
+
def log(level: LOG_LEVEL_DEBUG, name: "store")
|
172
|
+
desired_level = LOG_LEVELS.fetch(log_level) { LOG_LEVEL_NONE }
|
173
|
+
return if desired_level == LOG_LEVEL_NONE
|
174
|
+
|
175
|
+
message_level = LOG_LEVELS.fetch(level) { LOG_LEVEL_DEBUG }
|
176
|
+
return unless desired_level >= message_level
|
165
177
|
|
166
|
-
puts "[fixtury
|
178
|
+
puts "[fixtury|#{name}] #{yield}"
|
167
179
|
end
|
168
180
|
|
169
181
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "fixtury/store"
|
4
4
|
|
5
5
|
module Fixtury
|
6
|
-
module
|
6
|
+
module TestHooks
|
7
7
|
|
8
8
|
extend ::ActiveSupport::Concern
|
9
9
|
|
@@ -18,15 +18,45 @@ module Fixtury
|
|
18
18
|
self.fixtury_dependencies += names.flatten.compact.map(&:to_s)
|
19
19
|
end
|
20
20
|
|
21
|
+
def define_fixture(name, &block)
|
22
|
+
fixture_name = name
|
23
|
+
namespace_names = self.name.underscore.split("/")
|
24
|
+
|
25
|
+
ns = ::Fixtury.schema
|
26
|
+
|
27
|
+
namespace_names.each do |ns_name|
|
28
|
+
ns = ns.namespace(ns_name){}
|
29
|
+
end
|
30
|
+
|
31
|
+
ns.fixture(fixture_name, &block)
|
32
|
+
|
33
|
+
fixtury("#{namespace_names.join("/")}/#{fixture_name}")
|
34
|
+
end
|
35
|
+
|
21
36
|
end
|
22
37
|
|
23
38
|
def fixtury(name)
|
24
|
-
|
39
|
+
return nil unless ::Fixtury::Store.instance
|
40
|
+
|
41
|
+
name = name.to_s
|
42
|
+
|
43
|
+
unless name.include?("/")
|
44
|
+
local_name = "#{self.class.name.underscore}/#{name}"
|
45
|
+
if self.fixtury_dependencies.include?(local_name)
|
46
|
+
return ::Fixtury::Store.instance.get(local_name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
unless self.fixtury_dependencies.include?(name)
|
51
|
+
raise ArgumentError, "Unrecognized fixtury dependency `#{name}` for #{self.class}"
|
52
|
+
end
|
25
53
|
|
26
54
|
::Fixtury::Store.instance.get(name)
|
27
55
|
end
|
28
56
|
|
29
57
|
def fixtury_loaded?(name)
|
58
|
+
return false unless ::Fixtury::Store.instance
|
59
|
+
|
30
60
|
::Fixtury::Store.instance.loaded?(name)
|
31
61
|
end
|
32
62
|
|
@@ -70,6 +100,8 @@ module Fixtury
|
|
70
100
|
end
|
71
101
|
|
72
102
|
def clear_expired_fixtury_fixtures!
|
103
|
+
return unless ::Fixtury::Store.instance
|
104
|
+
|
73
105
|
::Fixtury::Store.instance.clear_expired_references!
|
74
106
|
end
|
75
107
|
|
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autotest
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '13.0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '13.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: sqlite
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,8 +160,6 @@ files:
|
|
160
160
|
- lib/fixtury/errors/fixture_not_defined_error.rb
|
161
161
|
- lib/fixtury/errors/schema_frozen_error.rb
|
162
162
|
- lib/fixtury/errors/unrecognizable_locator_error.rb
|
163
|
-
- lib/fixtury/execution_context.rb
|
164
|
-
- lib/fixtury/hooks.rb
|
165
163
|
- lib/fixtury/locator.rb
|
166
164
|
- lib/fixtury/locator_backend/common.rb
|
167
165
|
- lib/fixtury/locator_backend/globalid.rb
|
@@ -172,6 +170,7 @@ files:
|
|
172
170
|
- lib/fixtury/schema.rb
|
173
171
|
- lib/fixtury/store.rb
|
174
172
|
- lib/fixtury/tasks.rake
|
173
|
+
- lib/fixtury/test_hooks.rb
|
175
174
|
- lib/fixtury/version.rb
|
176
175
|
homepage: https://github.com/guideline-tech/fixtury
|
177
176
|
licenses: []
|
@@ -191,9 +190,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
190
|
version: '0'
|
192
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
192
|
requirements:
|
194
|
-
- - "
|
193
|
+
- - ">="
|
195
194
|
- !ruby/object:Gem::Version
|
196
|
-
version:
|
195
|
+
version: '0'
|
197
196
|
requirements: []
|
198
197
|
rubygems_version: 3.0.6
|
199
198
|
signing_key:
|