Class: Cornucopia::Util::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cornucopia/util/configuration.rb

Constant Summary collapse

@@configurations =
Cornucopia::Util::GenericSettings.new

Class Method Summary collapse

Class Method Details

.add_log_file(log_file_name, options = {}) ⇒ Object

Adds the specified log file to the list of log files to capture. If the log file is already in the list, the passed in options will be merged with the existing options. See Cornucopia::LogCapture



321
322
323
324
# File 'lib/cornucopia/util/configuration.rb', line 321

def add_log_file(log_file_name, options = {})
  @@configurations.user_log_files[log_file_name] ||= {}
  @@configurations.user_log_files[log_file_name] = @@configurations.user_log_files[log_file_name].merge options
end

.analyze_find_exceptions ⇒ Object

This setting is used by the Capybara utilities.

When Capybara::Node.find throws an exception, if this is set, the system will try to use the FinderDiagnostics to output some diagnostic information about the page and the finder to try to assist in determining what happened.



386
387
388
# File 'lib/cornucopia/util/configuration.rb', line 386

def analyze_find_exceptions
  @@configurations.analyze_find_exceptions
end

.analyze_find_exceptions=(value) ⇒ Object



390
391
392
# File 'lib/cornucopia/util/configuration.rb', line 390

def analyze_find_exceptions=(value)
  @@configurations.analyze_find_exceptions = value
end

.analyze_selector_exceptions ⇒ Object

This setting is used by the Capybara utilities.

When Capybara::Node.analyze_selector throws an exception, if this is set, the system will try to use the FinderDiagnostics to output some diagnostic information about the page and the selector to try to assist in determining what happened.



399
400
401
# File 'lib/cornucopia/util/configuration.rb', line 399

def analyze_selector_exceptions
  @@configurations.analyze_selector_exceptions
end

.analyze_selector_exceptions=(value) ⇒ Object



403
404
405
# File 'lib/cornucopia/util/configuration.rb', line 403

def analyze_selector_exceptions=(value)
  @@configurations.analyze_selector_exceptions = value
end

.auto_open_report_after_generation(open_report, report_name = nil) ⇒ Object

To make it easier to know about and to see the reports, this configuration will cause a report to be automatically opened if there is anything to report when the report is closed.

The posible values for report_name are:

nil
"rspec_report"
"cucumber_report"
"spinach_report"


443
444
445
# File 'lib/cornucopia/util/configuration.rb', line 443

def auto_open_report_after_generation(open_report, report_name = nil)
  @@configurations.open_report_settings[report_name || :default] = open_report
end

.base_folder ⇒ Object

Sets or returns the name of the folder to generate reports into.

Default: "cornucopia_report"



483
484
485
# File 'lib/cornucopia/util/configuration.rb', line 483

def base_folder
  @@configurations.base_folder
end

.base_folder=(value) ⇒ Object



487
488
489
# File 'lib/cornucopia/util/configuration.rb', line 487

def base_folder=(value)
  @@configurations.base_folder = value
end

.default_num_lines=(value) ⇒ Object

default_num_lines sets the default number of lines to extract from the log file



313
314
315
# File 'lib/cornucopia/util/configuration.rb', line 313

def default_num_lines=(value)
  @@configurations.default_num_lines = value
end

.grab_logs ⇒ Object



291
292
293
# File 'lib/cornucopia/util/configuration.rb', line 291

def grab_logs
  @@configurations.grab_logs
end

.grab_logs=(value) ⇒ Object

grab_logs indicates if the system should try to automatically grab a tail of the log file if outputing a diagnostics report.

The system will try to grab the following log files:

* Rails.env.log
* any user specified logs

The log capture is done by reading from the end of the file of the log file. If the log file cannot be found, or if the system cannot open the file (no access rights, etc.) nothing will be output.

Related options:

user_log_files
num_lines
add_log_file
remove_log_file


287
288
289
# File 'lib/cornucopia/util/configuration.rb', line 287

def grab_logs=(value)
  @@configurations.grab_logs = value
end

.num_lines(log_file_name = nil) ⇒ Object

num_lines returns the number of lines that will be grabbed for a file. If no file name is supplied, or the name does not match a user file, the default log length will returned.



308
309
310
# File 'lib/cornucopia/util/configuration.rb', line 308

def num_lines(log_file_name=nil)
  @@configurations.user_log_files[log_file_name].try(:[], :num_lines) || @@configurations.default_num_lines
end

.open_report_after_generation(report_name) ⇒ Object



447
448
449
450
451
# File 'lib/cornucopia/util/configuration.rb', line 447

