Have field matcher

This commit is contained in:
Jonas Nicklas 2011-03-25 09:54:52 +00:00
parent 7df9e80233
commit 414b2d983f
2 changed files with 8 additions and 4 deletions

View File

@ -118,5 +118,9 @@ module Capybara
def have_button(button, options={})
HaveMatcher.new(:button, button, options)
end
def have_field(button, options={})
HaveMatcher.new(:field, button, options)
end
end
end

View File

@ -313,16 +313,16 @@ describe Capybara::RSpecMatchers do
end
describe "have_field matcher" do
let(:html) { '<button>A button</button><button>Another button</button>' }
let(:html) { '<p><label>Text field<input type="text"/></label></p>' }
it "passes if there is such a field" do
html.should have_button('A button')
html.should have_field('Text field')
end
it "fails if there is no such field" do
expect do
html.should have_button('No such Button')
end.to raise_error(/expected button "No such Button"/)
html.should have_field('No such Field')
end.to raise_error(/expected field "No such Field"/)
end
end