Class: Wrapybara::Option

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Element

#click, #default_how, #default_scope, #disabled?, #element_identifier, #enabled?, #exists?, #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(select, option) ⇒ Option

Returns a new instance of Option.



7
8
9
10
11
12
# File 'lib/wrapybara/elements/option.rb', line 7

def initialize(select, option)
	@option = option
	@parent = select
	xpath = option.blank? ? ".//option[normalize-space()='']" : XPath::HTML.option(option)
	@element = select.element.find(xpath) rescue nil
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



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

def element
  @element
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

Instance Method Details

#deselectObject



28
29
30
31
32
# File 'lib/wrapybara/elements/option.rb', line 28

def deselect
	self.should_exist
	# Capybara method
	@element.unselect_option
end

#selectObject



22
23
24
25
26
# File 'lib/wrapybara/elements/option.rb', line 22

def select
	self.should_exist
	# Capybara method
	@element.select_option
end

#selected?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/wrapybara/elements/option.rb', line 34

def selected?
	self.should_exist
	# Capybara method
	@element.selected? || @parent.element.value == @element.value
end

#should_be_selectedObject

Raises:



40
41
42
# File 'lib/wrapybara/elements/option.rb', line 40

def should_be_selected
	raise UnmetExpectation, "Expected select #{self.parent_identifier} to have option '#{@option}' selected" unless self.selected?
end

#should_existObject



14
15
16
# File 'lib/wrapybara/elements/option.rb', line 14

def should_exist
	super "Expected select #{self.parent_identifier} to have option '#{@option}'"
end

#should_not_be_selectedObject

Raises:



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

def should_not_be_selected
	raise UnmetExpectation, "Did not expect select #{self.parent_identifier} to have option '#{@option}' selected" if self.selected?
end

#should_not_existObject



18
19
20
# File 'lib/wrapybara/elements/option.rb', line 18

def should_not_exist
	super "Did not expect select #{self.parent_identifier} to have option '#{@option}'"
end