Class: Xpath::Specs::PagePart

Inherits:
Object
  • Object
show all
Defined in:
lib/xpath/specs/page_part.rb

Overview

XPath wrapper providing a user friendly description. Should be used with the contain_a rspec matcher.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, xpath, parent = nil) ⇒ PagePart

description: user friendly text used in assertions error messages xpath: the actual xpath to search for parent: an optional parent page part, used to provide better assertion failure diagnostic



14
15
16
17
18
# File 'lib/xpath/specs/page_part.rb', line 14

def initialize(description, xpath, parent = nil)
  @xpath = xpath
  @description = description
  @parent = parent
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



20
21
22
# File 'lib/xpath/specs/page_part.rb', line 20

def description
  @description
end

#parentObject (readonly)

Returns the value of attribute parent.



20
21
22
# File 'lib/xpath/specs/page_part.rb', line 20

def parent
  @parent
end

#xpathObject (readonly)

Returns the value of attribute xpath.



20
21
22
# File 'lib/xpath/specs/page_part.rb', line 20

def xpath
  @xpath
end

Instance Method Details

#has_parentObject



22
23
24
# File 'lib/xpath/specs/page_part.rb', line 22

def has_parent
  !parent.nil?
end

#long_descriptionObject

A full description containing the xpath



27
28
29
# File 'lib/xpath/specs/page_part.rb', line 27

def long_description
  "#{description} (#{xpath})"
end

#that(description, xpath) ⇒ Object

Creates another PagePart instance to match elements relatively to self Concatenates the descriptions. It’s the prefered way to add constraints to the currently matched elements, xpath should usually start with ‘[’



41
42
43
44
45
# File 'lib/xpath/specs/page_part.rb', line 41

def that(description, xpath)
  PagePart.new("#{self.description} that #{description}",
               self.xpath+xpath,
               self)
end

#with(description, xpath) ⇒ Object

Creates another PagePart instance to match elements relatively to self Uses a completely new description. It’s the prefered way to mach sub elements, xpath should usually start with ‘/’



34
35
36
# File 'lib/xpath/specs/page_part.rb', line 34

def with(description, xpath)
  PagePart.new(description, self.xpath+xpath, self)
end

#within_a(outer_page_part) ⇒ Object

Creates another PagePart instance like self, but relatively to another existing page part.



49
50
51
# File 'lib/xpath/specs/page_part.rb', line 49

def within_a(outer_page_part)
  outer_page_part.with(self.description, self.xpath)
end