Class: Spec::Watir::HaveText

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

Overview

:nodoc

Instance Method Summary collapse

Constructor Details

#initialize(text_or_regexp) ⇒ HaveText

Returns a new instance of HaveText.



51
52
53
# File 'lib/spec/ui/watir_helper.rb', line 51

def initialize(text_or_regexp)
  @text_or_regexp = text_or_regexp
end

Instance Method Details

#failure_messageObject



64
65
66
# File 'lib/spec/ui/watir_helper.rb', line 64

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

#matches?(browser) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
# File 'lib/spec/ui/watir_helper.rb', line 55

def matches?(browser)
  @browser = browser
  if @text_or_regexp.is_a?(Regexp)
    !!browser.text =~ @text_or_regexp
  else
    !!browser.text.index(@text_or_regexp.to_s)
  end
end

#negative_failure_messageObject



68
69
70
# File 'lib/spec/ui/watir_helper.rb', line 68

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