cornucopia 0.1.16 → 0.1.17

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
  SHA1:
3
- metadata.gz: bd93163007cffbc1d139c208d1fafd4b3c6a776f
4
- data.tar.gz: 3be2a99870eea81dc4e7634f6b2e4c3af895f478
3
+ metadata.gz: c605a3ac693c8cfb36d7f52304456400d1b2e766
4
+ data.tar.gz: 690678034748ce8f86ba8f2642dca2a4e5cf22b7
5
5
  SHA512:
6
- metadata.gz: dd9fc46194b3b61840474ec462444434786222d987400b5ec1f3018aa3cbf26637c4a1ecabac5393843b322df0d338c8caf170ecae002b548f1ca8b06a64886b
7
- data.tar.gz: 2ad558e17c4bf9f80ab3bb08a9e88bafe19a57805cdbe025b8dc4bfb50004c28e640eee1abbc43faa641a95771c0c7a252209afc7031a3044cf01f42821753da
6
+ metadata.gz: 0b71eb0bc8f122c07036cd021f662fed6525242570c187690d4ffac02ea038ce29c7b782e7279eecffdabeb9995d941d1c7b344498318adc57c442409c7bfa89
7
+ data.tar.gz: 288f628863535d59af56d50af116e238aefc95f7020111135c093677d96a24937c45629bea64224271e56b4f89d4d59be2d21d9b251899bb1b7f0e747db53cdd
data/README.md CHANGED
@@ -65,7 +65,9 @@ I have added the following functions to Capybara to help simplify using it.
65
65
 
66
66
  * synchronize_test(seconds=Capybara.default_wait_time, options = {}, &block)
67
67
 
68
- This function yields to a block until the Capybara timeout occurs or the block returns true.
68
+ This function yields to a block until the Capybara timeout occurs or the block returns true. I added it because I
69
+ find that simple synchronized find functions are not always sufficient. This will allow the system to wait till any
70
+ random block returns true, synchronizing to a wide variety of conditions.
69
71
 
70
72
  # Wait until either #some_element or #another_element exists.
71
73
  Capybara::current_session.synchronize_test do
@@ -78,13 +80,20 @@ This function yields to a block until the Capybara timeout occurs or the block r
78
80
  This function selects the option from a select box based on the value for the selected option instead of the
79
81
  value string.
80
82
 
83
+ If I have the a SELECT list with the following option:
84
+
85
+ <option value="AZ">Arizona</option>
86
+
87
+ The following line will select the "Arizona" option:
88
+
89
+ my_address.state_abbreviation = "AZ"
81
90
  page.find("#state_selector").select_value(my_address.state_abbreviation)
82
91
 
83
92
  * **value_text**
84
93
 
85
94
  This function returns the string value of the currently selected option(s).
86
95
 
87
- page.find("#state_selector").value_text # returns "Arizona" instead of "AZ"
96
+ page.find("#state_selector").value_text # returns "Arizona" instead of "AZ" if "AZ" is selected.
88
97
 
89
98
  ### SitePrism
90
99
 
@@ -232,7 +241,7 @@ automatically as long as I follow some simple rules.
232
241
  Basically, just create all of my pages underneath a single module in a single folder, and the a class derived from
233
242
  PageApplication will find the pages and memoize them for you automatically.
234
243
 
235
- class MyApplication < Cornucopia::SitePrism::PageApplication
244
+ class MyPageApplication < Cornucopia::SitePrism::PageApplication
236
245
  def pages_module
237
246
  MyPagesModule
238
247
  end
@@ -252,8 +261,32 @@ PageApplication will find the pages and memoize them for you automatically.
252
261
  end
253
262
  end
254
263
 
255
- a_memoized_page = MyApplication.my_module__my_page
256
- a_memoized_other_page = MyApplication.my_other_page
264
+ a_memoized_page = MyPageApplication.my_module__my_page
265
+ a_memoized_other_page = MyPageApplication.my_other_page
266
+
267
+ #### Capybara::Node::Simple integration
268
+
269
+ SitePrism is very useful, but it only works with the main page: `Capybara::current_session.page`. I have found that
270
+ there are times where it is very useful to use the `Capybara::Node::Simple` object. The problem I have is that I can't
271
+ use my SitePrism pages with the SimpleNode.
272
+
273
+ I therefore added a property `owner_node` to the `SitePrism::Page` and `SitePrism::Section` classes. You can assign
274
+ to this property the `Capybara::Node` that you want to execute the finder functions against.
275
+
276
+ An example might be something like:
277
+
278
+ RSpec.describe MyController, type: :controller do
279
+ get :index
280
+
281
+ expect(response.status).to eq 200
282
+
283
+ my_node = Capybara::Node::Simple.new(response.body)
284
+ my_page = MyPageApplication.my_page
285
+
286
+ my_page.owner_node = my_node
287
+
288
+ expect(my_page.my_section.my_list[0].my_element.text).to eq(my_expectation)
289
+ end
257
290
 
258
291
  ### Utilities
259
292
 
@@ -350,6 +383,102 @@ The configuration class contains the various configurations that are used by the
350
383
  The `Cornucopia::Util::ConfiguredReport` class allows you to configure what information is exported to generated
351
384
  report files.
352
385
 
