Permalink
Browse files

Bug fix for finding a field by name using a regex

Bug fix for when using a regular expression to fill in a field that is
not visible on the page, i.e. css attributes on the element are set to
"display:none;"
  • Loading branch information...
Nick Anderson
Nick Anderson committed Oct 30, 2012
1 parent 004cc24 commit ca8e6c26a48204e9fdb6fc5cd1f82f747c895366
Showing with 20 additions and 1 deletion.
  1. +5 −1 lib/webrat/core/locators/field_named_locator.rb
  2. +15 −0 spec/public/locators/field_named_spec.rb
@@ -11,7 +11,11 @@ def locate

def field_element
field_elements.detect do |field_element|
field_element["name"] == @value.to_s
if @value.is_a?(Regexp)
field_element["name"] =~ @value
else
field_element["name"] == @value.to_s
end
end
end

@@ -0,0 +1,15 @@
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")

describe "field_named" do
it "should work when passed a regular expression for the name" do
with_html <<-HTML
<html>
<form>
<input type="text" name="user_1_input">
</form>
</html>
HTML
result = field_named(/user_\d_input/).element.attributes['name'].value
result.should == "user_1_input"
end
end

0 comments on commit ca8e6c2

Please sign in to comment.