Class: Capybara::Playwright::PageExtension::DialogMessageMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/playwright/page.rb

Instance Method Summary collapse

Constructor Details

#initialize(text_or_regex_or_nil) ⇒ DialogMessageMatcher

Returns a new instance of DialogMessageMatcher.



69
70
71
72
73
74
75
# File 'lib/capybara/playwright/page.rb', line 69

def initialize(text_or_regex_or_nil)
  if [NilClass, Regexp, String].none? { |k| text_or_regex_or_nil.is_a?(k) }
    raise ArgumentError.new("invalid type: #{text_or_regex_or_nil.inspect}")
  end

  @filter = text_or_regex_or_nil
end

Instance Method Details

#matches?(message) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
86
# File 'lib/capybara/playwright/page.rb', line 77

def matches?(message)
  case @filter
  when nil
    true
  when Regexp
    message =~ @filter
  when String
    message&.include?(@filter)
  end
end