Class: Wrapybara::TableCell

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/wrapybara/elements/table_cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Element

#click, #default_how, #default_scope, #disabled?, #element_identifier, #enabled?, #focused?, #get_element, #parent_identifier, #path, #should_be_disabled, #should_be_enabled, #should_be_focused, #should_be_visible, #should_have_attribute, #should_not_be_disabled, #should_not_be_enabled, #should_not_be_focused, #should_not_be_visible, #should_not_have_attribute, #style, #visible?, #within

Constructor Details

#initialize(parent, *args) ⇒ TableCell

Returns a new instance of TableCell.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wrapybara/elements/table_cell.rb', line 7

def initialize(parent, *args)
	args = args.first if args.first.is_a?(Array)
	
	@parent = parent
	t_what = parent.is_a?(TableHead) ? 'th' : 'td'
	xpath =
		if args.first.to_i == 0
			@content = args.first
			"*/#{t_what}[contains(normalize-space(), '#{@content}')]"
		else
			@row = args.first.to_i
			@column = args.last.to_i
			"tr[#{@row}]/#{t_what}[#{@column}]"
		end

	@element = parent.element.find(xpath) rescue nil
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



5
6
7
# File 'lib/wrapybara/elements/table_cell.rb', line 5

def element
  @element
end

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/wrapybara/elements/table_cell.rb', line 5

def parent
  @parent
end

Instance Method Details

#contains?(element, identifier, how) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/wrapybara/elements/table_cell.rb', line 53

def contains?(element, identifier, how)
	child = "Wrapybara::#{element.camelize}".constantize.new(identifier, self.element.path, how)
	child.exists?
end

#contains_message(element, identifier, how) ⇒ Object



80
81
82
83
84
85
# File 'lib/wrapybara/elements/table_cell.rb', line 80

def contains_message(element, identifier, how)
	parent = @parent.is_a?(TableHead) ? 'head' : 'body'
	message = "#{parent} cell at row #{@row} column #{@column} of table #{@parent.parent.how} '#{@parent.parent.identifier}'#{within(@parent.parent.scope)}"
	message += " to contain a[n] #{element} #{how} '#{identifier}'"
	message
end

#exists?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/wrapybara/elements/table_cell.rb', line 58

def exists?
	!@element.nil?
end

#exists_messageObject



66
67
68
69
70
71
# File 'lib/wrapybara/elements/table_cell.rb', line 66

def exists_message
	parent = @parent.is_a?(TableHead) ? 'head' : 'body'
	message = "#{parent} of table #{@parent.parent.how} '#{@parent.parent.identifier}'#{within(@parent.parent.scope)} to have a cell "
	message += @content ? "with content '#{@content}'" : "at row #{@row} column #{@column}"
	message
end

#has_content?(content) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/wrapybara/elements/table_cell.rb', line 62

def has_content?(content)
	@element.text =~ /#{content}/
end

#has_content_message(content) ⇒ Object



73
74
75
76
77
78
# File 'lib/wrapybara/elements/table_cell.rb', line 73

def has_content_message(content)
	parent = @parent.is_a?(TableHead) ? 'head' : 'body'
	message = "#{parent} cell at row #{@row} column #{@column} of table #{@parent.parent.how} '#{@parent.parent.identifier}'#{within(@parent.parent.scope)}"
	message += " to have content '#{content}'"
	message
end

#should_contain(element, identifier, how) ⇒ Object

Raises:



43
44
45
46
# File 'lib/wrapybara/elements/table_cell.rb', line 43

def should_contain(element, identifier, how)
	self.should_exist
	raise UnmetExpectation, "Expected #{self.contains_message(element, identifier, how)}" unless self.contains?(element, identifier, how)
end

#should_existObject



25
26
27
# File 'lib/wrapybara/elements/table_cell.rb', line 25

def should_exist
	super "Expected #{self.exists_message}"
end

#should_have_content(content) ⇒ Object

Raises:



33
34
35
36
# File 'lib/wrapybara/elements/table_cell.rb', line 33

def should_have_content(content)
	self.should_exist
	raise UnmetExpectation, "Expected #{self.has_content_message(content)}" unless self.has_content?(content)
end

#should_not_contain(element, identifier, how) ⇒ Object

Raises:



48
49
50
51
# File 'lib/wrapybara/elements/table_cell.rb', line 48

def should_not_contain(element, identifier, how)
	self.should_exist
	raise UnmetExpectation, "Did not expect #{self.contains_message(element, identifier, how)}" if self.contains?(element, identifier, how)
end

#should_not_content(content) ⇒ Object

Raises:



38
39
40
41
# File 'lib/wrapybara/elements/table_cell.rb', line 38

def should_not_content(content)
	self.should_exist
	raise UnmetExpectation, "Did not expect #{self.has_content_message(content)}" if self.has_content?(content)
end

#should_not_existObject



29
30
31
# File 'lib/wrapybara/elements/table_cell.rb', line 29

def should_not_exist
	super "Did not expect #{self.exists_message}"
end