This commit is contained in:
Markus Graf 2013-09-25 15:07:02 +02:00
parent 6d4fad6cdf
commit bdf6192eb4
3 changed files with 26 additions and 2 deletions

View File

@ -32,6 +32,7 @@ module Capybara
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 File

@ -103,7 +103,7 @@ Capybara.add_selector(:field) do
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

View File

@ -519,21 +519,44 @@ describe Capybara::RSpecMatchers do
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