386
+ I've tried to create reasonable default configuration for what gets reported when there is an error in the test
387
+ environments that I know enough to support: Cucumber, RSpec, and Spinach. I also provided a default configuration
388
+ for what to report when an error occurs a Capybara page is open.
389
+
390
+ You can override these defaults if you find a need and specify the configured report that is used when an exception
391
+ occurs in a particular environment.
392
+
393
+ The default configurations will output the following information that it can find/is available:
394
+
395
+ * The exception that caused the problem and its call stack
396
+ * Test details such as the test name, file path, etc.
397
+ * Any instance variables for the test
398
+ * Any values defined using `let`
399
+ * The log for the current environment
400
+ * Any additional log files specified by the user
401
+ * Any Capybara details that can be determined like the HTML source, a screen shot, etc.
402
+
403
+ The ConfiguredReport class and the example configurations detail how the configured reports work if you feel the need
404
+ to create your own.
405
+
406
+ #### ReportBuilder
407
+
408
+ The ReportBuilder is the tool which is used to create the reports that are generated when an exception is caught.
409
+ There are 3 basic objects to work with in a report:
410
+
411
+ ##### Tests
412
+
413
+ A test is basically a new sub-report. When you create a new test, you will pass in a name for the test. This name
414
+ will appear in the left portion of the report. When the user clicks on the test, the report for the test will appear
415
+ on the right side. You will likely not need to create your own tests. To do so, you call `within_test`.
416
+
417
+ An example:
418
+
419
+ Cornucopia::ReportBuilder.current_report.within_test("This is the name of my test") do
420
+ # build your test report here.
421
+ end
422
+
423
+ ##### Sections
424
+
425
+ A section is a block within a test. The section has a header that describes the section and is the primary container
426
+ for tables. Multiple sections are allowed within a test and are colored alternating colors to distinguish them.
427
+
428
+ An example:
429
+
430
+ Cornucopia::ReportBuilder.current_report.within_section("Section header") do |section|
431
+ # Build the details for the section here.
432
+
433
+ # NOTE: Currently section is == Cornucopia::ReportBuilder.current_report This may or may not be so in the
434
+ # future.
435
+ end
436
+
437
+ Note that only one test is allowed to be active at all times and that if no other test is active a defaut "unknown"
438
+ test will be used. As a result, you can call the `within_section` function directly from the report object and it
439
+ will be within the currently active test.
440
+
441
+ ##### Tables
442
+
443
+ A table is exactly what it sounds like it is a table of information. Tables have rows of information pairs - a label
444
+ and the information to be shown. Unlike Sections and Tests, Tables can be nested inside each other. That is the
445
+ information in a table row can be another table.
446
+
447
+ If the information for a particular cell is too large, that information will be partially hidden from view so that
448
+ the table size doesn't get out of hand.
449
+
450
+ To write out a value, you simply use `write_stats` and pass in a label and a value.
451
+
452
+ An example:
453
+
454
+ Cornucopia::ReportBuilder.current_report.within_section("Section header") do |section|
455
+ section.within_table do |table|
456
+ table.write_stats "Statistic name", "Statistic value"
457
+
458
+ ReportTable.new nested_table: table, nested_table_label: "Sub Table" do |sub_table|
459
+ sub_table.write_stats "Sub statistic name", "Sub statistic value"
460
+ end
461
+ end
462
+ end
463
+
464
+ Tables have a lot of options:
465
+
466
+ * **table_prefix** - This is the value to use to "open" the table.
467
+ * **table_postfix** - This is the value to use to "close" the table.
468
+ * **report_table** - If set, all table calls are passed through to this table object. The purpose of this value is
469
+ to allow for an optional sub-table. That is the code acts as if it is working on a sub-table, but in reality it is
470
+ working in the report_table.
471
+ * **nested_table** - This is the table that the table being created will be a sub-table of. When the new table is
472
+ completed, it till be output into a row of the specified table.
473
+ * **nested_table_label** - This is the lable that will be used for this table when it is output in the nested_table.
474
+ * **nested_table_options** - A hash of options that will be used to determine the look and feel of the nested table
475
+ when it is output. These options are passed into write_stats when the table is output.
476
+ * **not_a_table** - If set, then when write_stats is called, the label value is ignored and the value is simply
477
+ appended to the table as-is.
478
+ * **suppress_blank_table** - If set, the table will not be output if it is blank.
479
+
480
+
481
+
353
482
  ## Contributing
354
483
 
355
484
  1. Fork it
@@ -79,9 +79,13 @@ module Cornucopia
79
79
  class FindAction
80
80
  @@diagnosed_finders = {}
81
81
 
82
+ Cornucopia::Util::ReportBuilder.on_close do
83
+ Cornucopia::Capybara::FinderDiagnostics::FindAction.clear_diagnosed_finders
84
+ end
85
+
82
86
  # Clears the class variable @@diagnosed_finders between tests if called.
83
87
  # This is done so that finder analysis is called at least once per test.
84
- def self.start_test
88
+ def self.clear_diagnosed_finders
85
89
  @@diagnosed_finders = {}
86
90
  end
87
91
 
@@ -8,7 +8,8 @@ Around do |scenario, block|
8
8
 
9
9
  scenario.instance_variable_set :@seed_value, seed_value
10
10
 
11
- Cornucopia::Capybara::FinderDiagnostics::FindAction.start_test
11
+ Cornucopia::Capybara::FinderDiagnostics::FindAction.clear_diagnosed_finders
12
+ Cornucopia::Capybara::PageDiagnostics.clear_dumped_pages
12
13
 
13
14
  Cornucopia::Util::ReportBuilder.current_report.within_test("#{scenario.feature.title} : #{scenario.title}") do
14
15
  block.call
@@ -18,6 +19,9 @@ Around do |scenario, block|
18
19
  seed_value = scenario.instance_variable_get(:@seed_value)
19
20
  puts ("random seed for testing was: #{seed_value}")
20
21
  end
22
+
23
+ Cornucopia::Capybara::FinderDiagnostics::FindAction.clear_diagnosed_finders
24
+ Cornucopia::Capybara::PageDiagnostics.clear_dumped_pages
21
25
  end
22
26
 
23
27
  After do |scenario|
@@ -20,7 +20,8 @@ RSpec.configure do |config|
20
20
 
21
21
  srand(@seed_value)
22
22
 
23
- Cornucopia::Capybara::FinderDiagnostics::FindAction.start_test
23
+ Cornucopia::Capybara::FinderDiagnostics::FindAction.clear_diagnosed_finders
24
+ Cornucopia::Capybara::PageDiagnostics.clear_dumped_pages
24
25
 
25
26
  test_example = example.example if example.respond_to?(:example)
26
27
  test_example ||= self.example if self.respond_to?(:example)
@@ -40,5 +41,8 @@ RSpec.configure do |config|
40
41
  end
