Class: Spec::Matchers::Watir::ContentMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/ui/watir/matchers.rb

Overview

:nodoc

Instance Method Summary collapse

Constructor Details

#initialize(kind, text_or_regexp) ⇒ ContentMatcher

Returns a new instance of ContentMatcher.



4
5
6
# File 'lib/spec/ui/watir/matchers.rb', line 4

def initialize(kind, text_or_regexp)
  @kind, @text_or_regexp = kind, text_or_regexp
end

Instance Method Details

#failure_messageObject



18
19
20
# File 'lib/spec/ui/watir/matchers.rb', line 18

def failure_message
  "Expected #{@container.class} to have #{@kind} matching #{@text_or_regexp}, but it was not found in:\n#{@content}"
end

#matches?(container) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
# File 'lib/spec/ui/watir/matchers.rb', line 8

def matches?(container)
  @container = container
  @content = container.__send__(@kind)
  if @text_or_regexp.is_a?(Regexp)
    !!@content =~ @text_or_regexp
  else
    !!@content.index(@text_or_regexp.to_s)
  end
end

#negative_failure_messageObject



22
23
24
# File 'lib/spec/ui/watir/matchers.rb', line 22

def negative_failure_message
  "Expected #{@container.class} to not have #{@kind} matching #{@text_or_regexp}, but it was found in:\n#{@content}"
end