fixtury 0.4.1 → 1.0.0.beta2
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/.ruby-version +1 -1
- data/Gemfile.lock +48 -44
- data/README.md +4 -4
- data/fixtury.gemspec +6 -6
- data/lib/fixtury/configuration.rb +117 -0
- data/lib/fixtury/definition.rb +34 -38
- data/lib/fixtury/definition_executor.rb +23 -52
- data/lib/fixtury/dependency.rb +52 -0
- data/lib/fixtury/dependency_store.rb +45 -0
- data/lib/fixtury/errors.rb +81 -0
- data/lib/fixtury/hooks.rb +90 -0
- data/lib/fixtury/locator.rb +52 -23
- data/lib/fixtury/locator_backend/common.rb +17 -19
- data/lib/fixtury/locator_backend/global_id.rb +32 -0
- data/lib/fixtury/locator_backend/memory.rb +9 -8
- data/lib/fixtury/mutation_observer.rb +140 -0
- data/lib/fixtury/path_resolver.rb +45 -0
- data/lib/fixtury/railtie.rb +4 -0
- data/lib/fixtury/reference.rb +12 -10
- data/lib/fixtury/schema.rb +47 -225
- data/lib/fixtury/schema_node.rb +175 -0
- data/lib/fixtury/store.rb +168 -84
- data/lib/fixtury/test_hooks.rb +125 -101
- data/lib/fixtury/version.rb +1 -1
- data/lib/fixtury.rb +84 -12
- metadata +35 -35
- data/lib/fixtury/errors/already_defined_error.rb +0 -13
- data/lib/fixtury/errors/circular_dependency_error.rb +0 -13
- data/lib/fixtury/errors/fixture_not_defined_error.rb +0 -13
- data/lib/fixtury/errors/option_collision_error.rb +0 -13
- data/lib/fixtury/errors/schema_frozen_error.rb +0 -13
- data/lib/fixtury/errors/unrecognizable_locator_error.rb +0 -11
- data/lib/fixtury/locator_backend/globalid.rb +0 -32
- data/lib/fixtury/path.rb +0 -36
- data/lib/fixtury/tasks.rake +0 -10
data/lib/fixtury.rb
CHANGED
@@ -1,14 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/array/extract_options"
|
4
5
|
require "active_support/core_ext/module/attribute_accessors"
|
5
6
|
require "active_support/core_ext/module/delegation"
|
7
|
+
require "active_support/core_ext/object/acts_like"
|
8
|
+
require "active_support/core_ext/object/blank"
|
9
|
+
|
6
10
|
require "fixtury/version"
|
7
|
-
|
11
|
+
|
12
|
+
require "fixtury/configuration"
|
13
|
+
require "fixtury/definition_executor"
|
14
|
+
require "fixtury/dependency"
|
15
|
+
require "fixtury/dependency_store"
|
16
|
+
require "fixtury/errors"
|
17
|
+
require "fixtury/hooks"
|
8
18
|
require "fixtury/locator"
|
19
|
+
require "fixtury/path_resolver"
|
20
|
+
require "fixtury/reference"
|
9
21
|
require "fixtury/store"
|
10
22
|
|
11
|
-
|
23
|
+
require "fixtury/schema_node"
|
24
|
+
require "fixtury/definition"
|
25
|
+
require "fixtury/schema"
|
26
|
+
|
27
|
+
|
28
|
+
# Top level namespace of the gem. The accessors provided on the Fixtury namespace are meant to be shared
|
29
|
+
# across the entire application. The Fixtury::Schema instance is the primary interface for defining and
|
30
|
+
# accessing fixtures and can be accessed via Fixtury.schema.
|
12
31
|
module Fixtury
|
13
32
|
|
14
33
|
LOG_LEVELS = {
|
@@ -20,29 +39,79 @@ module Fixtury
|
|
20
39
|
|
21
40
|
DEFAULT_LOG_LEVEL = LOG_LEVEL_INFO
|
22
41
|
|
42
|
+
def self.configuration
|
43
|
+
@configuration ||= ::Fixtury::Configuration.new
|
44
|
+
yield @configuration if block_given?
|
45
|
+
@configuration
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.configure(&block)
|
49
|
+
self.configuration(&block)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
23
53
|
# Shortcut for opening the top level schema.
|
24
54
|
def self.define(&block)
|
25
55
|
schema.define(&block)
|
26
56
|
schema
|
27
57
|
end
|
28
58
|
|
59
|
+
# Global hooks accessor. Fixtury will call these hooks at various points in the lifecycle of a fixture or setup.
|
60
|
+
def self.hooks
|
61
|
+
@hooks ||= ::Fixtury::Hooks.new
|
62
|
+
end
|
63
|
+
|
29
64
|
# The default top level schema. Fixtury::Schema instances can be completely self-contained but most
|
30
65
|
# usage would be through this shared definition.
|
31
66
|
def self.schema
|
32
|
-
@schema ||= ::Fixtury::Schema.new
|
67
|
+
@schema ||= ::Fixtury::Schema.new
|
33
68
|
end
|
34
69
|
|
35
|
-
def self.
|
36
|
-
|
70
|
+
def self.schema=(schema)
|
71
|
+
@schema = schema
|
72
|
+
end
|
73
|
+
|
74
|
+
# Default store for fixtures. This is a shared store that can be used across the application.
|
75
|
+
def self.store
|
76
|
+
@store ||= ::Fixtury::Store.new
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.store=(store)
|
80
|
+
@store = store
|
81
|
+
end
|
82
|
+
|
83
|
+
# Require each schema file to ensure that all definitions are loaded.
|
84
|
+
def self.load_all_schemas
|
85
|
+
configuration.fixture_files.each do |filepath|
|
86
|
+
require filepath
|
87
|
+
end
|
88
|
+
end
|
37
89
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
90
|
+
# Ensure all definitions are loaded and then load all known fixtures.
|
91
|
+
def self.load_all_fixtures
|
92
|
+
load_all_schemas
|
93
|
+
Fixtury.store.load_all
|
42
94
|
end
|
43
95
|
|
44
|
-
|
45
|
-
|
96
|
+
# Remove all references from the active store and reset the dependency file
|
97
|
+
def self.reset
|
98
|
+
log("resetting", level: LOG_LEVEL_INFO)
|
99
|
+
|
100
|
+
configuration.reset
|
101
|
+
store.reset
|
102
|
+
end
|
103
|
+
|
104
|
+
# Perform a reset if any of the tracked files have changed.
|
105
|
+
def self.reset_if_changed
|
106
|
+
if configuration.files_changed?
|
107
|
+
reset
|
108
|
+
else
|
109
|
+
log("no changes, skipping reset", level: LOG_LEVEL_INFO)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.log(text = nil, level: LOG_LEVEL_DEBUG, name: nil, newline: true)
|
114
|
+
desired_level = LOG_LEVELS.fetch(configuration.log_level) { DEFAULT_LOG_LEVEL }
|
46
115
|
return if desired_level == LOG_LEVEL_NONE
|
47
116
|
|
48
117
|
message_level = LOG_LEVELS.fetch(level) { LOG_LEVEL_DEBUG }
|
@@ -53,7 +122,10 @@ module Fixtury
|
|
53
122
|
msg << "]"
|
54
123
|
msg << " #{text}" if text
|
55
124
|
msg << " #{yield}" if block_given?
|
56
|
-
|
125
|
+
msg << "\n" if newline
|
126
|
+
|
127
|
+
print msg
|
128
|
+
msg
|
57
129
|
end
|
58
130
|
|
59
131
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixtury
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,21 +25,21 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: globalid
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: activerecord
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,21 +67,21 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: m
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: minitest
|
84
|
+
name: minitest
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -112,18 +112,18 @@ dependencies:
|
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '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: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: sqlite3
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description:
|
139
|
+
description:
|
140
140
|
email:
|
141
141
|
- mike@guideline.com
|
142
142
|
executables: []
|
@@ -154,24 +154,24 @@ files:
|
|
154
154
|
- bin/setup
|
155
155
|
- fixtury.gemspec
|
156
156
|
- lib/fixtury.rb
|
157
|
+
- lib/fixtury/configuration.rb
|
157
158
|
- lib/fixtury/definition.rb
|
158
159
|
- lib/fixtury/definition_executor.rb
|
159
|
-
- lib/fixtury/
|
160
|
-
- lib/fixtury/
|
161
|
-
- lib/fixtury/errors
|
162
|
-
- lib/fixtury/
|
163
|
-
- lib/fixtury/errors/schema_frozen_error.rb
|
164
|
-
- lib/fixtury/errors/unrecognizable_locator_error.rb
|
160
|
+
- lib/fixtury/dependency.rb
|
161
|
+
- lib/fixtury/dependency_store.rb
|
162
|
+
- lib/fixtury/errors.rb
|
163
|
+
- lib/fixtury/hooks.rb
|
165
164
|
- lib/fixtury/locator.rb
|
166
165
|
- lib/fixtury/locator_backend/common.rb
|
167
|
-
- lib/fixtury/locator_backend/
|
166
|
+
- lib/fixtury/locator_backend/global_id.rb
|
168
167
|
- lib/fixtury/locator_backend/memory.rb
|
169
|
-
- lib/fixtury/
|
168
|
+
- lib/fixtury/mutation_observer.rb
|
169
|
+
- lib/fixtury/path_resolver.rb
|
170
170
|
- lib/fixtury/railtie.rb
|
171
171
|
- lib/fixtury/reference.rb
|
172
172
|
- lib/fixtury/schema.rb
|
173
|
+
- lib/fixtury/schema_node.rb
|
173
174
|
- lib/fixtury/store.rb
|
174
|
-
- lib/fixtury/tasks.rake
|
175
175
|
- lib/fixtury/test_hooks.rb
|
176
176
|
- lib/fixtury/version.rb
|
177
177
|
homepage: https://github.com/guideline-tech/fixtury
|
@@ -181,7 +181,7 @@ metadata:
|
|
181
181
|
homepage_uri: https://github.com/guideline-tech/fixtury
|
182
182
|
source_code_uri: https://github.com/guideline-tech/fixtury
|
183
183
|
changelog_uri: https://github.com/guideline-tech/fixtury
|
184
|
-
post_install_message:
|
184
|
+
post_install_message:
|
185
185
|
rdoc_options: []
|
186
186
|
require_paths:
|
187
187
|
- lib
|
@@ -196,8 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
- !ruby/object:Gem::Version
|
197
197
|
version: '0'
|
198
198
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
200
|
-
signing_key:
|
199
|
+
rubygems_version: 3.5.6
|
200
|
+
signing_key:
|
201
201
|
specification_version: 4
|
202
202
|
summary: Treat fixtures like factories and factories like fixtures
|
203
203
|
test_files: []
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fixtury
|
4
|
-
module Errors
|
5
|
-
class OptionCollisionError < ::StandardError
|
6
|
-
|
7
|
-
def initialize(schema_name, option_key, old_value, new_value)
|
8
|
-
super("The #{schema_name.inspect} schema #{option_key.inspect} option value of #{old_value.inspect} conflicts with the new value #{new_value.inspect}.")
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./common"
|
4
|
-
require "globalid"
|
5
|
-
|
6
|
-
module Fixtury
|
7
|
-
module LocatorBackend
|
8
|
-
class GlobalID
|
9
|
-
|
10
|
-
include ::Fixtury::LocatorBackend::Common
|
11
|
-
|
12
|
-
MATCHER = %r{^gid://}.freeze
|
13
|
-
|
14
|
-
def recognized_reference?(ref)
|
15
|
-
ref.is_a?(String) && MATCHER.match?(ref)
|
16
|
-
end
|
17
|
-
|
18
|
-
def recognized_value?(val)
|
19
|
-
val.respond_to?(:to_global_id)
|
20
|
-
end
|
21
|
-
|
22
|
-
def load_recognized_reference(ref)
|
23
|
-
::GlobalID::Locator.locate ref
|
24
|
-
end
|
25
|
-
|
26
|
-
def dump_recognized_value(value)
|
27
|
-
value.to_global_id.to_s
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/fixtury/path.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fixtury
|
4
|
-
class Path
|
5
|
-
|
6
|
-
def initialize(namespace:, path:)
|
7
|
-
@namespace = namespace.to_s
|
8
|
-
@path = path.to_s
|
9
|
-
@full_path = (
|
10
|
-
@path.start_with?("/") ?
|
11
|
-
@path :
|
12
|
-
File.expand_path(::File.join(@namespace, @path), "/")
|
13
|
-
)
|
14
|
-
@segments = @full_path.split("/")
|
15
|
-
end
|
16
|
-
|
17
|
-
def top_level_namespace
|
18
|
-
return "" if @segments.size == 1
|
19
|
-
|
20
|
-
@segments.first
|
21
|
-
end
|
22
|
-
|
23
|
-
def relative?
|
24
|
-
@path.start_with?(".")
|
25
|
-
end
|
26
|
-
|
27
|
-
def possible_absolute_paths
|
28
|
-
@possible_absolute_paths ||= begin
|
29
|
-
out = [@full_path]
|
30
|
-
out << @path unless relative?
|
31
|
-
out
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
data/lib/fixtury/tasks.rake
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :fixtury do
|
4
|
-
task :setup
|
5
|
-
|
6
|
-
desc "Clear fixtures from your cache. Accepts a pattern or fixture name such as foo/bar or /foo/*. Default pattern is /*"
|
7
|
-
task :clear_cache, [:pattern] => :setup do |_t, args|
|
8
|
-
::Fixtury::Store.instance.clear_cache!(pattern: args[:pattern])
|
9
|
-
end
|
10
|
-
end
|