41
42
  end
42
43
  end
44
+
45
+ Cornucopia::Capybara::FinderDiagnostics::FindAction.clear_diagnosed_finders
46
+ Cornucopia::Capybara::PageDiagnostics.clear_dumped_pages
43
47
  end
44
48
  end
@@ -15,11 +15,15 @@ Spinach.hooks.before_scenario do |scenario, step_definitions|
15
15
 
16
16
  scenario.instance_variable_set :@seed_value, seed_value
17
17
 
18
- Cornucopia::Capybara::FinderDiagnostics::FindAction.start_test
18
+ Cornucopia::Capybara::FinderDiagnostics::FindAction.clear_diagnosed_finders
19
+ Cornucopia::Capybara::PageDiagnostics.clear_dumped_pages
19
20
  end
20
21
 
21
22
  Spinach.hooks.after_scenario do |scenario, step_definitions|
22
23
  @running_scenario = nil
24
+
25
+ Cornucopia::Capybara::FinderDiagnostics::FindAction.clear_diagnosed_finders
26
+ Cornucopia::Capybara::PageDiagnostics.clear_dumped_pages
23
27
  end
24
28
 
25
29
  Spinach.hooks.on_failed_step do |step_data, exception, location, step_definitions|
@@ -1,3 +1,4 @@
1
+ require "singleton"
1
2
  require ::File.expand_path('configured_report', File.dirname(__FILE__))
2
3
  require ::File.expand_path('generic_settings', File.dirname(__FILE__))
3
4
  require ::File.expand_path('report_formatters', File.dirname(__FILE__))
@@ -5,254 +6,263 @@ require ::File.expand_path('report_formatters', File.dirname(__FILE__))
5
6
  module Cornucopia
6
7
  module Util
7
8
  class Configuration
