Support selecting options by their values (Alex Lang)
This commit is contained in:
parent
7adeb86f2c
commit
1b51de8f0f
@ -10,7 +10,8 @@
|
||||
|
||||
* Minor enhancements
|
||||
|
||||
* Add support for clicking areas of an image map (Alex Lang)
|
||||
* Support selecting options by their values (Alex Lang)
|
||||
* Support for clicking areas of an image map (Alex Lang)
|
||||
* Add should_see and should_not_see for verifying HTML response bodys
|
||||
* Support relative links, including href="?foo=bar" (Kyle Hargraves)
|
||||
* Separated Rails-specific code from the Webrat core to make it easier to use Webrat with other environments
|
||||
|
@ -30,11 +30,11 @@ module Webrat
|
||||
end
|
||||
|
||||
def matches_id?(id)
|
||||
@element["id"] == id.to_s
|
||||
matches?(self.id, id)
|
||||
end
|
||||
|
||||
def matches_name?(name)
|
||||
@element["name"] == name.to_s
|
||||
matches?(self.name, name)
|
||||
end
|
||||
|
||||
def matches_label?(label_text)
|
||||
@ -69,6 +69,14 @@ module Webrat
|
||||
|
||||
protected
|
||||
|
||||
def matches?(string, string_or_regex)
|
||||
if string_or_regex.is_a?(Regexp)
|
||||
string_or_regex.match string
|
||||
else
|
||||
string == string_or_regex
|
||||
end
|
||||
end
|
||||
|
||||
def id
|
||||
@element["id"]
|
||||
end
|
||||
@ -303,7 +311,7 @@ module Webrat
|
||||
class SelectField < Field
|
||||
|
||||
def find_option(text)
|
||||
options.detect { |o| o.matches_text?(text) }
|
||||
options.detect { |o| o.matches_text?(text) || o.matches_value?(text)}
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -14,6 +14,10 @@ module Webrat
|
||||
end
|
||||
end
|
||||
|
||||
def matches_value?(value)
|
||||
@element.attributes['value'] == value.to_s
|
||||
end
|
||||
|
||||
def choose
|
||||
@select.raise_error_if_disabled
|
||||
@select.set(value)
|
||||
|
@ -108,6 +108,18 @@ describe "selects" do
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send value from option in list specified by value" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<select name="start_month"><option value="s1">January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.should_receive(:post).with("/login", "start_month" => "s1")
|
||||
@session.selects "s1", :from => "start_month"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send value from option in list specified by label" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
|
Loading…
Reference in New Issue
Block a user