fixtury 0.2.0 → 0.2.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/Gemfile.lock +1 -1
- data/lib/fixtury/store.rb +1 -1
- data/lib/fixtury/test_hooks.rb +51 -18
- data/lib/fixtury/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9090092db55914068c6478939047d638ee8bb678ee53a41f0d36380bf2df7dea
|
4
|
+
data.tar.gz: 4e58164635a72d63e059a5622b1c867556235ba09537e127b5498f94a3bf8e60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e1ddd158beafe83cbe9e9d32abf10a49dcdb59709cc372f31a29a1a52c3eafe0b802eba8015ccdb429444678d94941db42dedb6202396b958c8d53d2e6f9d2
|
7
|
+
data.tar.gz: 70e2abc1abc6324e3523631a6f2caf936d0b0859eeb14b41fec843b766bf648d047b1e09e9d9bb6da60131f06be23e7e02c1adcf86be30910387581b7e191d3e
|
data/Gemfile.lock
CHANGED
data/lib/fixtury/store.rb
CHANGED
@@ -80,7 +80,7 @@ module Fixtury
|
|
80
80
|
def clear_cache!(pattern: nil)
|
81
81
|
pattern ||= "*"
|
82
82
|
pattern = "/" + pattern unless pattern.start_with?("/")
|
83
|
-
glob = pattern.
|
83
|
+
glob = pattern.end_with?("*")
|
84
84
|
pattern = pattern[0...-1] if glob
|
85
85
|
references.delete_if do |key, _value|
|
86
86
|
hit = glob ? key.start_with?(pattern) : key == pattern
|
data/lib/fixtury/test_hooks.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "fixtury/store"
|
4
|
+
require "active_support/core_ext/class/attribute"
|
4
5
|
|
5
6
|
module Fixtury
|
6
7
|
module TestHooks
|
@@ -14,36 +15,64 @@ module Fixtury
|
|
14
15
|
|
15
16
|
module ClassMethods
|
16
17
|
|
17
|
-
def fixtury(*names)
|
18
|
-
|
19
|
-
|
18
|
+
def fixtury(*names, &definition)
|
19
|
+
opts = names.extract_options!
|
20
|
+
|
21
|
+
# define fixtures if blocks are given
|
22
|
+
if block_given?
|
23
|
+
raise ArgumentError, "A fixture cannot be defined in an anonymous class" if name.nil?
|
24
|
+
|
25
|
+
namespace = name.underscore
|
20
26
|
|
21
|
-
|
22
|
-
fixture_name = name
|
23
|
-
namespace_names = self.name.underscore.split("/")
|
27
|
+
ns = ::Fixtury.schema
|
24
28
|
|
25
|
-
|
29
|
+
namespace.split("/").each do |ns_name|
|
30
|
+
ns = ns.namespace(ns_name){}
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
names.each do |fixture_name|
|
34
|
+
ns.fixture(fixture_name, &definition)
|
35
|
+
self.fixtury_dependencies += ["#{namespace}/#{fixture_name}"]
|
36
|
+
end
|
37
|
+
|
38
|
+
# otherwise, just record the dependency
|
39
|
+
else
|
40
|
+
self.fixtury_dependencies += names.flatten.compact.map(&:to_s)
|
29
41
|
end
|
30
42
|
|
31
|
-
|
43
|
+
if opts[:accessor]
|
44
|
+
|
45
|
+
if opts[:accessor] != true && names.length > 1
|
46
|
+
raise ArgumentError, "A named :accessor option is only available when providing one fixture"
|
47
|
+
end
|
32
48
|
|
33
|
-
|
49
|
+
names.each do |fixture_name|
|
50
|
+
method_name = opts[:accessor] == true ? fixture_name.split("/").last : opts[:accessor]
|
51
|
+
ivar = :"@#{method_name}"
|
52
|
+
|
53
|
+
class_eval <<-EV, __FILE__, __LINE__ + 1
|
54
|
+
def #{method_name}
|
55
|
+
return #{ivar} if defined?(#{ivar})
|
56
|
+
|
57
|
+
value = fixtury("#{fixture_name}")
|
58
|
+
#{ivar} = value
|
59
|
+
end
|
60
|
+
EV
|
61
|
+
end
|
62
|
+
end
|
34
63
|
end
|
35
64
|
|
36
65
|
end
|
37
66
|
|
38
67
|
def fixtury(name)
|
39
|
-
return nil unless
|
68
|
+
return nil unless fixtury_store
|
40
69
|
|
41
70
|
name = name.to_s
|
42
71
|
|
43
72
|
unless name.include?("/")
|
44
73
|
local_name = "#{self.class.name.underscore}/#{name}"
|
45
74
|
if self.fixtury_dependencies.include?(local_name)
|
46
|
-
return
|
75
|
+
return fixtury_store.get(local_name)
|
47
76
|
end
|
48
77
|
end
|
49
78
|
|
@@ -51,13 +80,17 @@ module Fixtury
|
|
51
80
|
raise ArgumentError, "Unrecognized fixtury dependency `#{name}` for #{self.class}"
|
52
81
|
end
|
53
82
|
|
54
|
-
|
83
|
+
fixtury_store.get(name)
|
84
|
+
end
|
85
|
+
|
86
|
+
def fixtury_store
|
87
|
+
::Fixtury::Store.instance
|
55
88
|
end
|
56
89
|
|
57
90
|
def fixtury_loaded?(name)
|
58
|
-
return false unless
|
91
|
+
return false unless fixtury_store
|
59
92
|
|
60
|
-
|
93
|
+
fixtury_store.loaded?(name)
|
61
94
|
end
|
62
95
|
|
63
96
|
def fixtury_database_connections
|
@@ -100,9 +133,9 @@ module Fixtury
|
|
100
133
|
end
|
101
134
|
|
102
135
|
def clear_expired_fixtury_fixtures!
|
103
|
-
return unless
|
136
|
+
return unless fixtury_store
|
104
137
|
|
105
|
-
|
138
|
+
fixtury_store.clear_expired_references!
|
106
139
|
end
|
107
140
|
|
108
141
|
def load_all_fixtury_fixtures!
|
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.2.
|
4
|
+
version: 0.2.1
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autotest
|