def open_report_after_generation(report_name)
  open_report = @@configurations.open_report_settings[report_name]
  open_report = @@configurations.open_report_settings[:default] if open_report.nil?
  open_report
end

Sets or returns the minimum amount of time in seconds to allow for the printing of variables. If it is available, the larger of this value and Capybara.default_wait_time will be used.

This value exists to prevent the printing of a value on a report from taking too long and holding up the system. If it takes longer than this amount of time to get the value it probably isn't diagnostically important.

Default: 10



351
352
353
# File 'lib/cornucopia/util/configuration.rb', line 351

def print_timeout_min
  @@configurations.print_timeout_min
end


355
356
357
# File 'lib/cornucopia/util/configuration.rb', line 355

def print_timeout_min=(value)
  @@configurations.print_timeout_min = value
end

.remove_log_file(log_file_name) ⇒ Object

Removes the specified log file from the list of log files to capture. NOTE: You cannot remove the default log file.



328
329
330
# File 'lib/cornucopia/util/configuration.rb', line 328

def remove_log_file(log_file_name)
  @@configurations.user_log_files.delete log_file_name
end

.report_configuration(report_name) ⇒ Object

returns the report configuration object for that type of report

values for report_name:

:rspec
:cucumber
:spinach
:capybara_page_diagnostics


339
340
341
# File 'lib/cornucopia/util/configuration.rb', line 339

def report_configuration(report_name)
  @@configurations.configured_reports[report_name]
end

.retry_match_with_found ⇒ Object

Sometimes, the analysis process found the element when it wasn't found other ways. This will cause the match accessor to try again with the found element.

The default is true because I have been getting a fair number of false negatives.



426
427
428
# File 'lib/cornucopia/util/configuration.rb', line 426

def retry_match_with_found
  @@configurations.retry_match_with_found
end

.retry_match_with_found=(value) ⇒ Object



430
431
432
# File 'lib/cornucopia/util/configuration.rb', line 430

def retry_match_with_found=(value)
  @@configurations.retry_match_with_found = value
end

.retry_with_found ⇒ Object

Sometimes, the analysis process found the element when it wasn't found other ways. This will cause the finder to try again with the found element.

The default is false because I haven't seen this be useful in a while.

WARNING: Using this is unsafe. If you use it, you could get false positive results in your test.



414
415
416
# File 'lib/cornucopia/util/configuration.rb', line 414

def retry_with_found
  @@configurations.retry_with_found
end

.retry_with_found=(value) ⇒ Object



418
419
420
# File 'lib/cornucopia/util/configuration.rb', line 418

def retry_with_found=(value)
  @@configurations.retry_with_found = value
end

.seed ⇒ Object



267
268
269
# File 'lib/cornucopia/util/configuration.rb', line 267

def seed
  @@configurations.rand_seed
end

.seed=(value) ⇒ Object

rand_seed is the seed value used to seed the srand function at the start of a test suite. This is done to allow tests with random elements in them to be repeatable. If a test fails, simply set Cornucopia::Util::Configuration.rand_seed to the value of the failed tests seed value (output in the stdout and the generated report) and run the test again. This should re-run the exact same test, resulting in a repeatable test even with randomization in it.



262
263
264
265
# File 'lib/cornucopia/util/configuration.rb', line 262

def seed=(value)
  @@configurations.rand_seed = value
  srand(value) if value
end

.selenium_cache_retry_count ⇒ Object

The Selenium driver can throw a StaleElementReferenceError exception sometimes. I often see it with animated items like dialog boxes and the like. When the system is looping trying to find the element or stop seeing it.

Because the element likely just disappeared between when it was found and when it was returned, trying again will often make the problem go away.

The default for this setting is 5 which will retry the find function if this error occurs.

NOTE: This should already be the default action (basically) for the Selenium driver, yet from a purely practical standpoint, this seems to be a problem that I've run into a lot. I am doing it this way to see if I can reduce the the occurrence of it.



373
374
375
# File 'lib/cornucopia/util/configuration.rb', line 373

def selenium_cache_retry_count
  @@configurations.selenium_cache_retry_count
end

.selenium_cache_retry_count=(value) ⇒ Object



377
378
379
# File 'lib/cornucopia/util/configuration.rb', line 377

def selenium_cache_retry_count=(value)
  @@configurations.selenium_cache_retry_count = value
end

.user_log_files ⇒ Object

user_log_files returns a hash of all of the log files which the user has specified are to be grabbed.

The keys are the relative paths of the log files to be grabbed, and the values are the options specified for the files. The values may be an empty hash.



301
302
303
# File 'lib/cornucopia/util/configuration.rb', line 301

def user_log_files
  @@configurations.user_log_files.clone
end