Permalink
Browse files

Merge pull request #70 from nbrookie/master

Searching for a field by name using a regex
  • Loading branch information...
2 parents 004cc24 + ca8e6c2 commit 931c080502d3199637cb3e5ca3c9490bad8be8a9 @indirect indirect committed Oct 31, 2012
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 931c080

Please sign in to comment.