More clarification of select option locating behavior.

TODO: Ensure the other locators are all matching on text, not HTML
This commit is contained in:
Bryan Helmkamp 2009-09-07 12:53:06 -04:00
parent 00c49a0521
commit 2490c247d2
2 changed files with 69 additions and 23 deletions

View File

@ -19,7 +19,7 @@ module Webrat
field.options.detect do |o| field.options.detect do |o|
if @option_text.is_a?(Regexp) if @option_text.is_a?(Regexp)
o.element.inner_html =~ @option_text o.element.inner_text =~ @option_text
else else
o.inner_text == @option_text.to_s o.inner_text == @option_text.to_s
end end
@ -27,7 +27,7 @@ module Webrat
else else
option_element = option_elements.detect do |o| option_element = option_elements.detect do |o|
if @option_text.is_a?(Regexp) if @option_text.is_a?(Regexp)
o.inner_html =~ @option_text o.inner_text =~ @option_text
else else
o.inner_text == @option_text.to_s o.inner_text == @option_text.to_s
end end

View File

@ -168,6 +168,36 @@ describe "select" do
click_button click_button
end end
it "should find options by regexp with HTML entities" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<select name="month"><option>Peanut butter &amp; jelly</option></select>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
select /Peanut butter & jelly/
click_button
end
it "should not find options by regexp with HTML entities in the regexp" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<select name="month"><option>Peanut butter &amp; jelly</option></select>
<input type="submit" />
</form>
</html>
HTML
lambda {
select /Peanut butter &amp; jelly/
}.should raise_error(Webrat::NotFoundError)
end
it "should fail if no option matching the regexp exists" do it "should fail if no option matching the regexp exists" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -201,31 +231,47 @@ describe "select" do
end end
it "should properly handle submitting HTML entities in select values" do it "should properly handle submitting HTML entities in select values" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>Peanut butter &amp; jelly</option></select> <select name="month"><option>Peanut butter &amp; jelly</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html> </html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
click_button webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
click_button
end end
it "should properly handle locating with HTML entities in select values" do it "should properly handle locating with HTML entities in select values" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>Peanut butter &amp; jelly</option></select> <select name="month"><option>Peanut butter &amp; jelly</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html> </html>
HTML HTML
lambda { webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
select "Peanut butter & jelly" select "Peanut butter & jelly"
}.should_not raise_error(Webrat::NotFoundError) click_button
end
it "should not locate based on HTML entities" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<select name="month"><option>Peanut butter &amp; jelly</option></select>
<input type="submit" />
</form>
</html>
HTML
lambda {
select "Peanut butter &amp; jelly"
}.should raise_error(Webrat::NotFoundError)
end end
it "should submit duplicates selected options as a single value" do it "should submit duplicates selected options as a single value" do