Class: Dekiru::Capybara::Matchers::JsNoErrorMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/dekiru/capybara/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(example_description) ⇒ JsNoErrorMatcher

Returns a new instance of JsNoErrorMatcher.



5
6
7
# File 'lib/dekiru/capybara/matchers.rb', line 5

def initialize(example_description)
  @example_description = example_description
end

Instance Method Details

#descriptionObject



24
25
26
# File 'lib/dekiru/capybara/matchers.rb', line 24

def description
  'have no js errors'
end

#failure_messageObject



28
29
30
# File 'lib/dekiru/capybara/matchers.rb', line 28

def failure_message
  @severe_errors.map(&:message).join("\n")
end

#matches?(page_or_logs) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dekiru/capybara/matchers.rb', line 9

def matches?(page_or_logs)
  logs = if page_or_logs.respond_to?(:driver)
           page_or_logs.driver.browser.logs.get(:browser)
         else
           page_or_logs
         end
  logs.find_all { |log| log.level == 'WARNING' }.each do |log|
    STDERR.puts "WARN: javascript warning in #{@example_description}"
    STDERR.puts log.message
  end

  @severe_errors = logs.find_all { |log| log.level == 'SEVERE' }
  @severe_errors.empty?
end