|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | RSpec.describe JsonSchematize::Generator do |
4 | | - |
5 | 4 | describe ".add_field" do |
6 | 5 | subject(:add_field) { klass.add_field(**field_params) } |
7 | 6 |
|
@@ -132,99 +131,6 @@ class KlassInit < described_class |
132 | 131 | end |
133 | 132 | end |
134 | 133 |
|
135 | | - describe "introspection" do |
136 | | - let(:instance) { klass.new(**params) } |
137 | | - |
138 | | - let(:params) do |
139 | | - { |
140 | | - id: 6457, |
141 | | - count: 9145, |
142 | | - style: :symbol, |
143 | | - something: "danger", |
144 | | - danger: :count, |
145 | | - zone: :zone, |
146 | | - } |
147 | | - end |
148 | | - |
149 | | - describe "#to_h" do |
150 | | - subject(:to_h) { instance.to_h } |
151 | | - |
152 | | - let(:klass) do |
153 | | - class IntrospectKlassToH < described_class |
154 | | - add_field name: :id, type: Integer |
155 | | - add_field name: :count, type: Integer |
156 | | - add_field name: :style, type: Symbol |
157 | | - add_field name: :something, type: String |
158 | | - add_field name: :danger, type: Symbol |
159 | | - add_field name: :zone, type: Symbol |
160 | | - end |
161 | | - IntrospectKlassToH |
162 | | - end |
163 | | - it { is_expected.to eq(params) } |
164 | | - end |
165 | | - |
166 | | - describe "#deep_inspect" do |
167 | | - subject(:deep_inspect) { instance.deep_inspect(with_raw_params: with_raw_params, with_field: with_field) } |
168 | | - |
169 | | - let(:klass) do |
170 | | - class IntrospectKlassDeepInspect < described_class |
171 | | - add_field name: :id, type: Integer |
172 | | - add_field name: :count, type: Integer |
173 | | - add_field name: :style, type: Symbol |
174 | | - add_field name: :something, type: String |
175 | | - add_field name: :danger, type: Symbol |
176 | | - add_field name: :zone, type: Symbol |
177 | | - end |
178 | | - IntrospectKlassDeepInspect |
179 | | - end |
180 | | - let(:with_raw_params) { false } |
181 | | - let(:with_field) { false } |
182 | | - let(:enumerate_expected) do |
183 | | - klass.fields.map do |field| |
184 | | - value = { |
185 | | - required: field.required, |
186 | | - acceptable_types: field.acceptable_types, |
187 | | - value: params[field.name], |
188 | | - } |
189 | | - value[:field] = field if with_field |
190 | | - value[:raw_params] = params if with_raw_params |
191 | | - [field.name, value] |
192 | | - end.to_h |
193 | | - end |
194 | | - |
195 | | - it { is_expected.to eq(enumerate_expected) } |
196 | | - |
197 | | - context 'when with_raw_params' do |
198 | | - let(:with_raw_params) { true } |
199 | | - it { is_expected.to eq(enumerate_expected) } |
200 | | - end |
201 | | - |
202 | | - context 'when with_field' do |
203 | | - let(:with_field) { true } |
204 | | - |
205 | | - it { is_expected.to eq(enumerate_expected) } |
206 | | - end |
207 | | - end |
208 | | - |
209 | | - describe "#inspect" do |
210 | | - subject(:inspect) { instance.inspect } |
211 | | - |
212 | | - let(:klass) do |
213 | | - class IntrospectKlassInspect < described_class |
214 | | - add_field name: :id, type: Integer |
215 | | - add_field name: :count, type: Integer |
216 | | - add_field name: :style, type: Symbol |
217 | | - add_field name: :something, type: String |
218 | | - add_field name: :danger, type: Symbol |
219 | | - add_field name: :zone, type: Symbol |
220 | | - end |
221 | | - IntrospectKlassInspect |
222 | | - end |
223 | | - let(:expected) { "#<#{klass} - required fields: #{params.keys}; #{instance.to_h.map { |k, v| "#{k}:#{v}" }.join(", ")}>" } |
224 | | - it { is_expected.to eq(expected) } |
225 | | - end |
226 | | - end |
227 | | - |
228 | 134 | context "when modifying values" do |
229 | 135 | let(:instance) { klass.new(raise_on_error: raise_on_error, **params) } |
230 | 136 | let(:klass) do |
|
0 commit comments