Updated regex for LabelLocator and FieldLabeledLocator to work with labels whose text ends in a non-word character like \? or #
This commit is contained in:
parent
ff42db076f
commit
7c08390bb8
@ -20,7 +20,7 @@ module Webrat
|
||||
|
||||
def matching_label_elements
|
||||
label_elements.select do |label_element|
|
||||
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
||||
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}(\b|\Z)/i
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -12,7 +12,7 @@ module Webrat
|
||||
|
||||
def label_element
|
||||
label_elements.detect do |label_element|
|
||||
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
||||
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}(\b|\Z)/i
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -154,4 +154,19 @@ describe "field_labeled" do
|
||||
with_an_id_of "element_42", :for => "The Label"
|
||||
end
|
||||
|
||||
describe "finding a field whose label ends with an non word character" do
|
||||
using_this_html <<-HTML
|
||||
<html>
|
||||
<form>
|
||||
<label for="element_42">License #</label>
|
||||
<input type="text" id="element_42">
|
||||
</form>
|
||||
</html>
|
||||
HTML
|
||||
|
||||
should_return_a Webrat::TextField, :for => "License #"
|
||||
with_an_id_of "element_42", :for => "License #"
|
||||
should_raise_error_matching /Could not find .* "Other License #"/, :for => "Other License #"
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -72,6 +72,30 @@ describe "select_date" do
|
||||
click_button
|
||||
end
|
||||
|
||||
it "should work when the label ends in a non word character" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
<form action="/appointments" method="post">
|
||||
<label for="appointment_date">date ?</label><br />
|
||||
<select id="appointment_date_1i" name="appointment[date(1i)]">
|
||||
<option value="2003">2003</option>
|
||||
</select>
|
||||
<select id="appointment_date_2i" name="appointment[date(2i)]">
|
||||
<option value="12">December</option>
|
||||
</select>
|
||||
<select id="appointment_date_3i" name="appointment[date(3i)]">
|
||||
<option value="25">25</option>
|
||||
</select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</html>
|
||||
HTML
|
||||
webrat_session.should_receive(:post).with("/appointments",
|
||||
"appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"})
|
||||
select_date Date.parse("December 25, 2003"), :from => "date ?"
|
||||
click_button
|
||||
end
|
||||
|
||||
it "should fail if the specified label is not found" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
|
@ -61,6 +61,37 @@ describe "select_datetime" do
|
||||
click_button
|
||||
end
|
||||
|
||||
it "should work when the label ends in a non word character" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
<form action="/appointments" method="post">
|
||||
<label for="appointment_time">Time ?</label><br />
|
||||
<select id="appointment_time_1i" name="appointment[time(1i)]">
|
||||
<option value="2003">2003</option>
|
||||
</select>
|
||||
<select id="appointment_time_2i" name="appointment[time(2i)]">
|
||||
<option value="12">December</option>
|
||||
</select>
|
||||
<select id="appointment_time_3i" name="appointment[time(3i)]">
|
||||
<option value="25">25</option>
|
||||
</select>
|
||||
<select id="appointment_time_4i" name="appointment[time(4i)]">
|
||||
<option value="09">09</option>
|
||||
</select>
|
||||
: <select id="appointment_time_5i" name="appointment[time(5i)]">
|
||||
<option value="30">30</option>
|
||||
</select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</html>
|
||||
HTML
|
||||
webrat_session.should_receive(:post).with("/appointments",
|
||||
"appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"})
|
||||
select_datetime "December 25, 2003 9:30", :from => "Time ?"
|
||||
click_button
|
||||
end
|
||||
|
||||
|
||||
it "should work when no label is specified" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
|
@ -43,6 +43,27 @@ describe "select_time" do
|
||||
click_button
|
||||
end
|
||||
|
||||
it "should work when the label ends in a non word character" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
<form action="/appointments" method="post">
|
||||
<label for="appointment_time">Time #</label><br />
|
||||
<select id="appointment_time_4i" name="appointment[time(4i)]">
|
||||
<option value="09">09</option>
|
||||
</select>
|
||||
: <select id="appointment_time_5i" name="appointment[time(5i)]">
|
||||
<option value="30">30</option>
|
||||
</select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</html>
|
||||
HTML
|
||||
webrat_session.should_receive(:post).with("/appointments",
|
||||
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
|
||||
select_time "9:30AM", :from => "Time #"
|
||||
click_button
|
||||
end
|
||||
|
||||
it "should work when no label is specified" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
|
Loading…
Reference in New Issue
Block a user