Class: Locator::Matcher::HaveTag

Inherits:
Object
  • Object
show all
Defined in:
lib/locator/matcher/have_tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ HaveTag

Returns a new instance of HaveTag.



6
7
8
9
10
11
# File 'lib/locator/matcher/have_tag.rb', line 6

def initialize(*args, &block)
  @options  = args.last.is_a?(Hash) ? args.pop : {}
  @selector = args.pop
  @count    = options.delete(:count)
  @block    = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/locator/matcher/have_tag.rb', line 4

def block
  @block
end

#countObject (readonly)

Returns the value of attribute count.



4
5
6
# File 'lib/locator/matcher/have_tag.rb', line 4

def count
  @count
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/locator/matcher/have_tag.rb', line 4

def options
  @options
end

#selectorObject (readonly)

Returns the value of attribute selector.



4
5
6
# File 'lib/locator/matcher/have_tag.rb', line 4

def selector
  @selector
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/locator/matcher/have_tag.rb', line 4

def target
  @target
end

Instance Method Details

#failure_messageObject

TODO



29
30
31
# File 'lib/locator/matcher/have_tag.rb', line 29

def failure_message # TODO
  "expected following text to match selector #{selector.inspect} and #{options.inspect}:\n#{target}"
end

#match_countObject



18
19
20
21
22
# File 'lib/locator/matcher/have_tag.rb', line 18

def match_count
  elements = Locator.all(target, selector, options)
  elements = elements.select(&block) if block
  elements.size == count.to_i
end

#match_elementObject



24
25
26
27
# File 'lib/locator/matcher/have_tag.rb', line 24

def match_element
  element = Locator.locate(target, selector, options)
  element && block ? Locator.within(element) { block.call(element) } : element
end

#matches?(target = nil) ⇒ Boolean

Returns:



13
14
15
16
# File 'lib/locator/matcher/have_tag.rb', line 13

def matches?(target = nil)
  @target = target
  count ? match_count : !!match_element
end

#negative_failure_messageObject



33
34
35
# File 'lib/locator/matcher/have_tag.rb', line 33

def negative_failure_message
  "expected following text to not match selector #{selector.inspect} and #{options.inspect}:\n#{target}"
end