Permalink
Browse files

fixes #1168

  • Loading branch information...
1 parent 6d4fad6 commit bdf6192eb4e9c1777b5c47b8a284afb7aff606e2 @gurix gurix committed Sep 25, 2013
Showing with 26 additions and 2 deletions.
  1. +1 −0 lib/capybara/query.rb
  2. +1 −1 lib/capybara/selector.rb
  3. +24 −1 spec/rspec/matchers_spec.rb
View
@@ -32,6 +32,7 @@ def label; selector.label or selector.name; end
def description
@description = "#{label} #{locator.inspect}"
@description << " with text #{options[:text].inspect}" if options[:text]
+ @description << " with value #{options[:with].inspect}" if options[:with]
@description
end
View
@@ -103,7 +103,7 @@ def filter(name, options={}, &block)
filter(:checked) { |node, value| not(value ^ node.checked?) }
filter(:unchecked) { |node, value| (value ^ node.checked?) }
filter(:disabled, :default => false) { |node, value| not(value ^ node.disabled?) }
- filter(:with) { |node, with| node.value == with }
+ filter(:with) { |node, with| node.value == with.to_s }
filter(:type) do |node, type|
if ['textarea', 'select'].include?(type)
node.tag_name == type
@@ -519,21 +519,44 @@
end
describe "have_field matcher" do
- let(:html) { '<p><label>Text field<input type="text"/></label></p>' }
+ let(:html) { '<p><label>Text field<input type="text" value="some value"/></label></p>' }
it "gives proper description" do
have_field('Text field').description.should == "have field \"Text field\""
end
+ it "gives proper description for a given value" do
+ have_field('Text field', with: 'some value').description.should == "have field \"Text field\" with value \"some value\""
+ end
+
it "passes if there is such a field" do
html.should have_field('Text field')
end
+ it "passes if there is such a field with value" do
+ html.should have_field('Text field', with: 'some value')
+ end
+
it "fails if there is no such field" do
expect do
html.should have_field('No such Field')
end.to raise_error(/expected to find field "No such Field"/)
end
+
+ it "fails if there is such field but with false value" do
+ expect do
+ html.should have_field('Text field', with: 'false value')
+ end.to raise_error(/expected to find field "Text field"/)
+ end
+
+ it "treats a given value as a string" do
+ class Foo
+ def to_s
+ "some value"
+ end
+ end
+ html.should have_field('Text field', with: Foo.new)
+ end
end
describe "have_checked_field matcher" do

0 comments on commit bdf6192

Please sign in to comment.