SelectOption is a Webrat::Element too
This commit is contained in:
parent
c84e5335b5
commit
830b459482
|
@ -7,7 +7,7 @@ require "webrat/core/scope"
|
|||
require "webrat/core/elements/link"
|
||||
require "webrat/core/elements/area"
|
||||
require "webrat/core/elements/label"
|
||||
require "webrat/core/select_option"
|
||||
require "webrat/core/elements/select_option"
|
||||
require "webrat/core/session"
|
||||
require "webrat/core/methods"
|
||||
require "webrat/core/matchers"
|
||||
|
|
|
@ -369,7 +369,7 @@ module Webrat
|
|||
end
|
||||
|
||||
def options
|
||||
option_elements.map { |oe| SelectOption.new(self, oe) }
|
||||
option_elements.map { |oe| SelectOption.new(@session, oe) }
|
||||
end
|
||||
|
||||
def option_elements
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
require "webrat/core/elements/element"
|
||||
|
||||
module Webrat
|
||||
class SelectOption < Element #:nodoc:
|
||||
|
||||
def matches_text?(text)
|
||||
if text.is_a?(Regexp)
|
||||
Webrat::XML.inner_html(@element) =~ text
|
||||
else
|
||||
Webrat::XML.inner_html(@element) == text.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def choose
|
||||
select.raise_error_if_disabled
|
||||
select.set(value)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def select
|
||||
@session.element_to_webrat_element(select_element)
|
||||
end
|
||||
|
||||
def select_element
|
||||
parent = @element.parent
|
||||
|
||||
while parent.respond_to?(:parent)
|
||||
return parent if parent.name == 'select'
|
||||
parent = parent.parent
|
||||
end
|
||||
end
|
||||
|
||||
def value
|
||||
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,29 +0,0 @@
|
|||
module Webrat
|
||||
class SelectOption #:nodoc:
|
||||
|
||||
def initialize(select, element)
|
||||
@select = select
|
||||
@element = element
|
||||
end
|
||||
|
||||
def matches_text?(text)
|
||||
if text.is_a?(Regexp)
|
||||
Webrat::XML.inner_html(@element) =~ text
|
||||
else
|
||||
Webrat::XML.inner_html(@element) == text.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def choose
|
||||
@select.raise_error_if_disabled
|
||||
@select.set(value)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def value
|
||||
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue