cornucopia 0.1.12
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 +7 -0
- data/.gitignore +51 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +16 -0
- data/LICENSE.TXT +22 -0
- data/README.md +341 -0
- data/Rakefile +18 -0
- data/cornucopia.gemspec +39 -0
- data/lib/cornucopia.rb +18 -0
- data/lib/cornucopia/capybara/finder_diagnostics.rb +536 -0
- data/lib/cornucopia/capybara/finder_extensions.rb +89 -0
- data/lib/cornucopia/capybara/install_finder_extensions.rb +105 -0
- data/lib/cornucopia/capybara/install_matcher_extensions.rb +39 -0
- data/lib/cornucopia/capybara/matcher_extensions.rb +83 -0
- data/lib/cornucopia/capybara/page_diagnostics.rb +228 -0
- data/lib/cornucopia/cucumber_hooks.rb +38 -0
- data/lib/cornucopia/factory_girl/dynamic_association.rb +14 -0
- data/lib/cornucopia/rspec_hooks.rb +37 -0
- data/lib/cornucopia/site_prism/element_extensions.rb +273 -0
- data/lib/cornucopia/site_prism/install_element_extensions.rb +23 -0
- data/lib/cornucopia/site_prism/page_application.rb +126 -0
- data/lib/cornucopia/source_files/collapse.gif +0 -0
- data/lib/cornucopia/source_files/cornucopia.css +162 -0
- data/lib/cornucopia/source_files/expand.gif +0 -0
- data/lib/cornucopia/source_files/index_base.html +10 -0
- data/lib/cornucopia/source_files/index_contents.html +2 -0
- data/lib/cornucopia/source_files/more_info.js +87 -0
- data/lib/cornucopia/source_files/report_base.html +10 -0
- data/lib/cornucopia/source_files/report_contents.html +3 -0
- data/lib/cornucopia/spinach_hooks.rb +51 -0
- data/lib/cornucopia/util/configuration.rb +493 -0
- data/lib/cornucopia/util/configured_report.rb +520 -0
- data/lib/cornucopia/util/file_asset.rb +46 -0
- data/lib/cornucopia/util/generic_settings.rb +37 -0
- data/lib/cornucopia/util/log_capture.rb +97 -0
- data/lib/cornucopia/util/pretty_formatter.rb +580 -0
- data/lib/cornucopia/util/report_builder.rb +474 -0
- data/lib/cornucopia/util/report_formatters.rb +11 -0
- data/lib/cornucopia/util/report_table.rb +195 -0
- data/lib/cornucopia/version.rb +3 -0
- data/lib/tasks/cornucopia_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +27 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cucumber.yml +8 -0
- data/spec/dummy/config/database.yml +37 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/features/support/env.rb +66 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/cucumber.rake +65 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/cucumber +10 -0
- data/spec/fixtures/sample_page.html +150 -0
- data/spec/lib/capybara/finder_diagnostics_spec.rb +517 -0
- data/spec/lib/capybara/finder_extensions_spec.rb +328 -0
- data/spec/lib/capybara/page_diagnostics_spec.rb +277 -0
- data/spec/lib/site_prism/element_extensions_spec.rb +290 -0
- data/spec/lib/site_prism/page_application_spec.rb +81 -0
- data/spec/lib/util/configuration_spec.rb +254 -0
- data/spec/lib/util/configured_report_spec.rb +1058 -0
- data/spec/lib/util/file_asset_spec.rb +86 -0
- data/spec/lib/util/generic_settings_spec.rb +48 -0
- data/spec/lib/util/log_capture_spec.rb +151 -0
- data/spec/lib/util/pretty_formatter_spec.rb +694 -0
- data/spec/lib/util/report_builder_spec.rb +983 -0
- data/spec/lib/util/report_formatters_spec.rb +13 -0
- data/spec/lib/util/report_table_exception_spec.rb +21 -0
- data/spec/lib/util/report_table_spec.rb +319 -0
- data/spec/pages/cornucopia_report_app.rb +10 -0
- data/spec/pages/google/email_page.rb +22 -0
- data/spec/pages/google/login_page.rb +25 -0
- data/spec/rails_helper.rb +43 -0
- data/spec/sample_report.rb +45 -0
- data/spec/spec_helper.rb +81 -0
- metadata +410 -0
|
@@ -0,0 +1,1058 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require ::File.expand_path("../../../lib/cornucopia/util/configured_report", File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
class SubTestClass
|
|
5
|
+
@sub_basic_variable
|
|
6
|
+
@sub_overridden_variable
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@sub_basic_variable = "sub basic variable"
|
|
10
|
+
@sub_overridden_variable = "sub overridden variable"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def sub_overridden_variable
|
|
14
|
+
"sub processed variable"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class TestPoint < Struct.new(:x, :y)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class TestClass
|
|
22
|
+
@basic_variable
|
|
23
|
+
@overridden_variable
|
|
24
|
+
@sub_class_variable
|
|
25
|
+
@hash_variable
|
|
26
|
+
@nil_variable
|
|
27
|
+
@struct_variable
|
|
28
|
+
|
|
29
|
+
def initialize
|
|
30
|
+
@basic_variable = "basic variable"
|
|
31
|
+
@overridden_variable = "overridden variable"
|
|
32
|
+
@sub_class_variable = SubTestClass.new
|
|
33
|
+
@hash_variable = {
|
|
34
|
+
key_1: "value",
|
|
35
|
+
"another key" => "another value"
|
|
36
|
+
}
|
|
37
|
+
@array_variable = [1, "b", :fred_sym]
|
|
38
|
+
@nil_variable = nil
|
|
39
|
+
@struct_variable = TestPoint.new(rand(0..1_000), rand(0..1_000))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def overridden_variable
|
|
43
|
+
"processed variable"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe Cornucopia::Util::ConfiguredReport do
|
|
48
|
+
let(:simple_report) { Cornucopia::Util::ConfiguredReport.new }
|
|
49
|
+
let(:test) { TestClass.new }
|
|
50
|
+
|
|
51
|
+
around(:each) do |example|
|
|
52
|
+
expect(File.directory?(Rails.root.join("cornucopia_report/"))).to be_falsey
|
|
53
|
+
|
|
54
|
+
begin
|
|
55
|
+
example.run
|
|
56
|
+
ensure
|
|
57
|
+
Cornucopia::Util::ReportBuilder.current_report.close if (Cornucopia::Util::ReportBuilder.class_variable_get("@@current_report"))
|
|
58
|
+
|
|
59
|
+
FileUtils.rm_rf Rails.root.join("cornucopia_report/")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "#get_instance_variable" do
|
|
64
|
+
it "gets the instance variable" do
|
|
65
|
+
expect(simple_report.get_instance_variable(test, :@basic_variable, "basic_variable")).to be == "basic variable"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "gets the getter function if there is one" do
|
|
69
|
+
expect(simple_report.get_instance_variable(test, :@overridden_variable, "overridden_variable")).
|
|
70
|
+
to be == "processed variable"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe "#split_full_field_symbol" do
|
|
75
|
+
it "splits a list by __" do
|
|
76
|
+
expect(simple_report.split_full_field_symbol(:var1__var2__var3)).to be == [:var1, :var2, :var3]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "splits a list by __, and can handle varaibles with _" do
|
|
80
|
+
expect(simple_report.split_full_field_symbol(:var1___var2__var3)).to be == [:var1, :_var2, :var3]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "splits a list by __, and can handle varaibles with __" do
|
|
84
|
+
expect(simple_report.split_full_field_symbol(:var1____var2__var3)).to be == [:var1, :__var2, :var3]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "splits a list by __, and can handle varaibles with ____" do
|
|
88
|
+
expect(simple_report.split_full_field_symbol(:var1______var2__var3)).to be == [:var1, :____var2, :var3]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "can handle arbitrary _ and depths" do
|
|
92
|
+
results = []
|
|
93
|
+
|
|
94
|
+
rand(5..20).times do |index|
|
|
95
|
+
sub_symbol = Faker::Lorem.word
|
|
96
|
+
if rand(5) == 0 || index == 0
|
|
97
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
results << sub_symbol.to_sym
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
expect(simple_report.split_full_field_symbol(results.join("__").to_sym)).to be == results
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "#split_field_symbols" do
|
|
108
|
+
it "returns [] when passed nil" do
|
|
109
|
+
expect(simple_report.split_field_symbols(nil)).to be == []
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "calls #split_full_field_symbol for every element in an array" do
|
|
113
|
+
results = []
|
|
114
|
+
source = []
|
|
115
|
+
|
|
116
|
+
rand(5..20).times do
|
|
117
|
+
sub_results = []
|
|
118
|
+
rand(5..20).times do
|
|
119
|
+
sub_symbol = Faker::Lorem.word
|
|
120
|
+
if rand(5) == 0
|
|
121
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
sub_results << sub_symbol.to_sym
|
|
125
|
+
end
|
|
126
|
+
results << { report_element: sub_results }
|
|
127
|
+
source << sub_results.join("__")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
expect(simple_report.split_field_symbols(source)).to be == results
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
describe "#find_variable_in_set" do
|
|
135
|
+
it "finds variables that are in the set" do
|
|
136
|
+
results = []
|
|
137
|
+
|
|
138
|
+
rand(5..20).times do
|
|
139
|
+
sub_results = []
|
|
140
|
+
rand(5..20).times do
|
|
141
|
+
sub_symbol = Faker::Lorem.word
|
|
142
|
+
if rand(5) == 0
|
|
143
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
sub_results << sub_symbol.to_sym
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
results << { report_element: sub_results }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
set_test = results.sample
|
|
153
|
+
expect(simple_report.find_variable_in_set(results, set_test[:report_element][0..-2], set_test[:report_element][-1])).
|
|
154
|
+
to be == set_test
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "does not find variables that are only partial matches" do
|
|
158
|
+
results = []
|
|
159
|
+
|
|
160
|
+
rand(5..20).times do
|
|
161
|
+
sub_results = []
|
|
162
|
+
rand(5..20).times do
|
|
163
|
+
sub_symbol = Faker::Lorem.word
|
|
164
|
+
if rand(5) == 0
|
|
165
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
sub_results << sub_symbol.to_sym
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
results << { report_element: sub_results }
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
set_test = results.sample[:report_element]
|
|
175
|
+
len = rand(0..set_test.length - 3)
|
|
176
|
+
|
|
177
|
+
expect(simple_report.find_variable_in_set(results, set_test[0..len], set_test[len + 1])).to be_falsey
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it "does not find variables that are not in the set" do
|
|
181
|
+
results = []
|
|
182
|
+
|
|
183
|
+
rand(5..20).times do
|
|
184
|
+
sub_results = []
|
|
185
|
+
rand(5..20).times do
|
|
186
|
+
sub_symbol = Faker::Lorem.word
|
|
187
|
+
if rand(5) == 0
|
|
188
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
sub_results << sub_symbol.to_sym
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
results << { report_element: sub_results }
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# There is a slim, but statistically unlikely chance that
|
|
198
|
+
# there will be another item in results with the first set
|
|
199
|
+
# of words identical, except for the last word.
|
|
200
|
+
# I'll take this risk.
|
|
201
|
+
set_test = results.sample[:report_element]
|
|
202
|
+
begin
|
|
203
|
+
test_var = Faker::Lorem.word
|
|
204
|
+
end while test_var == set_test[-1]
|
|
205
|
+
|
|
206
|
+
expect(simple_report.find_variable_in_set(results, set_test[0..-2], test_var)).to be_falsey
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it "is used by #expand_variable_inline?" do
|
|
210
|
+
results = []
|
|
211
|
+
source = []
|
|
212
|
+
|
|
213
|
+
rand(5..20).times do
|
|
214
|
+
sub_results = []
|
|
215
|
+
rand(5..20).times do
|
|
216
|
+
sub_symbol = Faker::Lorem.word
|
|
217
|
+
if rand(5) == 0
|
|
218
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
sub_results << sub_symbol.to_sym
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
results << sub_results
|
|
225
|
+
source << sub_results.join("__")
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
set_test = results.sample
|
|
229
|
+
simple_report.expand_inline_fields = source
|
|
230
|
+
expect(simple_report.expand_variable_inline?(set_test[0..-2], set_test[-1])).to be_truthy
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it "is used by #expand_variable?" do
|
|
234
|
+
results = []
|
|
235
|
+
source = []
|
|
236
|
+
|
|
237
|
+
rand(5..20).times do
|
|
238
|
+
sub_results = []
|
|
239
|
+
rand(5..20).times do
|
|
240
|
+
sub_symbol = Faker::Lorem.word
|
|
241
|
+
if rand(5) == 0
|
|
242
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
sub_results << sub_symbol.to_sym
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
results << sub_results
|
|
249
|
+
source << sub_results.join("__")
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
set_test = results.sample
|
|
253
|
+
simple_report.expand_inline_fields = source
|
|
254
|
+
expect(simple_report.expand_variable?(set_test[0..-2], set_test[-1])).to be_truthy
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it "is used by #expand_variable?" do
|
|
258
|
+
results = []
|
|
259
|
+
source = []
|
|
260
|
+
|
|
261
|
+
rand(5..20).times do
|
|
262
|
+
sub_results = []
|
|
263
|
+
rand(5..20).times do
|
|
264
|
+
sub_symbol = Faker::Lorem.word
|
|
265
|
+
if rand(5) == 0
|
|
266
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
sub_results << sub_symbol.to_sym
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
results << sub_results
|
|
273
|
+
source << sub_results.join("__")
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
set_test = results.sample
|
|
277
|
+
simple_report.expand_fields = source
|
|
278
|
+
expect(simple_report.expand_variable?(set_test[0..-2], set_test[-1])).to be_truthy
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
it "is used by #exclude_variable?" do
|
|
282
|
+
results = []
|
|
283
|
+
source = []
|
|
284
|
+
|
|
285
|
+
rand(5..20).times do
|
|
286
|
+
sub_results = []
|
|
287
|
+
rand(5..20).times do
|
|
288
|
+
sub_symbol = Faker::Lorem.word
|
|
289
|
+
if rand(5) == 0
|
|
290
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
sub_results << sub_symbol.to_sym
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
results << sub_results
|
|
297
|
+
source << sub_results.join("__")
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
set_test = results.sample
|
|
301
|
+
simple_report.exclude_fields = source
|
|
302
|
+
expect(simple_report.exclude_variable?(set_test[0..-2], set_test[-1])).to be_truthy
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it "supports wildcards as the last field to match" do
|
|
306
|
+
results = []
|
|
307
|
+
|
|
308
|
+
rand(5..20).times do
|
|
309
|
+
sub_results = []
|
|
310
|
+
rand(5..20).times do
|
|
311
|
+
sub_symbol = Faker::Lorem.word
|
|
312
|
+
if rand(5) == 0
|
|
313
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
sub_results << sub_symbol.to_sym
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
results << { report_element: sub_results }
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# There is a slim, but statistically unlikely chance that
|
|
323
|
+
# there will be another item in results with the first set
|
|
324
|
+
# of words identical, except for the last word.
|
|
325
|
+
# I'll take this risk.
|
|
326
|
+
rand_pos = rand(0..results.length - 1)
|
|
327
|
+
set_test = results[rand_pos][:report_element].clone
|
|
328
|
+
results[rand_pos][:report_element][-1] = "*".to_sym
|
|
329
|
+
|
|
330
|
+
expect(simple_report.find_variable_in_set(results, set_test[0..-2], set_test[-1])).to be_truthy
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
it "supports wildcards as any field to match" do
|
|
334
|
+
results = []
|
|
335
|
+
|
|
336
|
+
rand(5..20).times do
|
|
337
|
+
sub_results = []
|
|
338
|
+
rand(5..20).times do
|
|
339
|
+
sub_symbol = Faker::Lorem.word
|
|
340
|
+
if rand(5) == 0
|
|
341
|
+
sub_symbol = (("_" * rand(1..10)) + sub_symbol)
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
sub_results << sub_symbol.to_sym
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
results << { report_element: sub_results }
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# There is a slim, but statistically unlikely chance that
|
|
351
|
+
# there will be another item in results with the first set
|
|
352
|
+
# of words identical, except for the last word.
|
|
353
|
+
# I'll take this risk.
|
|
354
|
+
|
|
355
|
+
rand_pos = rand(0..results.length - 1)
|
|
356
|
+
set_test = results[rand_pos][:report_element].clone
|
|
357
|
+
|
|
358
|
+
results[rand_pos][:report_element][rand(0..results[rand_pos][:report_element].length - 1)] = "*".to_sym
|
|
359
|
+
|
|
360
|
+
expect(simple_report.find_variable_in_set(results, set_test[0..-2], set_test[-1])).to be_truthy
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
describe "#export_field_record" do
|
|
365
|
+
it "takes a passed in parent" do
|
|
366
|
+
string_val = "string"
|
|
367
|
+
|
|
368
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
369
|
+
expect(report_table).to receive(:write_stats).with(:string_val, "string", {})
|
|
370
|
+
|
|
371
|
+
simple_report.export_field_record({ report_element: [:string_val] },
|
|
372
|
+
string_val,
|
|
373
|
+
:string_val,
|
|
374
|
+
report_table,
|
|
375
|
+
0,
|
|
376
|
+
report_object_set: true)
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
it "takes a parent that is an instance variable" do
|
|
381
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
382
|
+
expect(report_table).to receive(:write_stats).with(:overridden_variable, "processed variable", {})
|
|
383
|
+
|
|
384
|
+
simple_report.export_field_record({ report_element: [:test, :overridden_variable] },
|
|
385
|
+
test,
|
|
386
|
+
:test,
|
|
387
|
+
report_table,
|
|
388
|
+
1)
|
|
389
|
+
end
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
it "deals with the variable we're fetching being the instance variable" do
|
|
393
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
394
|
+
expect(report_table).to receive(:write_stats).with(:overridden_variable, "processed variable", {})
|
|
395
|
+
|
|
396
|
+
simple_report.export_field_record({ report_element: [:test, :overridden_variable] },
|
|
397
|
+
test,
|
|
398
|
+
:test,
|
|
399
|
+
report_table,
|
|
400
|
+
1)
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
it "outputs the variable .to_s" do
|
|
405
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
406
|
+
expect(report_table).to receive(:write_stats).with(:overridden_variable, "processed variable", {})
|
|
407
|
+
|
|
408
|
+
simple_report.export_field_record({ report_element: [:test, :overridden_variable, :to_s] },
|
|
409
|
+
test,
|
|
410
|
+
:test,
|
|
411
|
+
report_table,
|
|
412
|
+
1)
|
|
413
|
+
end
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
it "finds the parent object if it is a member function" do
|
|
417
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
418
|
+
expect(report_table).to receive(:write_stats).with(:overridden_variable, "processed variable", {})
|
|
419
|
+
|
|
420
|
+
simple_report.export_field_record({ report_element: [:test, :overridden_variable] },
|
|
421
|
+
test,
|
|
422
|
+
:test,
|
|
423
|
+
report_table,
|
|
424
|
+
1)
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
it "finds the parent object if it is accessible via []" do
|
|
429
|
+
hash = { my_hash_key: "hash key" }
|
|
430
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
431
|
+
expect(report_table).to receive(:write_stats).with(:my_hash_key, "hash key", {})
|
|
432
|
+
|
|
433
|
+
simple_report.export_field_record({ report_element: [:hash, :my_hash_key] },
|
|
434
|
+
hash,
|
|
435
|
+
:hash,
|
|
436
|
+
report_table,
|
|
437
|
+
1)
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
it "finds the parent object if it is an array index expanded" do
|
|
442
|
+
array = [1, 2, 3]
|
|
443
|
+
|
|
444
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
445
|
+
expect(report_table).to receive(:write_stats).with("0".to_sym, 1, {})
|
|
446
|
+
|
|
447
|
+
simple_report.export_field_record({ report_element: [:array, 0.to_s.to_sym] },
|
|
448
|
+
array,
|
|
449
|
+
:array,
|
|
450
|
+
report_table,
|
|
451
|
+
1,
|
|
452
|
+
{ expanded_field: true })
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
it "finds the parent object if it is an array index expanded inline and puts the right value out" do
|
|
457
|
+
array = [1, 2, 3]
|
|
458
|
+
simple_report.expand_inline_fields = [:array]
|
|
459
|
+
|
|
460
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
461
|
+
expect(report_table).to receive(:write_stats).with("array[0]", 1, {})
|
|
462
|
+
|
|
463
|
+
simple_report.export_field_record({ report_element: [:array, 0.to_s.to_sym] },
|
|
464
|
+
array,
|
|
465
|
+
:array,
|
|
466
|
+
report_table,
|
|
467
|
+
1)
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
it "finds the parent object if it is an array index exported directly" do
|
|
472
|
+
array = [1, 2, 3]
|
|
473
|
+
|
|
474
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
475
|
+
expect(report_table).to receive(:write_stats).with("array[0]", 1, {})
|
|
476
|
+
|
|
477
|
+
simple_report.export_field_record({ report_element: [:array, 0.to_s.to_sym] },
|
|
478
|
+
array,
|
|
479
|
+
:array,
|
|
480
|
+
report_table,
|
|
481
|
+
1)
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
it "outputs an error if it cannot find the parent object" do
|
|
486
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
487
|
+
expect(report_table).to receive(:write_stats).with("ERROR", "Could not identify field: hash__my_hash_key while exporting hash__my_hash_key")
|
|
488
|
+
|
|
489
|
+
simple_report.export_field_record({ report_element: [:hash, :my_hash_key] },
|
|
490
|
+
test,
|
|
491
|
+
:hash,
|
|
492
|
+
report_table,
|
|
493
|
+
1)
|
|
494
|
+
end
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
it "expands leaf nodes" do
|
|
498
|
+
report_result_table = nil
|
|
499
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
500
|
+
report_result_table = report_table
|
|
501
|
+
simple_report.expand_fields = [:test]
|
|
502
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
503
|
+
test,
|
|
504
|
+
:test,
|
|
505
|
+
report_table,
|
|
506
|
+
0,
|
|
507
|
+
report_object_set: true)
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
expect(report_result_table.full_table).to match(/\>\ntest\n\</)
|
|
511
|
+
expect(report_result_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
512
|
+
expect(report_result_table.full_table).to match(/\>basic variable\</)
|
|
513
|
+
expect(report_result_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
514
|
+
expect(report_result_table.full_table).to match(/\>processed variable\</)
|
|
515
|
+
expect(report_result_table.full_table).to match(/@sub_basic_variable=/)
|
|
516
|
+
expect(report_result_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
517
|
+
expect(report_result_table.full_table).to match(/@sub_overridden_variable=/)
|
|
518
|
+
expect(report_result_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
it "expands leaf nodes inline" do
|
|
522
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
523
|
+
simple_report.expand_fields = [:test]
|
|
524
|
+
simple_report.expand_inline_fields = [:test]
|
|
525
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
526
|
+
test,
|
|
527
|
+
:test,
|
|
528
|
+
report_table,
|
|
529
|
+
0,
|
|
530
|
+
report_object_set: true)
|
|
531
|
+
|
|
532
|
+
expect(report_table.full_table).not_to match(/\>\ntest\n\</)
|
|
533
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
534
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
535
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
536
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
537
|
+
expect(report_table.full_table).to match(/@sub_basic_variable=/)
|
|
538
|
+
expect(report_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
539
|
+
expect(report_table.full_table).to match(/@sub_overridden_variable=/)
|
|
540
|
+
expect(report_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
541
|
+
end
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
it "expands instance variables" do
|
|
545
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
546
|
+
simple_report.expand_fields = [:test]
|
|
547
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
548
|
+
test,
|
|
549
|
+
:test,
|
|
550
|
+
report_table,
|
|
551
|
+
0,
|
|
552
|
+
report_object_set: true)
|
|
553
|
+
|
|
554
|
+
expect(report_table.full_table).to match(/\>\ntest\n\</)
|
|
555
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
556
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
557
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
558
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
559
|
+
expect(report_table.full_table).to match(/@sub_basic_variable=/)
|
|
560
|
+
expect(report_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
561
|
+
expect(report_table.full_table).to match(/@sub_overridden_variable=/)
|
|
562
|
+
expect(report_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
563
|
+
end
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
it "expands instance variables inline" do
|
|
567
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
568
|
+
simple_report.expand_fields = [:test, :test__sub_class_variable]
|
|
569
|
+
simple_report.expand_inline_fields = [:test, :test__sub_class_variable]
|
|
570
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
571
|
+
test,
|
|
572
|
+
:test,
|
|
573
|
+
report_table,
|
|
574
|
+
0,
|
|
575
|
+
report_object_set: true)
|
|
576
|
+
|
|
577
|
+
expect(report_table.full_table).not_to match(/\>\ntest\n\</)
|
|
578
|
+
expect(report_table.full_table).not_to match(/\>\n@sub_class_variable\n\</)
|
|
579
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
580
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
581
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
582
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
583
|
+
expect(report_table.full_table).to match(/\>\nsub_basic_variable\n\</)
|
|
584
|
+
expect(report_table.full_table).to match(/\>sub basic variable\</)
|
|
585
|
+
expect(report_table.full_table).to match(/\>\nsub_overridden_variable\n\</)
|
|
586
|
+
expect(report_table.full_table).to match(/\>sub processed variable\</)
|
|
587
|
+
end
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
it "excludes variables" do
|
|
591
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
592
|
+
simple_report.expand_fields = [:test]
|
|
593
|
+
simple_report.exclude_fields = [:test__sub_class_variable]
|
|
594
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
595
|
+
test,
|
|
596
|
+
:test,
|
|
597
|
+
report_table,
|
|
598
|
+
0,
|
|
599
|
+
report_object_set: true)
|
|
600
|
+
|
|
601
|
+
expect(report_table.full_table).to match(/\>\ntest\n\</)
|
|
602
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
603
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
604
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
605
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
606
|
+
expect(report_table.full_table).not_to match(/@sub_basic_variable=/)
|
|
607
|
+
expect(report_table.full_table).not_to match(/\"\;sub basic variable\"\;/)
|
|
608
|
+
expect(report_table.full_table).not_to match(/@sub_overridden_variable=/)
|
|
609
|
+
expect(report_table.full_table).not_to match(/\"\;sub overridden variable\"\;/)
|
|
610
|
+
end
|
|
611
|
+
end
|
|
612
|
+
|
|
613
|
+
it "outputs log files" do
|
|
614
|
+
expect(Cornucopia::Util::LogCapture).to receive(:capture_logs).and_return(nil)
|
|
615
|
+
|
|
616
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
617
|
+
simple_report.export_field_record({ report_element: [:logs] },
|
|
618
|
+
test,
|
|
619
|
+
:logs,
|
|
620
|
+
report_table,
|
|
621
|
+
0)
|
|
622
|
+
end
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
it "outputs diagnostics" do
|
|
626
|
+
expect(Cornucopia::Capybara::PageDiagnostics).to receive(:dump_details_in_table).and_return(nil)
|
|
627
|
+
|
|
628
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
629
|
+
simple_report.export_field_record({ report_element: [:capybara_page_diagnostics] },
|
|
630
|
+
test,
|
|
631
|
+
:capybara_page_diagnostics,
|
|
632
|
+
report_table,
|
|
633
|
+
0)
|
|
634
|
+
end
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
it "expands a hash" do
|
|
638
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
639
|
+
simple_report.expand_fields = [:test, :test__hash_variable]
|
|
640
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
641
|
+
test,
|
|
642
|
+
:test,
|
|
643
|
+
report_table,
|
|
644
|
+
0,
|
|
645
|
+
report_object_set: true)
|
|
646
|
+
|
|
647
|
+
expect(report_table.full_table).to match(/\>\ntest\n\</)
|
|
648
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
649
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
650
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
651
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
652
|
+
expect(report_table.full_table).to match(/@sub_basic_variable=/)
|
|
653
|
+
expect(report_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
654
|
+
expect(report_table.full_table).to match(/@sub_overridden_variable=/)
|
|
655
|
+
expect(report_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
656
|
+
expect(report_table.full_table).to match(/\>\nhash_variable\n\</)
|
|
657
|
+
expect(report_table.full_table).to match(/\>\nkey_1\n\</)
|
|
658
|
+
expect(report_table.full_table).to match(/\>value\</)
|
|
659
|
+
expect(report_table.full_table).to match(/\>\nanother key\n\</)
|
|
660
|
+
expect(report_table.full_table).to match(/\>another value\</)
|
|
661
|
+
end
|
|
662
|
+
end
|
|
663
|
+
|
|
664
|
+
it "doesn't expand a field if it isn't directly exported" do
|
|
665
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
666
|
+
simple_report.expand_fields = [:test, :test__hash_variable]
|
|
667
|
+
simple_report.exclude_fields = [:test__hash_variable]
|
|
668
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
669
|
+
test,
|
|
670
|
+
:test,
|
|
671
|
+
report_table,
|
|
672
|
+
0,
|
|
673
|
+
report_object_set: true)
|
|
674
|
+
|
|
675
|
+
expect(report_table.full_table).to match(/\>\ntest\n\</)
|
|
676
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
677
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
678
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
679
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
680
|
+
expect(report_table.full_table).to match(/@sub_basic_variable=/)
|
|
681
|
+
expect(report_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
682
|
+
expect(report_table.full_table).to match(/@sub_overridden_variable=/)
|
|
683
|
+
expect(report_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
684
|
+
expect(report_table.full_table).not_to match(/\>\nhash_variable\n\</)
|
|
685
|
+
expect(report_table.full_table).not_to match(/\>\nkey_1\n\</)
|
|
686
|
+
expect(report_table.full_table).not_to match(/\>value\</)
|
|
687
|
+
expect(report_table.full_table).not_to match(/\>\nanother key\n\</)
|
|
688
|
+
expect(report_table.full_table).not_to match(/\>another value\</)
|
|
689
|
+
end
|
|
690
|
+
end
|
|
691
|
+
|
|
692
|
+
it "expands an array" do
|
|
693
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
694
|
+
simple_report.expand_fields = [:test, :test__array_variable]
|
|
695
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
696
|
+
test,
|
|
697
|
+
:test,
|
|
698
|
+
report_table,
|
|
699
|
+
0,
|
|
700
|
+
report_object_set: true)
|
|
701
|
+
|
|
702
|
+
expect(report_table.full_table).to match(/\>\ntest\n\</)
|
|
703
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
704
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
705
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
706
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
707
|
+
expect(report_table.full_table).to match(/@sub_basic_variable=/)
|
|
708
|
+
expect(report_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
709
|
+
expect(report_table.full_table).to match(/@sub_overridden_variable=/)
|
|
710
|
+
expect(report_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
711
|
+
expect(report_table.full_table).to match(/\>\nhash_variable\n\</)
|
|
712
|
+
expect(report_table.full_table).not_to match(/\>\nkey_1\n\</)
|
|
713
|
+
expect(report_table.full_table).not_to match(/\>value\</)
|
|
714
|
+
expect(report_table.full_table).not_to match(/\>\nanother key\n\</)
|
|
715
|
+
expect(report_table.full_table).not_to match(/\>another value\</)
|
|
716
|
+
expect(report_table.full_table).to match(/\>\narray_variable\n\</)
|
|
717
|
+
expect(report_table.full_table).to match(/\>\n0\n\</)
|
|
718
|
+
expect(report_table.full_table).to match(/\>1\n\</)
|
|
719
|
+
expect(report_table.full_table).to match(/\>\n1\n\</)
|
|
720
|
+
expect(report_table.full_table).to match(/\>b\</)
|
|
721
|
+
expect(report_table.full_table).to match(/\>\n2\n\</)
|
|
722
|
+
expect(report_table.full_table).to match(/\>:fred_sym\n\</)
|
|
723
|
+
expect(report_table.full_table).to match(/\>\nstruct_variable\n\</)
|
|
724
|
+
expect(report_table.full_table).not_to match(/\>\nx\n\</)
|
|
725
|
+
expect(report_table.full_table).not_to match(/\>#{test.instance_variable_get(:@struct_variable).x}\n\</)
|
|
726
|
+
expect(report_table.full_table).not_to match(/\>\ny\n\</)
|
|
727
|
+
expect(report_table.full_table).not_to match(/\>#{test.instance_variable_get(:@struct_variable).y}\n\</)
|
|
728
|
+
end
|
|
729
|
+
end
|
|
730
|
+
|
|
731
|
+
it "expands a structure" do
|
|
732
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
733
|
+
simple_report.expand_fields = [:test, :test__struct_variable]
|
|
734
|
+
simple_report.export_field_record({ report_element: [:test] },
|
|
735
|
+
test,
|
|
736
|
+
:test,
|
|
737
|
+
report_table,
|
|
738
|
+
0,
|
|
739
|
+
report_object_set: true)
|
|
740
|
+
|
|
741
|
+
expect(report_table.full_table).to match(/\>\ntest\n\</)
|
|
742
|
+
expect(report_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
743
|
+
expect(report_table.full_table).to match(/\>basic variable\</)
|
|
744
|
+
expect(report_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
745
|
+
expect(report_table.full_table).to match(/\>processed variable\</)
|
|
746
|
+
expect(report_table.full_table).to match(/@sub_basic_variable=/)
|
|
747
|
+
expect(report_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
748
|
+
expect(report_table.full_table).to match(/@sub_overridden_variable=/)
|
|
749
|
+
expect(report_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
750
|
+
expect(report_table.full_table).to match(/\>\nhash_variable\n\</)
|
|
751
|
+
expect(report_table.full_table).not_to match(/\>\nkey_1\n\</)
|
|
752
|
+
expect(report_table.full_table).not_to match(/\>value\</)
|
|
753
|
+
expect(report_table.full_table).not_to match(/\>\nanother key\n\</)
|
|
754
|
+
expect(report_table.full_table).not_to match(/\>another value\</)
|
|
755
|
+
expect(report_table.full_table).to match(/\>\narray_variable\n\</)
|
|
756
|
+
expect(report_table.full_table).not_to match(/\>\n0\n\</)
|
|
757
|
+
expect(report_table.full_table).not_to match(/\>1\n\</)
|
|
758
|
+
expect(report_table.full_table).not_to match(/\>\n1\n\</)
|
|
759
|
+
expect(report_table.full_table).not_to match(/\>b\</)
|
|
760
|
+
expect(report_table.full_table).not_to match(/\>\n2\n\</)
|
|
761
|
+
expect(report_table.full_table).not_to match(/\>:fred_sym\n\</)
|
|
762
|
+
expect(report_table.full_table).to match(/\>\nstruct_variable\n\</)
|
|
763
|
+
expect(report_table.full_table).to match(/\>\nx\n\</)
|
|
764
|
+
expect(report_table.full_table).to match(/\>#{test.instance_variable_get(:@struct_variable).x}\n\</)
|
|
765
|
+
expect(report_table.full_table).to match(/\>\ny\n\</)
|
|
766
|
+
expect(report_table.full_table).to match(/\>#{test.instance_variable_get(:@struct_variable).y}\n\</)
|
|
767
|
+
end
|
|
768
|
+
end
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
describe "#add_report_objects" do
|
|
772
|
+
it "adds report objects" do
|
|
773
|
+
report = Cornucopia::Util::ConfiguredReport.new
|
|
774
|
+
|
|
775
|
+
expect(report.instance_variable_get(:@report_objects)[:test_object]).not_to be
|
|
776
|
+
expect(report.instance_variable_get(:@report_objects)[:another_object]).not_to be
|
|
777
|
+
|
|
778
|
+
report.add_report_objects({ test_object: "a test object", another_object: "another object" })
|
|
779
|
+
|
|
780
|
+
expect(report.instance_variable_get(:@report_objects)[:test_object]).to be == "a test object"
|
|
781
|
+
expect(report.instance_variable_get(:@report_objects)[:another_object]).to be == "another object"
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
it "updates report objects" do
|
|
785
|
+
report = Cornucopia::Util::ConfiguredReport.new
|
|
786
|
+
|
|
787
|
+
expect(report.instance_variable_get(:@report_objects)[:test_object]).not_to be
|
|
788
|
+
expect(report.instance_variable_get(:@report_objects)[:another_object]).not_to be
|
|
789
|
+
|
|
790
|
+
report.add_report_objects({ test_object: "a test object", another_object: "another object" })
|
|
791
|
+
|
|
792
|
+
expect(report.instance_variable_get(:@report_objects)[:test_object]).to be == "a test object"
|
|
793
|
+
expect(report.instance_variable_get(:@report_objects)[:another_object]).to be == "another object"
|
|
794
|
+
|
|
795
|
+
report.add_report_objects({ another_object: "still another object", third_object: "A third object" })
|
|
796
|
+
|
|
797
|
+
expect(report.instance_variable_get(:@report_objects)[:test_object]).to be == "a test object"
|
|
798
|
+
expect(report.instance_variable_get(:@report_objects)[:another_object]).to be == "still another object"
|
|
799
|
+
expect(report.instance_variable_get(:@report_objects)[:third_object]).to be == "A third object"
|
|
800
|
+
end
|
|
801
|
+
end
|
|
802
|
+
|
|
803
|
+
describe "#generate_report" do
|
|
804
|
+
it "can generate a report" do
|
|
805
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
806
|
+
builder = Cornucopia::Util::ConfiguredReport.new
|
|
807
|
+
builder.add_report_objects({ fred: "fred", test: test })
|
|
808
|
+
|
|
809
|
+
builder.expand_fields = [:test, :test__hash_variable]
|
|
810
|
+
|
|
811
|
+
builder.min_fields = [:test]
|
|
812
|
+
|
|
813
|
+
builder.generate_report(report)
|
|
814
|
+
|
|
815
|
+
full_table = File.read(report.report_contents_page_name)
|
|
816
|
+
|
|
817
|
+
expect(full_table).not_to match(/\"cornucopia-show-hide-section\"/)
|
|
818
|
+
expect(full_table).to match(/\>\ntest\n\</)
|
|
819
|
+
expect(full_table).to match(/\>\nbasic_variable\n\</)
|
|
820
|
+
expect(full_table).to match(/\>basic variable\</)
|
|
821
|
+
expect(full_table).to match(/\>\noverridden_variable\n\</)
|
|
822
|
+
expect(full_table).to match(/\>processed variable\</)
|
|
823
|
+
expect(full_table).to match(/@sub_basic_variable=/)
|
|
824
|
+
expect(full_table).to match(/\"\;sub basic variable\"\;/)
|
|
825
|
+
expect(full_table).to match(/@sub_overridden_variable=/)
|
|
826
|
+
expect(full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
827
|
+
expect(full_table).to match(/\>\nhash_variable\n\</)
|
|
828
|
+
expect(full_table).to match(/\>\nkey_1\n\</)
|
|
829
|
+
expect(full_table).to match(/\>value\</)
|
|
830
|
+
expect(full_table).to match(/\>\nanother key\n\</)
|
|
831
|
+
expect(full_table).to match(/\>another value\</)
|
|
832
|
+
end
|
|
833
|
+
|
|
834
|
+
it "allows adding to a report" do
|
|
835
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
836
|
+
builder = Cornucopia::Util::ConfiguredReport.new
|
|
837
|
+
builder.add_report_objects({ fred: "fred", test: test })
|
|
838
|
+
|
|
839
|
+
builder.expand_fields = [:test, :test__hash_variable]
|
|
840
|
+
|
|
841
|
+
builder.min_fields = [:test]
|
|
842
|
+
|
|
843
|
+
builder.generate_report(report) do |in_report, table|
|
|
844
|
+
table.write_stats("Something_Extra", "A value")
|
|
845
|
+
end
|
|
846
|
+
|
|
847
|
+
full_table = File.read(report.report_contents_page_name)
|
|
848
|
+
|
|
849
|
+
expect(full_table).to match(/\"cornucopia-show-hide-section\"/)
|
|
850
|
+
expect(full_table).to match(/\>\ntest\n\</)
|
|
851
|
+
expect(full_table).to match(/\>\nSomething_Extra\n\</)
|
|
852
|
+
expect(full_table).to match(/\>A value\</)
|
|
853
|
+
expect(full_table).to match(/\>\nbasic_variable\n\</)
|
|
854
|
+
expect(full_table).to match(/\>basic variable\</)
|
|
855
|
+
expect(full_table).to match(/\>\noverridden_variable\n\</)
|
|
856
|
+
expect(full_table).to match(/\>processed variable\</)
|
|
857
|
+
expect(full_table).to match(/@sub_basic_variable=/)
|
|
858
|
+
expect(full_table).to match(/\"\;sub basic variable\"\;/)
|
|
859
|
+
expect(full_table).to match(/@sub_overridden_variable=/)
|
|
860
|
+
expect(full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
861
|
+
expect(full_table).to match(/\>\nhash_variable\n\</)
|
|
862
|
+
expect(full_table).to match(/\>\nkey_1\n\</)
|
|
863
|
+
expect(full_table).to match(/\>value\</)
|
|
864
|
+
expect(full_table).to match(/\>\nanother key\n\</)
|
|
865
|
+
expect(full_table).to match(/\>another value\</)
|
|
866
|
+
end
|
|
867
|
+
|
|
868
|
+
it "creates a sub-section for secondary information" do
|
|
869
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
870
|
+
builder = Cornucopia::Util::ConfiguredReport.new
|
|
871
|
+
builder.add_report_objects({ fred: "fred", test: test })
|
|
872
|
+
|
|
873
|
+
builder.expand_fields = [:test, :test__hash_variable]
|
|
874
|
+
|
|
875
|
+
builder.min_fields = [:test__basic_variable]
|
|
876
|
+
builder.exclude_fields = [:test__basic_variable]
|
|
877
|
+
builder.more_info_fields = [:test]
|
|
878
|
+
|
|
879
|
+
builder.generate_report(report)
|
|
880
|
+
|
|
881
|
+
full_table = File.read(report.report_contents_page_name)
|
|
882
|
+
|
|
883
|
+
expect(full_table).to match(/\"cornucopia-show-hide-section\"/)
|
|
884
|
+
expect(full_table).to match(/\>\ntest\n\</)
|
|
885
|
+
expect(full_table).to match(/\>\nbasic_variable\n\</)
|
|
886
|
+
expect(full_table).to match(/\>basic variable\</)
|
|
887
|
+
expect(full_table).to match(/\>\noverridden_variable\n\</)
|
|
888
|
+
expect(full_table).to match(/\>processed variable\</)
|
|
889
|
+
expect(full_table).to match(/@sub_basic_variable=/)
|
|
890
|
+
expect(full_table).to match(/\"\;sub basic variable\"\;/)
|
|
891
|
+
expect(full_table).to match(/@sub_overridden_variable=/)
|
|
892
|
+
expect(full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
893
|
+
expect(full_table).to match(/\>\nhash_variable\n\</)
|
|
894
|
+
expect(full_table).to match(/\>\nkey_1\n\</)
|
|
895
|
+
expect(full_table).to match(/\>value\</)
|
|
896
|
+
expect(full_table).to match(/\>\nanother key\n\</)
|
|
897
|
+
expect(full_table).to match(/\>another value\</)
|
|
898
|
+
end
|
|
899
|
+
|
|
900
|
+
it "creates a report within an existing table" do
|
|
901
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
902
|
+
the_table = nil
|
|
903
|
+
|
|
904
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
905
|
+
the_table = report_table
|
|
906
|
+
|
|
907
|
+
builder = Cornucopia::Util::ConfiguredReport.new
|
|
908
|
+
builder.add_report_objects({ fred: "fred", test: test })
|
|
909
|
+
|
|
910
|
+
builder.expand_fields = [:test, :test__hash_variable]
|
|
911
|
+
|
|
912
|
+
builder.min_fields = [:test__basic_variable]
|
|
913
|
+
builder.exclude_fields = [:test__basic_variable]
|
|
914
|
+
builder.more_info_fields = [:test]
|
|
915
|
+
|
|
916
|
+
builder.generate_report(report, report_table: report_table)
|
|
917
|
+
end
|
|
918
|
+
|
|
919
|
+
report.close
|
|
920
|
+
|
|
921
|
+
expect(the_table.full_table).not_to match(/\"cornucopia-show-hide-section\"/)
|
|
922
|
+
expect(the_table.full_table).to match(/\>\ntest\n\</)
|
|
923
|
+
expect(the_table.full_table).to match(/\>\nbasic_variable\n\</)
|
|
924
|
+
expect(the_table.full_table).to match(/\>basic variable\</)
|
|
925
|
+
expect(the_table.full_table).to match(/\>\noverridden_variable\n\</)
|
|
926
|
+
expect(the_table.full_table).to match(/\>processed variable\</)
|
|
927
|
+
expect(the_table.full_table).to match(/@sub_basic_variable=/)
|
|
928
|
+
expect(the_table.full_table).to match(/\"\;sub basic variable\"\;/)
|
|
929
|
+
expect(the_table.full_table).to match(/@sub_overridden_variable=/)
|
|
930
|
+
expect(the_table.full_table).to match(/\"\;sub overridden variable\"\;/)
|
|
931
|
+
expect(the_table.full_table).to match(/\>\nhash_variable\n\</)
|
|
932
|
+
expect(the_table.full_table).to match(/\>\nkey_1\n\</)
|
|
933
|
+
expect(the_table.full_table).to match(/\>value\</)
|
|
934
|
+
expect(the_table.full_table).to match(/\>\nanother key\n\</)
|
|
935
|
+
expect(the_table.full_table).to match(/\>another value\</)
|
|
936
|
+
end
|
|
937
|
+
|
|
938
|
+
it "does not export values that don't exist on the object" do
|
|
939
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
940
|
+
simple_report.expand_fields = [:test, :test__hash_variable]
|
|
941
|
+
|
|
942
|
+
simple_report.export_field_record({ report_element: [:test,
|
|
943
|
+
:hash_variable,
|
|
944
|
+
:fake_hash_value] },
|
|
945
|
+
test,
|
|
946
|
+
:test,
|
|
947
|
+
report_table,
|
|
948
|
+
0,
|
|
949
|
+
report_object_set: true)
|
|
950
|
+
|
|
951
|
+
expect(report_table.full_table).not_to match(/fake_hash_value/)
|
|
952
|
+
end
|
|
953
|
+
end
|
|
954
|
+
end
|
|
955
|
+
|
|
956
|
+
describe "leaf options" do
|
|
957
|
+
describe "#find_leaf_options" do
|
|
958
|
+
it "only finds an element in the array" do
|
|
959
|
+
leaf_options = []
|
|
960
|
+
leaf_elements = rand(40..50).times.map { Faker::Lorem.word.to_sym }.uniq
|
|
961
|
+
num_items = rand(5..10)
|
|
962
|
+
leaf_pos = 0
|
|
963
|
+
leaf_size = (leaf_elements.size - 1) / num_items
|
|
964
|
+
|
|
965
|
+
num_items.times do
|
|
966
|
+
some_options = { some_option: Faker::Lorem.sentence }
|
|
967
|
+
leaf_options << { report_element: leaf_elements[leaf_pos..leaf_pos + leaf_size - 1], report_options: some_options }
|
|
968
|
+
leaf_pos += leaf_size
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
rand_item = rand(0..leaf_pos - 1)
|
|
972
|
+
|
|
973
|
+
simple_report.leaf_options = leaf_options
|
|
974
|
+
expect(simple_report.find_leaf_options(leaf_elements[rand_item])).to be == leaf_options[rand_item / leaf_size]
|
|
975
|
+
expect(simple_report.find_leaf_options(leaf_elements[leaf_pos])).not_to be
|
|
976
|
+
end
|
|
977
|
+
end
|
|
978
|
+
|
|
979
|
+
it "uses leaf options" do
|
|
980
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
981
|
+
simple_report.leaf_options = [{ report_element: [:key_1], report_options: { fake_options: true } }]
|
|
982
|
+
|
|
983
|
+
expect(report_table).to receive(:write_stats).with(:key_1, "value", fake_options: true)
|
|
984
|
+
|
|
985
|
+
simple_report.export_field_record({ report_element: [:test,
|
|
986
|
+
:hash_variable,
|
|
987
|
+
:key_1] },
|
|
988
|
+
test,
|
|
989
|
+
:test,
|
|
990
|
+
report_table,
|
|
991
|
+
0,
|
|
992
|
+
report_object_set: true)
|
|
993
|
+
end
|
|
994
|
+
end
|
|
995
|
+
|
|
996
|
+
it "uses node options over leaf options" do
|
|
997
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
998
|
+
simple_report.leaf_options = [{ report_element: [:key_1], report_options: { fake_options: true } }]
|
|
999
|
+
|
|
1000
|
+
expect(report_table).to receive(:write_stats).with(:key_1, "value", real_options: true)
|
|
1001
|
+
|
|
1002
|
+
simple_report.export_field_record({ report_element: [:test,
|
|
1003
|
+
:hash_variable,
|
|
1004
|
+
:key_1],
|
|
1005
|
+
report_options: { real_options: true } },
|
|
1006
|
+
test,
|
|
1007
|
+
:test,
|
|
1008
|
+
report_table,
|
|
1009
|
+
0,
|
|
1010
|
+
report_object_set: true)
|
|
1011
|
+
end
|
|
1012
|
+
end
|
|
1013
|
+
|
|
1014
|
+
it "outputs a custom label" do
|
|
1015
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
1016
|
+
custom_label = Faker::Lorem.word
|
|
1017
|
+
simple_report.leaf_options = [{ report_element: [:key_1], report_options: { fake_options: true } }]
|
|
1018
|
+
|
|
1019
|
+
expect(report_table).
|
|
1020
|
+
to receive(:write_stats).with(custom_label, "value", real_options: true, label: custom_label)
|
|
1021
|
+
|
|
1022
|
+
simple_report.export_field_record({ report_element: [:test,
|
|
1023
|
+
:hash_variable,
|
|
1024
|
+
:key_1],
|
|
1025
|
+
report_options: { label: custom_label, real_options: true } },
|
|
1026
|
+
test,
|
|
1027
|
+
:test,
|
|
1028
|
+
report_table,
|
|
1029
|
+
0,
|
|
1030
|
+
report_object_set: true)
|
|
1031
|
+
end
|
|
1032
|
+
end
|
|
1033
|
+
|
|
1034
|
+
it "sends expand options to children nodes" do
|
|
1035
|
+
Cornucopia::Util::ReportTable.new do |report_table|
|
|
1036
|
+
simple_report.expand_fields = [:test, :test__hash_variable]
|
|
1037
|
+
simple_report.leaf_options = [{ report_element: [:key_1], report_options: { fake_options: true } }]
|
|
1038
|
+
|
|
1039
|
+
total_count = 0
|
|
1040
|
+
allow_any_instance_of(Cornucopia::Util::ReportTable).to receive(:write_stats) do |label, value, options|
|
|
1041
|
+
total_count += 1 if label == :key_1 && value == "value" && options == { real_options: true }
|
|
1042
|
+
total_count += 1 if label == "another key" && value == "another value"
|
|
1043
|
+
end.and_call_original
|
|
1044
|
+
|
|
1045
|
+
simple_report.export_field_record({ report_element: [:test,
|
|
1046
|
+
:hash_variable],
|
|
1047
|
+
report_options: { exclude_code_block: true } },
|
|
1048
|
+
test,
|
|
1049
|
+
:test,
|
|
1050
|
+
report_table,
|
|
1051
|
+
0,
|
|
1052
|
+
report_object_set: true)
|
|
1053
|
+
|
|
1054
|
+
expect(report_table.full_table).not_to match /\<code\>/
|
|
1055
|
+
end
|
|
1056
|
+
end
|
|
1057
|
+
end
|
|
1058
|
+
end
|