8
- @@configurations = Cornucopia::Util::GenericSettings.new
9
- @@configurations.order_seed = nil
10
- @@configurations.rand_seed = nil
11
- @@configurations.user_log_files = {}
12
- @@configurations.default_num_lines = 500
13
- @@configurations.grab_logs = true
14
- @@configurations.print_timeout_min = 10
15
- @@configurations.selenium_cache_retry_count = 5
16
- @@configurations.analyze_find_exceptions = true
17
- @@configurations.analyze_selector_exceptions = true
18
- @@configurations.retry_with_found = false
19
- @@configurations.retry_match_with_found = false
20
- @@configurations.open_report_settings = { default: false }
21
- @@configurations.base_folder = "cornucopia_report"
22
-
23
- # @@configurations.alternate_retry = false
24
-
25
- @@configurations.configured_reports = {
26
- rspec: Cornucopia::Util::ConfiguredReport.new(
27
- min_fields: [
28
- :example__full_description,
29
- :example__location,
30
- :example__exception__to_s,
31
- :example__exception__backtrace
32
- ],
33
- more_info_fields: [
34
- :example__exception__class__name,
35
- :example,
36
- :example__example_group_instance,
37
- :example__metadata__caller,
38
- :rspec__configuration__seed,
39
- :logs,
40
- :capybara_page_diagnostics
41
- ],
42
- expand_fields: [
43
- :example,
44
- :example__example_group_instance__response,
45
- :example__example_group_instance__controller,
46
- :example__example_group_instance__request,
47
- :example__example_group_instance
48
- ],
49
- expand_inline_fields: [
50
- :example__example_group_instance____memoized
51
- ],
52
- exclude_fields: [
53
- :example__fixture_connections,
54
- :example,
55
- :example__example_group_instance,
56
- ]
57
- ),
58
- cucumber: Cornucopia::Util::ConfiguredReport.new(
59
- min_fields: [
60
- {
61
- report_element: :scenario__feature__title,
62
- report_options: { label: "feature" }
63
- },
64
- {
65
- report_element: :scenario__feature__location,
66
- # report_options: { format: ->(value) { "#{value.file}:#{value.line}" } }
67
- report_options: { format_object: Cornucopia::Util::CucumberFormatter,
68
- format_function: :format_location }
69
- },
70
- {
71
- report_element: :scenario__title,
72
- report_options: { label: "scenario" }
73
- },
74
- {
75
- report_element: :scenario__location,
76
- report_options: { format_object: Cornucopia::Util::CucumberFormatter,
77
- format_function: :format_location }
78
- },
79
- :scenario__exception__to_s,
80
- :scenario__exception__backtrace
81
- ],
82
- more_info_fields: [
83
- :scenario__exception__class__name,
84
- :scenario,
85
- :scenario__feature__comment,
86
- :scenario__feature__keyword,
87
- :scenario__feature__description,
88
- :scenario__feature__gherkin_statement,
89
- :scenario__feature__tags,
90
- :scenario__current_visitor__configuration,
91
- :cucumber,
92
- :logs,
93
- :capybara_page_diagnostics
94
- ],
95
- expand_fields: [
96
- :scenario,
97
- :cucumber,
98
- ],
99
- expand_inline_fields: [
100
- ],
101
- exclude_fields: [
102
- :scenario__background,
103
- :scenario__feature,
104
- :scenario__current_visitor,
105
- :scenario__raw_steps,
106
- :scenario__title,
107
- :scenario__location,
108
- :cucumber____cucumber_runtime,
109
- :cucumber____natural_language,
110
- :cucumber___rack_test_sessions,
111
- :cucumber___rack_mock_sessions,
112
- :cucumber__integration_session
113
- ]
114
- ),
115
- spinach: Cornucopia::Util::ConfiguredReport.new(
116
- min_fields: [
117
- :failure_description,
118
- :running_scenario__feature__name,
119
- :running_scenario__name,
120
- :running_scenario__line,
121
- :step_data__name,
122
- :step_data__line,
123
- :exception__to_s,
124
- :exception__backtrace
125
- ],
126
- more_info_fields: [
127
- :exception__class__name,
128
- :running_scenario__feature__tags,
129
- :running_scenario,
130
- :step_data,
131
- :step_definitions,
132
- :logs,
133
- :capybara_page_diagnostics
134
- ],
135
- expand_fields: [
136
- :running_scenario,
137
- :step_data,
138
- :step_definitions
139
- ],
140
- expand_inline_fields: [
141
- ],
142
- exclude_fields: [
143
- :running_scenario__feature,
144
- :step_data__scenario__feature,
145
- :running_scenario__name,
146
- :running_scenario__line,
147
- :step_data__name,
148
- :step_data__line
149
- ]
150
- ),
151
- capybara_page_diagnostics: Cornucopia::Util::ConfiguredReport.new(
152
- min_fields: [
153
- :capybara__page_url,
154
- :capybara__title,
155
- :capybara__screen_shot
156
- ],
157
- more_info_fields: [
158
- :capybara,
159
- :capybara__other_windows,
160
- ],
161
- expand_fields: [
162
- :capybara,
163
- :capybara__other_windows,
164
- "capybara__other_windows__*",
165
- ],
166
- expand_inline_fields: [
167
- :capybara,
168
- ],
169
- exclude_fields: [
170
- :capybara__page_url,
171
- :capybara__title,
172
- :capybara__screen_shot,
173
- :capybara__page_url,
174
- :capybara__title,
175
- :capybara__screen_shot,
176
- :capybara__options,
177
- :capybara__report,
178
- :capybara__table,
179
- :capybara__unsupported_list,
180
- :capybara__allow_other_windows,
181
- :capybara__iterating,
182
- :capybara__session,
183
- :capybara__driver,
184
- :capybara__window_handles,
185
- :capybara__current_window,
186
- "capybara__other_windows__*__options",
187
- "capybara__other_windows__*__report",
188
- "capybara__other_windows__*__table",
189
- "capybara__other_windows__*__unsupported_list",
190
- "capybara__other_windows__*__allow_other_windows",
191
- "capybara__other_windows__*__iterating",
192
- "capybara__other_windows__*__session",
193
- "capybara__other_windows__*__driver",
194
- "capybara__other_windows__*__window_handles",
195
- "capybara__other_windows__*__current_window"
196
- ],
197
- leaf_options: [
198
- { report_element: [:html_source,
199
- :html_frame,
200
- :screen_shot
201
- ],
202
- report_options: { prevent_shrink: true,
203
- exclude_code_block: true,
204
- do_not_pretty_print: true
9
+ include Singleton
10
+
11
+ attr_accessor :configurations
12
+
13
+ def initialize
14
+ @configurations = Cornucopia::Util::GenericSettings.new
15
+
16
+ configurations.order_seed = nil
17
+ configurations.rand_seed = nil
18
+ configurations.user_log_files = {}
19
+ configurations.default_num_lines = 500
20
+ configurations.grab_logs = true
21
+ configurations.print_timeout_min = 10
22
+ configurations.selenium_cache_retry_count = 5
23
+ configurations.analyze_find_exceptions = true
24
+ configurations.analyze_selector_exceptions = true
25
+ configurations.retry_with_found = false
26
+ configurations.retry_match_with_found = false
27
+ configurations.open_report_settings = { default: false }
28
+ configurations.base_folder = "cornucopia_report"
29
+
30
+ # configurations.alternate_retry = false
31
+
32
+ configurations.default_configuration = {
33
+ rspec: {
34
+ min_fields: [
35
+ :example__full_description,
36
+ :example__location,
37
+ :example__exception__to_s,
38
+ :example__exception__backtrace
39
+ ],
40
+ more_info_fields: [
41
+ :example__exception__class__name,
42
+ :example,
43
+ :example__example_group_instance,
44
+ :example__metadata__caller,
45
+ :rspec__configuration__seed,
46
+ :logs,
47
+ :capybara_page_diagnostics
48
+ ],
49
+ expand_fields: [
50
+ :example,
51
+ :example__example_group_instance__response,
52
+ :example__example_group_instance__controller,
53
+ :example__example_group_instance__request,
54
+ :example__example_group_instance
55
+ ],
56
+ expand_inline_fields: [
57
+ :example__example_group_instance____memoized
58
+ ],
59
+ exclude_fields: [
60
+ :example__fixture_connections,
61
+ :example,
62
+ :example__example_group_instance,
63
+ ]
64
+ },
65
+ cucumber: {
66
+ min_fields: [
67
+ {
68
+ report_element: :scenario__feature__title,
69
+ report_options: { label: "feature" }
70
+ },
71
+ {
72
+ report_element: :scenario__feature__location,
73
+ # report_options: { format: ->(value) { "#{value.file}:#{value.line}" } }
74
+ report_options: { format_object: Cornucopia::Util::CucumberFormatter,
75
+ format_function: :format_location }
76
+ },
77
+ {
78
+ report_element: :scenario__title,
79
+ report_options: { label: "scenario" }
80
+ },
81
+ {
82
+ report_element: :scenario__location,
83
+ report_options: { format_object: Cornucopia::Util::CucumberFormatter,
84
+ format_function: :format_location }
85
+ },
86
+ :scenario__exception__to_s,
87
+ :scenario__exception__backtrace
88
+ ],
89
+ more_info_fields: [
90
+ :scenario__exception__class__name,
91
+ :scenario,
92
+ :scenario__feature__comment,
93
+ :scenario__feature__keyword,
94
+ :scenario__feature__description,
95
+ :scenario__feature__gherkin_statement,
96
+ :scenario__feature__tags,
97
+ :scenario__current_visitor__configuration,
98
+ :cucumber,
99
+ :logs,
100
+ :capybara_page_diagnostics
101
+ ],
102
+ expand_fields: [
103
+ :scenario,
104
+ :cucumber,
105
+ ],
106
+ expand_inline_fields: [
107
+ ],
108
+ exclude_fields: [
109
+ :scenario__background,
110
+ :scenario__feature,
111
+ :scenario__current_visitor,
112
+ :scenario__raw_steps,
113
+ :scenario__title,
114
+ :scenario__location,
115
+ :cucumber____cucumber_runtime,
116
+ :cucumber____natural_language,
117
+ :cucumber___rack_test_sessions,
118
+ :cucumber___rack_mock_sessions,
119
+ :cucumber__integration_session
120
+ ]
121
+ },
122
+ spinach: {
123
+ min_fields: [
124
+ :failure_description,
125
+ :running_scenario__feature__name,
126
+ :running_scenario__name,
127
+ :running_scenario__line,
128
+ :step_data__name,
129
+ :step_data__line,
130
+ :exception__to_s,
131
+ :exception__backtrace
132
+ ],
133
+ more_info_fields: [
134
+ :exception__class__name,
135
+ :running_scenario__feature__tags,
136
+ :running_scenario,
137
+ :step_data,
138
+ :step_definitions,
139
+ :logs,
140
+ :capybara_page_diagnostics
141
+ ],
142
+ expand_fields: [
143
+ :running_scenario,
144
+ :step_data,
145
+ :step_definitions
146
+ ],
147
+ expand_inline_fields: [
148
+ ],
149
+ exclude_fields: [
150
+ :running_scenario__feature,
151
+ :step_data__scenario__feature,
152
+ :running_scenario__name,
153
+ :running_scenario__line,
154
+ :step_data__name,
155
+ :step_data__line
156
+ ]
157
+ },
158
+ capybara_page_diagnostics: {
159
+ min_fields: [
160
+ :capybara__page_url,
161
+ :capybara__title,
162
+ :capybara__screen_shot
163
+ ],
164
+ more_info_fields: [
165
+ :capybara,
166
+ :capybara__other_windows,
167
+ ],
168
+ expand_fields: [
169
+ :capybara,
170
+ :capybara__other_windows,
171
+ "capybara__other_windows__*",
172
+ ],
173
+ expand_inline_fields: [
174
+ :capybara,
175
+ ],
176
+ exclude_fields: [
177
+ :capybara__page_url,
178
+ :capybara__title,
179
+ :capybara__screen_shot,
180
+ :capybara__page_url,
181
+ :capybara__title,
182
+ :capybara__screen_shot,
183
+ :capybara__options,
184
+ :capybara__report,
185
+ :capybara__table,
186
+ :capybara__unsupported_list,
187
+ :capybara__allow_other_windows,
188
+ :capybara__iterating,
189
+ :capybara__session,
190
+ :capybara__driver,
191
+ :capybara__window_handles,
192
+ :capybara__current_window,
193
+ "capybara__other_windows__*__options",
194
+ "capybara__other_windows__*__report",
195
+ "capybara__other_windows__*__table",
196
+ "capybara__other_windows__*__unsupported_list",
197
+ "capybara__other_windows__*__allow_other_windows",
198
+ "capybara__other_windows__*__iterating",
199
+ "capybara__other_windows__*__session",
200
+ "capybara__other_windows__*__driver",
201
+ "capybara__other_windows__*__window_handles",
202
+ "capybara__other_windows__*__current_window"
203
+ ],
204
+ leaf_options: [
205
+ { report_element: [:html_source,
206
+ :html_frame,
207
+ :screen_shot
208
+ ],
209
+ report_options: { prevent_shrink: true,
210
+ exclude_code_block: true,
211
+ do_not_pretty_print: true
212
+ }
213
+ },
214
+ { report_element: [:html_file],
215
+ report_options: { exclude_code_block: true },
205
216
  }
206
- },
207
- { report_element: [:html_file],
208
- report_options: { exclude_code_block: true },
209
- }
210
- ]
211
- ),
212
- capybara_finder_diagnostics: Cornucopia::Util::ConfiguredReport.new(
213
- min_fields: [
214
- :finder__function_name,
215
- :finder__args__0,
216
- :finder__search_args,
217
- :finder__options,
218
- :exception__to_s,
219
- :exception__backtrace
220
- ],
221
- more_info_fields: [
222
- :exception__class__name,
223
- :finder,
224
- :capybara_page_diagnostics
225
- ],
226
- expand_fields: [
227
- :finder,
228
- :finder__args,
229
- :finder__all_elements,
230
- :finder__all_other_elements,
231
- "finder__all_elements__*",
232
- "finder__all_other_elements__*",
233
- "finder__all_elements__*__native_size",
234
- "finder__all_other_elements__*__native_size",
235
- "finder__all_elements__*__elem_location",
236
- "finder__all_other_elements__*__elem_location",
237
- :finder__search_args,
238
- :finder__options
239
- ],
240
- expand_inline_fields: [
241
- :finder
242
- ],
243
- exclude_fields: [
244
- :finder__return_value,
245
- :finder__function_name,
246
- :finder__args__0,
247
- :finder__search_args,
248
- :finder__options,
249
- :finder__report_options,
250
- :finder__test_object,
251
- "finder__all_elements__*__found_element",
252
- "finder__all_other_elements__*__found_element"
253
- ]
254
- )
255
- }
217
+ ]
218
+ },
219
+ capybara_finder_diagnostics: {
220
+ min_fields: [
221
+ :finder__function_name,
222
+ :finder__args__0,
223
+ :finder__search_args,
224
+ :finder__options,
225
+ :exception__to_s,
226
+ :exception__backtrace
227
+ ],
228
+ more_info_fields: [
229
+ :exception__class__name,
230
+ :finder,
231
+ :capybara_page_diagnostics
232
+ ],
233
+ expand_fields: [
234
+ :finder,
235
+ :finder__args,
236
+ :finder__all_elements,
237
+ :finder__all_other_elements,
238
+ "finder__all_elements__*",
239
+ "finder__all_other_elements__*",
240
+ "finder__all_elements__*__native_size",
241
+ "finder__all_other_elements__*__native_size",
242
+ "finder__all_elements__*__elem_location",
243
+ "finder__all_other_elements__*__elem_location",
244
+ :finder__search_args,
245
+ :finder__options
246
+ ],
247
+ expand_inline_fields: [
248
+ :finder
249
+ ],
250
+ exclude_fields: [
251
+ :finder__return_value,
252
+ :finder__function_name,
253
+ :finder__args__0,
254
+ :finder__search_args,
255
+ :finder__options,
256
+ :finder__report_options,
257
+ :finder__test_object,
258
+ "finder__all_elements__*__found_element",
259
+ "finder__all_other_elements__*__found_element"
260
+ ]
261
+ }
262
+ }
263
+
264
+ configurations.configured_reports = {}
265
+ end
256
266
 
257
267
  class << self
258
268
  # rand_seed is the seed value used to seed the srand function at the start of a test
@@ -262,24 +272,24 @@ module Cornucopia
262
272
  # and run the test again. This should re-run the exact same test, resulting in a
263
273
  # repeatable test even with randomization in it.
264
274
  def seed=(value)
265
- @@configurations.rand_seed = value
275
+ Cornucopia::Util::Configuration.instance.configurations.rand_seed = value
266
276
  srand(value) if value
267
277
  end
268
278
 
269
279
  def seed
270
- @@configurations.rand_seed
280
+ Cornucopia::Util::Configuration.instance.configurations.rand_seed
271
281
  end
272
282
 
273
283
  # order_seed is the seed value used to set the order that randomly ordered tests are run in.
274
284
  # This is provided as a convenience method. I think it is easier to set this in rails_helper than it is to
275
285
  # set it on the command line. This also provides a uniform method to do it.
276
286
  def order_seed=(value)
277
- @@configurations.order_seed = value
278
- RSpec.configuration.seed = value if value
287
+ Cornucopia::Util::Configuration.instance.configurations.order_seed = value
288
+ RSpec.configuration.seed = value if value
279
289
  end
280
290
 
281
291
  def order_seed
282
- @@configurations.order_seed
292
+ Cornucopia::Util::Configuration.instance.configurations.order_seed
283
293
  end
284
294
 
285
295
  # grab_logs indicates if the system should try to automatically grab a tail of
@@ -299,11 +309,11 @@ module Cornucopia
299
309
  # add_log_file
300
310
  # remove_log_file
301
311
  def grab_logs=(value)
302
- @@configurations.grab_logs = value
312
+ Cornucopia::Util::Configuration.instance.configurations.grab_logs = value
303
313
  end
304
314
 
305
315
  def grab_logs
306
- @@configurations.grab_logs
316
+ Cornucopia::Util::Configuration.instance.configurations.grab_logs
307
317
  end
308
318
 
309
319
  # user_log_files returns a hash of all of the log files which
@@ -313,19 +323,20 @@ module Cornucopia
313
323
  # grabbed, and the values are the options specified for the
314
324
  # files. The values may be an empty hash.
315
325
  def user_log_files
316
- @@configurations.user_log_files.clone
326
+ Cornucopia::Util::Configuration.instance.configurations.user_log_files.clone
317
327
  end
318
328
 
319
329
  # num_lines returns the number of lines that will be grabbed
320
330
  # for a file. If no file name is supplied, or the name does not match a
321
331
  # user file, the default log length will returned.
322
332
  def num_lines(log_file_name=nil)
323
- @@configurations.user_log_files[log_file_name].try(:[], :num_lines) || @@configurations.default_num_lines
333
+ Cornucopia::Util::Configuration.instance.configurations.user_log_files[log_file_name].try(:[], :num_lines) ||
334
+ Cornucopia::Util::Configuration.instance.configurations.default_num_lines
324
335
  end
325
336
 
326
337
  # default_num_lines sets the default number of lines to extract from the log file
327
338
  def default_num_lines=(value)
328
- @@configurations.default_num_lines = value
339
+ Cornucopia::Util::Configuration.instance.configurations.default_num_lines = value
329
340
  end
330
341
 
331
342
  # Adds the specified log file to the list of log files to capture.
@@ -333,14 +344,15 @@ module Cornucopia
333
344
  # the existing options.
334
345
  # See Cornucopia::LogCapture
335
346
  def add_log_file(log_file_name, options = {})
336
- @@configurations.user_log_files[log_file_name] ||= {}
337
- @@configurations.user_log_files[log_file_name] = @@configurations.user_log_files[log_file_name].merge options
347
+ Cornucopia::Util::Configuration.instance.configurations.user_log_files[log_file_name] ||= {}
348
+ Cornucopia::Util::Configuration.instance.configurations.user_log_files[log_file_name] =
349
+ Cornucopia::Util::Configuration.instance.configurations.user_log_files[log_file_name].merge options
338
350
  end
339
351
 
340
352
  # Removes the specified log file from the list of log files to capture.
341
353
  # NOTE: You cannot remove the default log file.
342
354
  def remove_log_file(log_file_name)
343
- @@configurations.user_log_files.delete log_file_name
355
+ Cornucopia::Util::Configuration.instance.configurations.user_log_files.delete log_file_name
344
356
  end
345
357
 
346
358
  # returns the report configuration object for that type of report
@@ -351,7 +363,35 @@ module Cornucopia
351
363
  # :spinach
352
364
  # :capybara_page_diagnostics
353
365
  def report_configuration(report_name)
354
- @@configurations.configured_reports[report_name]
366
+ Cornucopia::Util::Configuration.instance.configurations.configured_reports[report_name] ||=
367
+ Cornucopia::Util::ConfiguredReport.new(Cornucopia::Util::Configuration.instance.configurations.default_configuration[report_name])
368
+ end
369
+
370
+ # sets the report configuration object for that type of report from a configuration has that is passed in
371
+ #
372
+ # values for report_name:
373
+ # :rspec
374
+ # :cucumber
375
+ # :spinach
376
+ # :capybara_page_diagnostics
377
+ def set_report_configuration(report_name, configuration)
378
+ if configuration.is_a?(Cornucopia::Util::ConfiguredReport)
379
+ Cornucopia::Util::Configuration.instance.configurations.configured_reports[report_name] = configuration
380
+ else
381
+ Cornucopia::Util::Configuration.instance.configurations.configured_reports[report_name] =
382
+ Cornucopia::Util::ConfiguredReport.new(configuration)
383
+ end
384
+ end
385
+
386
+ # returns the report configuration object for that type of report
387
+ #
388
+ # values for report_name:
389
+ # :rspec
390
+ # :cucumber
391
+ # :spinach
392
+ # :capybara_page_diagnostics
393
+ def default_report_configuration(report_name)
394
+ Cornucopia::Util::Configuration.instance.configurations.default_configuration[report_name].try :clone
355
395
  end
356
396
 
357
397
  # Sets or returns the minimum amount of time in seconds to allow for the printing of variables.
@@ -363,11 +403,11 @@ module Cornucopia
363
403
  #
364
404
  # Default: 10
365
405
  def print_timeout_min
366
- @@configurations.print_timeout_min
406
+ Cornucopia::Util::Configuration.instance.configurations.print_timeout_min
367
407
  end
368
408
 
369
409
  def print_timeout_min=(value)
370
- @@configurations.print_timeout_min = value
410
+ Cornucopia::Util::Configuration.instance.configurations.print_timeout_min = value
371
411
  end
372
412
 
373
413
  # The Selenium driver can throw a StaleElementReferenceError exception sometimes.
@@ -385,11 +425,11 @@ module Cornucopia
385
425
  # that I've run into a lot. I am doing it this way to see if I can reduce the
386
426
  # the occurrence of it.
387
427
  def selenium_cache_retry_count
388
- @@configurations.selenium_cache_retry_count
428
+ Cornucopia::Util::Configuration.instance.configurations.selenium_cache_retry_count
389
429
  end
390
430
 
391
431
  def selenium_cache_retry_count=(value)
392
- @@configurations.selenium_cache_retry_count = value
432
+ Cornucopia::Util::Configuration.instance.configurations.selenium_cache_retry_count = value
393
433
  end
394
434
 
395
435
  # This setting is used by the Capybara utilities.
@@ -398,11 +438,11 @@ module Cornucopia
398
438
  # use the FinderDiagnostics to output some diagnostic information about the page and the finder
399
439
  # to try to assist in determining what happened.
400
440
  def analyze_find_exceptions
401
- @@configurations.analyze_find_exceptions
441
+ Cornucopia::Util::Configuration.instance.configurations.analyze_find_exceptions
402
442
  end
403
443
 
404
444
  def analyze_find_exceptions=(value)
405
- @@configurations.analyze_find_exceptions = value
445
+ Cornucopia::Util::Configuration.instance.configurations.analyze_find_exceptions = value
406
446
  end
407
447
 
408
448
  # This setting is used by the Capybara utilities.
@@ -411,11 +451,11 @@ module Cornucopia
411
451
  # use the FinderDiagnostics to output some diagnostic information about the page and the
412
452
  # selector to try to assist in determining what happened.
413
453
  def analyze_selector_exceptions
414
- @@configurations.analyze_selector_exceptions
454
+ Cornucopia::Util::Configuration.instance.configurations.analyze_selector_exceptions
415
455
  end
416
456
 
417
457
  def analyze_selector_exceptions=(value)
418
- @@configurations.analyze_selector_exceptions = value
458
+ Cornucopia::Util::Configuration.instance.configurations.analyze_selector_exceptions = value
419
459
  end
420
460
 
421
461
  # Sometimes, the analysis process found the element when it wasn't found other ways.
@@ -426,11 +466,11 @@ module Cornucopia
426
466
  # WARNING: Using this is unsafe. If you use it, you could get false positive
427
467
  # results in your test.
428
468
  def retry_with_found
429
- @@configurations.retry_with_found
469
+ Cornucopia::Util::Configuration.instance.configurations.retry_with_found
430
470
  end
431
471
 
432
472
  def retry_with_found=(value)
433
- @@configurations.retry_with_found = value
473
+ Cornucopia::Util::Configuration.instance.configurations.retry_with_found = value
434
474
  end
435
475
 
436
476
  # Sometimes, the analysis process found the element when it wasn't found other ways.
@@ -438,11 +478,11 @@ module Cornucopia
438
478
  #
439
479
  # The default is true because I have been getting a fair number of false negatives.
440
480
  def retry_match_with_found
441
- @@configurations.retry_match_with_found
481
+ Cornucopia::Util::Configuration.instance.configurations.retry_match_with_found
442
482
  end
443
483
 
444
484
  def retry_match_with_found=(value)
445
- @@configurations.retry_match_with_found = value
485
+ Cornucopia::Util::Configuration.instance.configurations.retry_match_with_found = value
446
486
  end
447
487
 
448
488
  # To make it easier to know about and to see the reports, this configuration will cause a report to be
@@ -455,12 +495,12 @@ module Cornucopia
455
495
  # "spinach_report"
456
496
 
457
497
  def auto_open_report_after_generation(open_report, report_name = nil)
458
- @@configurations.open_report_settings[report_name || :default] = open_report
498
+ Cornucopia::Util::Configuration.instance.configurations.open_report_settings[report_name || :default] = open_report
459
499
  end
460
500
 
461
501
  def open_report_after_generation(report_name)
462
- open_report = @@configurations.open_report_settings[report_name]
463
- open_report = @@configurations.open_report_settings[:default] if open_report.nil?
502
+ open_report = Cornucopia::Util::Configuration.instance.configurations.open_report_settings[report_name]
503
+ open_report = Cornucopia::Util::Configuration.instance.configurations.open_report_settings[:default] if open_report.nil?
464
504
  open_report
465
505
  end
466
506
 
@@ -484,22 +524,22 @@ module Cornucopia
484
524
  # # WARNING: Using this is unsafe. If you use it, you could get false positive
485
525
  # # results in your test.
486
526
  # def alternate_retry
487
- # @@configurations.alternate_retry
527
+ # Cornucopia::Util::Configuration.instance.configurations.alternate_retry
488
528
  # end
489
529
  #
490
530
  # def alternate_retry=(value)
491
- # @@configurations.alternate_retry = value
531
+ # Cornucopia::Util::Configuration.instance.configurations.alternate_retry = value
492
532
  # end
493
533
 
494
534
  # Sets or returns the name of the folder to generate reports into.
495
535
  #
496
536
  # Default: "cornucopia_report"
497
537
  def base_folder
498
- @@configurations.base_folder
538
+ Cornucopia::Util::Configuration.instance.configurations.base_folder
499
539
  end
500
540
 
501
541
  def base_folder=(value)
502
- @@configurations.base_folder = value
542
+ Cornucopia::Util::Configuration.instance.configurations.base_folder = value
503
543
  end
504
544
  end
505
545
  end
@@ -1,11 +1,22 @@
1
+ require "singleton"
2
+
1
3
  module Cornucopia
2
4
  module Util
5
+ class FileAssetCache
6
+ include Singleton
7
+
8
+ attr_accessor :asset_cache
9
+
10
+ def initialize
11
+ @asset_cache = {}
12
+ end
13
+ end
14
+
3
15
  class FileAsset
4
16
  class << self
5
17
  def asset(asset_name)
6
- @@asset_list ||= {}
7
- @@asset_list[asset_name.to_sym] = FileAsset.new(asset_name) unless @@asset_list[asset_name.to_sym]
8
- @@asset_list[asset_name.to_sym]
18
+ Cornucopia::Util::FileAssetCache.asset_cache[asset_name.to_sym] ||= FileAsset.new(asset_name)
19
+ Cornucopia::Util::FileAssetCache.asset_cache[asset_name.to_sym]
9
20
  end
10
21
  end
11
22
 
@@ -1,3 +1,3 @@
1
1
  module Cornucopia
2
- VERSION = "0.1.16"
2
+ VERSION = "0.1.17"
3
3
  end
@@ -32,7 +32,7 @@ describe "Cornucopia::Util::Configuration" do
32
32
  expect(Cornucopia::Util::Configuration.order_seed).to be == seed_value
33
33
  expect(RSpec.configuration.seed).to be == seed_value
34
34
  ensure
35
- RSpec.configuration.seed = config_seed
35
+ RSpec.configuration.seed = config_seed
36
36
  Cornucopia::Util::Configuration.order_seed = nil
37
37
  end
38
38
  end
@@ -161,9 +161,61 @@ describe "Cornucopia::Util::Configuration" do
161
161
  end
162
162
 
163
163
  describe "configured_reports" do
164
+ let(:sample_configuaration) do
165
+ config = {}
166
+ rand(5..10).times do
167
+ config[Faker::Lorem.word] = Faker::Lorem.sentence
168
+ end
169
+
170
+ config
171
+ end
172
+
164
173
  [:rspec, :cucumber, :spinach, :capybara_page_diagnostics].each do |report_type|
165
- it "has a #{report_type} report" do
166
- expect(Cornucopia::Util::Configuration.report_configuration(report_type)).to be
174
+ describe "#{report_type} configured reports" do
175
+ after(:each) do
176
+ Cornucopia::Util::Configuration.set_report_configuration(
177
+ report_type,
178
+ Cornucopia::Util::Configuration.default_report_configuration(report_type)
179
+ )
180
+ end
181
+
182
+ it "has a #{report_type} report" do
183
+ expect(Cornucopia::Util::Configuration.report_configuration(report_type)).to be
184
+ end
185
+
186
+ it "has a default #{report_type} report" do
187
+ expect(Cornucopia::Util::Configuration.default_report_configuration(report_type)).to be
188
+ end
189
+
190
+ it "can set a #{report_type} report" do
191
+ Cornucopia::Util::Configuration.set_report_configuration(report_type, sample_configuaration)
192
+ expect(Cornucopia::Util::Configuration.report_configuration(report_type)).to be_a(Cornucopia::Util::ConfiguredReport)
193
+ end
194
+
195
+ it "can set a #{report_type} report to a ConfiguredReport" do
196
+ configured_report = Cornucopia::Util::ConfiguredReport.
197
+ new(Cornucopia::Util::Configuration.default_report_configuration(report_type))
198
+
199
+ Cornucopia::Util::Configuration.set_report_configuration(report_type, configured_report)
200
+ expect(Cornucopia::Util::Configuration.report_configuration(report_type)).to eq configured_report
201
+ end
202
+
203
+ it "doesn't change the default #{report_type} report" do
204
+ orig = Cornucopia::Util::Configuration.default_report_configuration(report_type).clone
205
+ Cornucopia::Util::Configuration.set_report_configuration(report_type, sample_configuaration)
206
+ expect(Cornucopia::Util::Configuration.default_report_configuration(report_type)).to eq orig
207
+ end
208
+
209
+ it "you can't change the default #{report_type} report" do
210
+ defaults = Cornucopia::Util::Configuration.default_report_configuration(report_type)
211
+ orig = defaults.clone
212
+
213
+ config_value =Faker::Lorem.sentence
214
+ defaults[config_value] = config_value
215
+
216
+ expect(Cornucopia::Util::Configuration.default_report_configuration(report_type)).to eq orig
217
+ expect(Cornucopia::Util::Configuration.default_report_configuration(report_type)[config_value]).not_to be
218
+ end
167
219
  end
168
220
  end
169
221
  end
@@ -298,7 +350,7 @@ describe "Cornucopia::Util::Configuration" do
298
350
 
299
351
  it "returns the value for a report" do
300
352
  def_value = [true, false].sample
301
- report = Faker::Lorem.word
353
+ report = Faker::Lorem.word
302
354
 
303
355
  Cornucopia::Util::Configuration.auto_open_report_after_generation(def_value)
304
356
  Cornucopia::Util::Configuration.auto_open_report_after_generation(!def_value, report)
@@ -315,7 +367,7 @@ describe "Cornucopia::Util::Configuration" do
315
367
 
316
368
  it "#can set the value" do
317
369
  begin
318
- base_value = Faker::Lorem.sentence
370
+ base_value = Faker::Lorem.sentence
319
371
  Cornucopia::Util::Configuration.base_folder = base_value
320
372
 
321
373
  expect(Cornucopia::Util::Configuration.base_folder).to eq base_value
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cornucopia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealNobody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-28 00:00:00.000000000 Z
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails