lib/capybara/chromedriver/logger/collector.rb in capybara-chromedriver-logger-0.2.0 vs lib/capybara/chromedriver/logger/collector.rb in capybara-chromedriver-logger-0.2.1

- old
+ new

@@ -1,13 +1,15 @@ module Capybara module Chromedriver module Logger class Collector - def initialize(log_destination: $stdout, filters: nil) - @log_destination = log_destination - @filters = filters || Capybara::Chromedriver::Logger.filters + def initialize(options = {}) @errors = [] + @log_destination = options[:log_destination] || $stdout + @filters = options[:filters] || Capybara::Chromedriver::Logger.filters + @filter_levels = options[:filter_levels] || + Capybara::Chromedriver::Logger.filter_levels end def flush_and_check_errors! flush_logs! @@ -22,12 +24,11 @@ return if errors.empty? formatted_errors = errors.map(&:to_s) error_list = formatted_errors.join("\n") - raise JsError, - "Got some JS errors during testing:\n\n#{error_list}" + raise JsError, "Got some JS errors during testing:\n\n#{error_list}" end def flush_logs! browser_logs.each do |log| message = Message.new(log) @@ -53,23 +54,24 @@ .logs .get(type) end def should_filter?(message) - filters.any? { |filter| filter =~ message.message } + should_filter_by_level?(message) || should_filter_content?(message) end - def errors - @errors + def should_filter_by_level?(message) + filter_levels.include?(message.level) end - def filters - @filters + def should_filter_content?(message) + filters.any? { |filter| filter =~ message.message } end - def log_destination - @log_destination - end + attr_reader :errors + attr_reader :filters + attr_reader :filter_levels + attr_reader :log_destination end end end end