fixtury 0.2.1 → 0.3.0.beta
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 +14 -44
- data/lib/fixtury/definition_executor.rb +78 -0
- data/lib/fixtury/schema.rb +26 -2
- data/lib/fixtury/store.rb +1 -4
- data/lib/fixtury/test_hooks.rb +7 -5
- data/lib/fixtury/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 965698b591633e500ea9a84c99f860e333abc4b43670adda323a39f156834971
|
4
|
+
data.tar.gz: 05157e6800473b9eb4d9a34d5f72572726db3318e1e415b5c9307b243c94e524
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cfe05cd9ee47eb81c70247ef902870bebeaa563035ab19ae920646fcf0421483f13ab0efd23a3ee2e0293092a70be7259b4088a3fbf56ebaf585788c8160993
|
7
|
+
data.tar.gz: 96797ae9dbf6b4ccc6d9e3149be61dc5b4cc57d7b4baec2f9355aff35f89d0b6a3fc25b3f11fc2c7198eabeaed0298f97e51c49f96fadce6a13709bf493a845c
|
data/Gemfile.lock
CHANGED
data/lib/fixtury/definition.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "fixtury/definition_executor"
|
4
|
+
|
3
5
|
module Fixtury
|
4
6
|
class Definition
|
5
7
|
|
@@ -24,55 +26,23 @@ module Fixtury
|
|
24
26
|
@enhancements.any?
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
value
|
34
|
-
end
|
29
|
+
def info
|
30
|
+
{
|
31
|
+
name: name,
|
32
|
+
loc: location_from_callable(callable),
|
33
|
+
enhancements: enhancements.map { |e| location_from_callable(e) },
|
34
|
+
}
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
return yield unless store
|
41
|
-
|
42
|
-
store.with_relative_schema(schema) do
|
43
|
-
yield
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def run_callable(store:, callable:, execution_context: nil, value:)
|
48
|
-
args = []
|
49
|
-
args << value unless value.nil?
|
50
|
-
if callable.arity > args.length
|
51
|
-
raise ArgumentError, "A store store must be provided if the definition expects it." unless store
|
52
|
-
|
53
|
-
args << store
|
54
|
-
end
|
55
|
-
|
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
|
37
|
+
def call(store: nil, execution_context: nil)
|
38
|
+
executor = ::Fixtury::DefinitionExecutor.new(store: store, definition: self, execution_context: execution_context)
|
39
|
+
executor.__call
|
63
40
|
end
|
64
41
|
|
65
|
-
def
|
66
|
-
return
|
42
|
+
def location_from_callable(callable)
|
43
|
+
return nil unless callable.respond_to?(:source_location)
|
67
44
|
|
68
|
-
|
69
|
-
value = if execution_context.respond_to?(:around_fixture)
|
70
|
-
execution_context.around_fixture(self) { yield execution_context }
|
71
|
-
else
|
72
|
-
yield execution_context
|
73
|
-
end
|
74
|
-
execution_context.after_fixture(self, value) if execution_context.respond_to?(:after_fixture)
|
75
|
-
value
|
45
|
+
callable.source_location.join(":")
|
76
46
|
end
|
77
47
|
|
78
48
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixtury
|
4
|
+
class DefinitionExecutor
|
5
|
+
|
6
|
+
attr_reader :value, :execution_type, :definition, :store, :execution_context
|
7
|
+
|
8
|
+
def initialize(store: nil, execution_context: nil, definition:)
|
9
|
+
@store = store
|
10
|
+
@definition = definition
|
11
|
+
@execution_context = execution_context
|
12
|
+
@execution_type = nil
|
13
|
+
@value = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def __call
|
17
|
+
maybe_set_store_context do
|
18
|
+
provide_schema_hooks do
|
19
|
+
run_callable(callable: definition.callable, type: :definition)
|
20
|
+
definition.enhancements.each do |e|
|
21
|
+
run_callable(callable: e, type: :enhancement)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
value
|
27
|
+
end
|
28
|
+
|
29
|
+
def get(name)
|
30
|
+
raise ArgumentError, "A store is required for #{definition.name}" unless store
|
31
|
+
|
32
|
+
store.get(name, execution_context: execution_context)
|
33
|
+
end
|
34
|
+
alias [] get
|
35
|
+
|
36
|
+
def method_missing(method_name, *args, &block)
|
37
|
+
return super unless execution_context
|
38
|
+
|
39
|
+
execution_context.send(method_name, *args, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def respond_to_missing?(method_name)
|
43
|
+
return super unless execution_context
|
44
|
+
|
45
|
+
execution_context.respond_to?(method_name, true)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def run_callable(callable:, type:)
|
51
|
+
@execution_type = type
|
52
|
+
|
53
|
+
@value = if callable.arity.positive?
|
54
|
+
instance_exec(self, &callable)
|
55
|
+
else
|
56
|
+
instance_eval(&callable)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def maybe_set_store_context
|
61
|
+
return yield unless store
|
62
|
+
|
63
|
+
store.with_relative_schema(definition.schema) do
|
64
|
+
yield
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def provide_schema_hooks
|
69
|
+
return yield unless definition.schema
|
70
|
+
|
71
|
+
@value = definition.schema.around_fixture_hook(self) do
|
72
|
+
yield
|
73
|
+
value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
data/lib/fixtury/schema.rb
CHANGED
@@ -9,16 +9,37 @@ require "fixtury/errors/schema_frozen_error"
|
|
9
9
|
module Fixtury
|
10
10
|
class Schema
|
11
11
|
|
12
|
-
attr_reader :definitions, :children, :name, :parent, :relative_name
|
12
|
+
attr_reader :definitions, :children, :name, :parent, :relative_name, :around_fixture_definition
|
13
13
|
|
14
14
|
def initialize(parent:, name:)
|
15
15
|
@name = name
|
16
16
|
@parent = parent
|
17
17
|
@relative_name = @name.split("/").last
|
18
|
+
@around_fixture_definition = nil
|
18
19
|
@frozen = false
|
19
20
|
reset!
|
20
21
|
end
|
21
22
|
|
23
|
+
def around_fixture(&block)
|
24
|
+
@around_fixture_definition = block
|
25
|
+
end
|
26
|
+
|
27
|
+
def around_fixture_hook(executor, &definition)
|
28
|
+
maybe_invoke_parent_around_fixture_hook(executor) do
|
29
|
+
if around_fixture_definition.nil?
|
30
|
+
yield
|
31
|
+
else
|
32
|
+
around_fixture_definition.call(executor, definition)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def maybe_invoke_parent_around_fixture_hook(executor, &block)
|
38
|
+
return yield unless parent
|
39
|
+
|
40
|
+
parent.around_fixture_hook(executor, &block)
|
41
|
+
end
|
42
|
+
|
22
43
|
def reset!
|
23
44
|
@children = {}
|
24
45
|
@definitions = {}
|
@@ -99,6 +120,8 @@ module Fixtury
|
|
99
120
|
end
|
100
121
|
end
|
101
122
|
|
123
|
+
around_fixture(&other_ns.around_fixture_definition) if other_ns.around_fixture_definition
|
124
|
+
|
102
125
|
self
|
103
126
|
end
|
104
127
|
|
@@ -172,6 +195,7 @@ module Fixtury
|
|
172
195
|
self.class.new(name: child_name, parent: self)
|
173
196
|
end
|
174
197
|
end
|
198
|
+
child
|
175
199
|
end
|
176
200
|
|
177
201
|
def find_child_definition(name:)
|
@@ -187,7 +211,7 @@ module Fixtury
|
|
187
211
|
def build_child_name(name:)
|
188
212
|
name = name&.to_s
|
189
213
|
raise ArgumentError, "`name` must be provided" if name.nil?
|
190
|
-
raise ArgumentError, "#{name} is invalid. `name` must contain only a-z, A-Z, 0-9, and _." unless
|
214
|
+
raise ArgumentError, "#{name} is invalid. `name` must contain only a-z, A-Z, 0-9, and _." unless /^[a-zA-Z_0-9]+$/.match?(name)
|
191
215
|
|
192
216
|
arr = ["", self.name, name]
|
193
217
|
arr.join("/").gsub(%r{/{2,}}, "/")
|
data/lib/fixtury/store.rb
CHANGED
@@ -21,7 +21,6 @@ module Fixtury
|
|
21
21
|
attr_reader :filepath, :references, :ttl, :auto_refresh_expired
|
22
22
|
attr_reader :schema, :locator
|
23
23
|
attr_reader :log_level
|
24
|
-
attr_reader :execution_context
|
25
24
|
|
26
25
|
def initialize(
|
27
26
|
filepath: nil,
|
@@ -29,7 +28,6 @@ module Fixtury
|
|
29
28
|
log_level: nil,
|
30
29
|
ttl: nil,
|
31
30
|
schema: nil,
|
32
|
-
execution_context: nil,
|
33
31
|
auto_refresh_expired: false
|
34
32
|
)
|
35
33
|
@schema = schema || ::Fixtury.schema
|
@@ -39,7 +37,6 @@ module Fixtury
|
|
39
37
|
@locator = locator
|
40
38
|
@filepath = filepath
|
41
39
|
@references = @filepath && ::File.file?(@filepath) ? ::YAML.load_file(@filepath) : {}
|
42
|
-
@execution_context = execution_context
|
43
40
|
@ttl = ttl ? ttl.to_i : ttl
|
44
41
|
@auto_refresh_expired = !!auto_refresh_expired
|
45
42
|
self.class.instance ||= self
|
@@ -107,7 +104,7 @@ module Fixtury
|
|
107
104
|
result
|
108
105
|
end
|
109
106
|
|
110
|
-
def get(name)
|
107
|
+
def get(name, execution_context: nil)
|
111
108
|
dfn = schema.get_definition!(name)
|
112
109
|
full_name = dfn.name
|
113
110
|
ref = references[full_name]
|
data/lib/fixtury/test_hooks.rb
CHANGED
@@ -40,14 +40,16 @@ module Fixtury
|
|
40
40
|
self.fixtury_dependencies += names.flatten.compact.map(&:to_s)
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
accessor_option = opts.key?(:accessor) ? opts[:accessor] : true
|
44
44
|
|
45
|
-
|
45
|
+
if accessor_option
|
46
|
+
|
47
|
+
if accessor_option != true && names.length > 1
|
46
48
|
raise ArgumentError, "A named :accessor option is only available when providing one fixture"
|
47
49
|
end
|
48
50
|
|
49
51
|
names.each do |fixture_name|
|
50
|
-
method_name =
|
52
|
+
method_name = accessor_option == true ? fixture_name.split("/").last : accessor_option
|
51
53
|
ivar = :"@#{method_name}"
|
52
54
|
|
53
55
|
class_eval <<-EV, __FILE__, __LINE__ + 1
|
@@ -72,7 +74,7 @@ module Fixtury
|
|
72
74
|
unless name.include?("/")
|
73
75
|
local_name = "#{self.class.name.underscore}/#{name}"
|
74
76
|
if self.fixtury_dependencies.include?(local_name)
|
75
|
-
return fixtury_store.get(local_name)
|
77
|
+
return fixtury_store.get(local_name, execution_context: self)
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
@@ -80,7 +82,7 @@ module Fixtury
|
|
80
82
|
raise ArgumentError, "Unrecognized fixtury dependency `#{name}` for #{self.class}"
|
81
83
|
end
|
82
84
|
|
83
|
-
fixtury_store.get(name)
|
85
|
+
fixtury_store.get(name, execution_context: self)
|
84
86
|
end
|
85
87
|
|
86
88
|
def fixtury_store
|
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.3.0.beta
|
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-10-
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autotest
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- fixtury.gemspec
|
156
156
|
- lib/fixtury.rb
|
157
157
|
- lib/fixtury/definition.rb
|
158
|
+
- lib/fixtury/definition_executor.rb
|
158
159
|
- lib/fixtury/errors/already_defined_error.rb
|
159
160
|
- lib/fixtury/errors/circular_dependency_error.rb
|
160
161
|
- lib/fixtury/errors/fixture_not_defined_error.rb
|
@@ -190,9 +191,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
191
|
version: '0'
|
191
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
193
|
requirements:
|
193
|
-
- - "
|
194
|
+
- - ">"
|
194
195
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
196
|
+
version: 1.3.1
|
196
197
|
requirements: []
|
197
198
|
rubygems_version: 3.0.6
|
198
199
|
signing_key:
|