Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
More clarification of select option locating behavior.
Browse files Browse the repository at this point in the history
TODO: Ensure the other locators are all matching on text, not HTML
  • Loading branch information
brynary committed Sep 7, 2009
1 parent 00c49a0 commit 2490c24
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/webrat/core/locators/select_option_locator.rb
Expand Up @@ -19,15 +19,15 @@ def locate

field.options.detect do |o|
if @option_text.is_a?(Regexp)
o.element.inner_html =~ @option_text
o.element.inner_text =~ @option_text
else
o.inner_text == @option_text.to_s
end
end
else
option_element = option_elements.detect do |o|
if @option_text.is_a?(Regexp)
o.inner_html =~ @option_text
o.inner_text =~ @option_text
else
o.inner_text == @option_text.to_s
end
Expand Down
90 changes: 68 additions & 22 deletions spec/public/select_spec.rb
Expand Up @@ -168,6 +168,36 @@
click_button
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
with_html <<-HTML
<html>
Expand Down Expand Up @@ -201,31 +231,47 @@
end

it "should properly handle submitting HTML entities in select values" 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")
click_button
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")
click_button
end

it "should properly handle locating with HTML entities in select values" 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 & jelly"
}.should_not raise_error(Webrat::NotFoundError)
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 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

it "should submit duplicates selected options as a single value" do
Expand Down

0 comments on commit 2490c24

Please sign in to comment.