Class: Spec::Matchers::Watir::ElementMatcher

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

Overview

:nodoc

Instance Method Summary collapse

Constructor Details

#initialize(kind, *args) ⇒ ElementMatcher

Returns a new instance of ElementMatcher.



38
39
40
# File 'lib/spec/ui/watir/matchers.rb', line 38

def initialize(kind, *args)
  @kind, @args = kind, args
end

Instance Method Details

#arg_stringObject



67
68
69
# File 'lib/spec/ui/watir/matchers.rb', line 67

def arg_string
  @args.map{|a| a.inspect}.join(", ")
end

#failure_messageObject



59
60
61
# File 'lib/spec/ui/watir/matchers.rb', line 59

def failure_message
  "Expected #{@container.class} to have #{@kind}(#{arg_string}), but it was not found"
end

#matches?(container) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spec/ui/watir/matchers.rb', line 42

def matches?(container)
  @container = container
  begin
    element = @container.__send__(@kind, *@args)
    if element.respond_to?(:assert_exists)
      # IE
      element.assert_exists
      true
    else
      # Safari
      element.exists?
    end
  rescue ::Watir::Exception::UnknownObjectException => e
    false
  end
end

#negative_failure_messageObject



63
64
65
# File 'lib/spec/ui/watir/matchers.rb', line 63

def negative_failure_message
  "Expected #{@container.class} to not have #{@kind}(#{arg_string}), but it was found"
end