fixtury 0.3.0.beta → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -5
- data/lib/fixtury.rb +5 -1
- data/lib/fixtury/definition.rb +4 -1
- data/lib/fixtury/reference.rb +7 -2
- data/lib/fixtury/schema.rb +11 -10
- data/lib/fixtury/test_hooks.rb +23 -11
- 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: 6e98c0301a74feb23eac901666363ac54ed521d91a497a3e24c981cc7237edb9
|
4
|
+
data.tar.gz: 949cd3db96159d072029ee2c7ca2b04579fd99cb471d1a22d75a2f0b72d8aced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ecd015fa82cbe560932a73b303cde3132614efaa8d231f6e0dea0272086c8b0441d7964a10039ded2fb5c64e89ff5a74835b9054fbfc1d675a42f479294142f
|
7
|
+
data.tar.gz: 1a8d220621bcdb4aff855fcd7cba8bfd51cd542bf3361747abba7e159fed2bdd2428d284cff3173829abda2ea9d27a8540cd687e4b65b1ce0345ec6e6b4efdf0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# Fixtury
|
2
2
|
|
3
|
-
|
3
|
+
Fixtury aims to provide an interface for creating, managing, and accessing test data in a simple and efficient way. It has no opinion on how you generate the data, it simply provides efficient ways to access it.
|
4
4
|
|
5
|
-
|
5
|
+
Often, fixture frameworks require you to either heavily maintain static fixtures or generate all your fixtures at runtime. Fixtury attempts to find a middle ground that enables a faster and more effecient development process.
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
For example, if a developer is running a test locally in their development environment there's no reason to build all fixtures for your suite of 30k tests. Instead, if we're able to track the fixture dependencies of the tests that are running we can build (and cache) the data relevant for the specific tests that are run.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class MyTest < ::ActiveSupport::TestCase
|
11
|
+
include ::Fixtury::TestHooks
|
9
12
|
|
10
13
|
fixtury "users.fresh"
|
11
14
|
let(:user) { fixtury("users.fresh") }
|
@@ -15,7 +18,6 @@ class MyTest < ::Test
|
|
15
18
|
end
|
16
19
|
|
17
20
|
end
|
18
|
-
|
19
21
|
```
|
20
22
|
|
21
23
|
Loading this file would ensure `users.fresh` is loaded into the fixture set before the suite is run. In the context of ActiveSupport::TestCase, the Fixtury::Hooks file will ensure the database records are present prior to your suite running. Setting `use_transactional_fixtures` ensures all records are rolled back prior to running another test.
|
data/lib/fixtury.rb
CHANGED
@@ -8,15 +8,19 @@ require "fixtury/schema"
|
|
8
8
|
require "fixtury/locator"
|
9
9
|
require "fixtury/store"
|
10
10
|
|
11
|
+
# Top level namespace of the gem
|
11
12
|
module Fixtury
|
12
13
|
|
14
|
+
# Shortcut for opening the top level schema.
|
13
15
|
def self.define(&block)
|
14
16
|
schema.define(&block)
|
15
17
|
schema
|
16
18
|
end
|
17
19
|
|
20
|
+
# The default top level schema. Fixtury::Schema instances can be completely self-contained but most
|
21
|
+
# usage would be through this shared definition.
|
18
22
|
def self.schema
|
19
|
-
@
|
23
|
+
@schema ||= ::Fixtury::Schema.new(parent: nil, name: "")
|
20
24
|
end
|
21
25
|
|
22
26
|
end
|
data/lib/fixtury/definition.rb
CHANGED
@@ -7,14 +7,17 @@ module Fixtury
|
|
7
7
|
|
8
8
|
attr_reader :name
|
9
9
|
attr_reader :schema
|
10
|
+
alias parent schema
|
11
|
+
attr_reader :options
|
10
12
|
|
11
13
|
attr_reader :callable
|
12
14
|
attr_reader :enhancements
|
13
15
|
|
14
|
-
def initialize(schema: nil, name:, &block)
|
16
|
+
def initialize(schema: nil, name:, options: {}, &block)
|
15
17
|
@name = name
|
16
18
|
@schema = schema
|
17
19
|
@callable = block
|
20
|
+
@options = options
|
18
21
|
@enhancements = []
|
19
22
|
end
|
20
23
|
|
data/lib/fixtury/reference.rb
CHANGED
@@ -9,12 +9,17 @@ module Fixtury
|
|
9
9
|
new(name, HOLDER_VALUE)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
def self.create(name, value)
|
13
|
+
new(name, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :name, :value, :created_at, :options
|
13
17
|
|
14
|
-
def initialize(name, value)
|
18
|
+
def initialize(name, value, options = {})
|
15
19
|
@name = name
|
16
20
|
@value = value
|
17
21
|
@created_at = Time.now.to_i
|
22
|
+
@options = options
|
18
23
|
end
|
19
24
|
|
20
25
|
def holder?
|
data/lib/fixtury/schema.rb
CHANGED
@@ -9,13 +9,14 @@ 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, :around_fixture_definition
|
12
|
+
attr_reader :definitions, :children, :name, :parent, :relative_name, :around_fixture_definition, :options
|
13
13
|
|
14
|
-
def initialize(parent:, name:)
|
14
|
+
def initialize(parent:, name:, options: {})
|
15
15
|
@name = name
|
16
16
|
@parent = parent
|
17
17
|
@relative_name = @name.split("/").last
|
18
18
|
@around_fixture_definition = nil
|
19
|
+
@options = options
|
19
20
|
@frozen = false
|
20
21
|
reset!
|
21
22
|
end
|
@@ -83,19 +84,19 @@ module Fixtury
|
|
83
84
|
out.join("\n")
|
84
85
|
end
|
85
86
|
|
86
|
-
def namespace(name, &block)
|
87
|
+
def namespace(name, options = {}, &block)
|
87
88
|
ensure_not_frozen!
|
88
89
|
ensure_no_conflict!(name: name, definitions: true, namespaces: false)
|
89
90
|
|
90
|
-
child = find_or_create_child_schema(name: name)
|
91
|
+
child = find_or_create_child_schema(name: name, options: options)
|
91
92
|
child.instance_eval(&block) if block_given?
|
92
93
|
child
|
93
94
|
end
|
94
95
|
|
95
|
-
def fixture(name, &block)
|
96
|
+
def fixture(name, options = {}, &block)
|
96
97
|
ensure_not_frozen!
|
97
98
|
ensure_no_conflict!(name: name, definitions: true, namespaces: true)
|
98
|
-
create_child_definition(name: name, &block)
|
99
|
+
create_child_definition(name: name, options: options, &block)
|
99
100
|
end
|
100
101
|
|
101
102
|
def enhance(name, &block)
|
@@ -186,13 +187,13 @@ module Fixtury
|
|
186
187
|
children[name.to_s]
|
187
188
|
end
|
188
189
|
|
189
|
-
def find_or_create_child_schema(name:)
|
190
|
+
def find_or_create_child_schema(name:, options:)
|
190
191
|
name = name.to_s
|
191
192
|
child = find_child_schema(name: name)
|
192
193
|
child ||= begin
|
193
194
|
children[name] = begin
|
194
195
|
child_name = build_child_name(name: name)
|
195
|
-
self.class.new(name: child_name, parent: self)
|
196
|
+
self.class.new(name: child_name, parent: self, options: options)
|
196
197
|
end
|
197
198
|
end
|
198
199
|
child
|
@@ -202,9 +203,9 @@ module Fixtury
|
|
202
203
|
definitions[name.to_s]
|
203
204
|
end
|
204
205
|
|
205
|
-
def create_child_definition(name:, &block)
|
206
|
+
def create_child_definition(name:, options:, &block)
|
206
207
|
child_name = build_child_name(name: name)
|
207
|
-
definition = ::Fixtury::Definition.new(name: child_name, schema: self, &block)
|
208
|
+
definition = ::Fixtury::Definition.new(name: child_name, schema: self, options: options, &block)
|
208
209
|
definitions[name.to_s] = definition
|
209
210
|
end
|
210
211
|
|
data/lib/fixtury/test_hooks.rb
CHANGED
@@ -11,6 +11,9 @@ module Fixtury
|
|
11
11
|
included do
|
12
12
|
class_attribute :fixtury_dependencies
|
13
13
|
self.fixtury_dependencies = Set.new
|
14
|
+
|
15
|
+
class_attribute :local_fixtury_dependencies
|
16
|
+
self.local_fixtury_dependencies = Set.new
|
14
17
|
end
|
15
18
|
|
16
19
|
module ClassMethods
|
@@ -22,7 +25,7 @@ module Fixtury
|
|
22
25
|
if block_given?
|
23
26
|
raise ArgumentError, "A fixture cannot be defined in an anonymous class" if name.nil?
|
24
27
|
|
25
|
-
namespace =
|
28
|
+
namespace = fixtury_namespace
|
26
29
|
|
27
30
|
ns = ::Fixtury.schema
|
28
31
|
|
@@ -30,9 +33,11 @@ module Fixtury
|
|
30
33
|
ns = ns.namespace(ns_name){}
|
31
34
|
end
|
32
35
|
|
33
|
-
names.
|
36
|
+
names.map! do |fixture_name|
|
34
37
|
ns.fixture(fixture_name, &definition)
|
35
|
-
|
38
|
+
new_name = "/#{namespace}/#{fixture_name}"
|
39
|
+
self.local_fixtury_dependencies += [new_name]
|
40
|
+
new_name
|
36
41
|
end
|
37
42
|
|
38
43
|
# otherwise, just record the dependency
|
@@ -40,12 +45,14 @@ module Fixtury
|
|
40
45
|
self.fixtury_dependencies += names.flatten.compact.map(&:to_s)
|
41
46
|
end
|
42
47
|
|
43
|
-
accessor_option = opts
|
48
|
+
accessor_option = opts[:as]
|
49
|
+
accessor_option = opts[:accessor] if accessor_option.nil? # old version, backwards compatability
|
50
|
+
accessor_option = accessor_option.nil? ? true : accessor_option
|
44
51
|
|
45
52
|
if accessor_option
|
46
53
|
|
47
54
|
if accessor_option != true && names.length > 1
|
48
|
-
raise ArgumentError, "A named :
|
55
|
+
raise ArgumentError, "A named :as option is only available when providing one fixture"
|
49
56
|
end
|
50
57
|
|
51
58
|
names.each do |fixture_name|
|
@@ -64,6 +71,10 @@ module Fixtury
|
|
64
71
|
end
|
65
72
|
end
|
66
73
|
|
74
|
+
def fixtury_namespace
|
75
|
+
name.underscore
|
76
|
+
end
|
77
|
+
|
67
78
|
end
|
68
79
|
|
69
80
|
def fixtury(name)
|
@@ -71,14 +82,15 @@ module Fixtury
|
|
71
82
|
|
72
83
|
name = name.to_s
|
73
84
|
|
85
|
+
# in the case that we're looking for a relative fixture, see if it's registered relative to the test's namespace.
|
74
86
|
unless name.include?("/")
|
75
|
-
local_name = "
|
76
|
-
if
|
87
|
+
local_name = "/#{self.class.fixtury_namespace}/#{name}"
|
88
|
+
if local_fixtury_dependencies.include?(local_name)
|
77
89
|
return fixtury_store.get(local_name, execution_context: self)
|
78
90
|
end
|
79
91
|
end
|
80
92
|
|
81
|
-
unless
|
93
|
+
unless fixtury_dependencies.include?(name) || local_fixtury_dependencies.include?(name)
|
82
94
|
raise ArgumentError, "Unrecognized fixtury dependency `#{name}` for #{self.class}"
|
83
95
|
end
|
84
96
|
|
@@ -101,7 +113,7 @@ module Fixtury
|
|
101
113
|
|
102
114
|
# piggybacking activerecord fixture setup for now.
|
103
115
|
def setup_fixtures(*args)
|
104
|
-
if fixtury_dependencies.any?
|
116
|
+
if fixtury_dependencies.any? || local_fixtury_dependencies.any?
|
105
117
|
setup_fixtury_fixtures
|
106
118
|
else
|
107
119
|
super
|
@@ -110,7 +122,7 @@ module Fixtury
|
|
110
122
|
|
111
123
|
# piggybacking activerecord fixture setup for now.
|
112
124
|
def teardown_fixtures(*args)
|
113
|
-
if fixtury_dependencies.any?
|
125
|
+
if fixtury_dependencies.any? || local_fixtury_dependencies.any?
|
114
126
|
teardown_fixtury_fixtures
|
115
127
|
else
|
116
128
|
super
|
@@ -141,7 +153,7 @@ module Fixtury
|
|
141
153
|
end
|
142
154
|
|
143
155
|
def load_all_fixtury_fixtures!
|
144
|
-
fixtury_dependencies.each do |name|
|
156
|
+
(fixtury_dependencies | local_fixtury_dependencies).each do |name|
|
145
157
|
fixtury(name) unless fixtury_loaded?(name)
|
146
158
|
end
|
147
159
|
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.3.
|
4
|
+
version: 0.3.4
|
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-23 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:
|