fixtury 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58e7de147f87ad30560d984945e6cc8f9d660336f053c31365ff3fd607e491b3
4
- data.tar.gz: f8c3d80fd0e51aba0607be65ef39c411cdb33de3427f3d3df017b039f4952012
3
+ metadata.gz: 35c4db20425a837221a7c979e51371b77e00790cded54b182b31e62f7f57d8c2
4
+ data.tar.gz: cbdb024ba301b393b97604879594c1d9d53bfe1ffd4f24959824e8f41e1fe4e2
5
5
  SHA512:
6
- metadata.gz: da1af2403b30fac589172ff22e45f7095ba5d4464d32723e555f6aa952deecfdbd4722cc02a5a3e36e75d3660a3185fd4f99c9b34434aa72513b34ff3258aa6e
7
- data.tar.gz: 1aa8adfec328a20afc3afef72af0125636de46f7a23cafd67e9cbb38bb5e3c7c8a85f2099336e780c9c54a67e621361b07de147440a62ceed70c5254071c691c
6
+ metadata.gz: 4748b476b6683ac9275a0c62ebca36f346f5d2bea208d47f55dfd836b521283c383aee7847961ffc90726292fd187389fc65b650dd508f9c67288fa32ae88c6c
7
+ data.tar.gz: bc765697630a9780752ab2ab9512dbe6bd92cee4f612dfa1ba11437d1f59f3e0c58a7d5a107576704d0018507ce989bf2e8726c165f244bf8757676c301a4f4d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fixtury (0.4.0)
4
+ fixtury (0.4.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,13 @@
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fixtury
2
4
  module Errors
3
5
  class SchemaFrozenError < ::StandardError
@@ -5,22 +5,33 @@ require "fixtury/path"
5
5
  require "fixtury/errors/already_defined_error"
6
6
  require "fixtury/errors/fixture_not_defined_error"
7
7
  require "fixtury/errors/schema_frozen_error"
8
+ require "fixtury/errors/option_collision_error"
8
9
 
9
10
  module Fixtury
10
11
  class Schema
11
12
 
12
13
  attr_reader :definitions, :children, :name, :parent, :relative_name, :around_fixture_definition, :options
13
14
 
14
- def initialize(parent:, name:, options: {})
15
+ def initialize(parent:, name:)
15
16
  @name = name
16
17
  @parent = parent
17
18
  @relative_name = @name.split("/").last
18
19
  @around_fixture_definition = nil
19
- @options = options
20
+ @options = {}
20
21
  @frozen = false
21
22
  reset!
22
23
  end
23
24
 
25
+ def merge_options(opts = {})
26
+ opts.each_pair do |k, v|
27
+ if options.key?(k) && options[k] != v
28
+ raise ::Fixtury::Errors::OptionCollisionError.new(name, k, options[k], v)
29
+ end
30
+
31
+ options[k] = v
32
+ end
33
+ end
34
+
24
35
  def around_fixture(&block)
25
36
  @around_fixture_definition = block
26
37
  end
@@ -109,14 +120,14 @@ module Fixtury
109
120
  def merge(other_ns)
110
121
  ensure_not_frozen!
111
122
  other_ns.definitions.each_pair do |name, dfn|
112
- fixture(name, &dfn.callable)
123
+ fixture(name, dfn.options, &dfn.callable)
113
124
  dfn.enhancements.each do |e|
114
125
  enhance(name, &e)
115
126
  end
116
127
  end
117
128
 
118
129
  other_ns.children.each_pair do |name, other_ns_child|
119
- namespace(name) do
130
+ namespace(name, other_ns_child.options) do
120
131
  merge(other_ns_child)
121
132
  end
122
133
  end
@@ -193,9 +204,10 @@ module Fixtury
193
204
  child ||= begin
194
205
  children[name] = begin
195
206
  child_name = build_child_name(name: name)
196
- self.class.new(name: child_name, parent: self, options: options)
207
+ self.class.new(name: child_name, parent: self)
197
208
  end
198
209
  end
210
+ child.merge_options(options)
199
211
  child
200
212
  end
201
213
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fixtury
4
4
 
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.1"
6
6
 
7
7
  end
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.0
4
+ version: 0.4.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-11-03 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: autotest
@@ -159,6 +159,7 @@ files:
159
159
  - lib/fixtury/errors/already_defined_error.rb
160
160
  - lib/fixtury/errors/circular_dependency_error.rb
161
161
  - lib/fixtury/errors/fixture_not_defined_error.rb
162
+ - lib/fixtury/errors/option_collision_error.rb
162
163
  - lib/fixtury/errors/schema_frozen_error.rb
163
164
  - lib/fixtury/errors/unrecognizable_locator_error.rb
164
165
  - lib/fixtury/locator.rb