1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Merge remote branch 'lenny/find_by_id_fix'

Conflicts:
	lib/capybara/dsl.rb
	lib/capybara/searchable.rb
	lib/capybara/session.rb
This commit is contained in:
Jonas Nicklas 2010-01-11 23:14:52 +01:00
commit 5c20277dfa
5 changed files with 28 additions and 11 deletions

View file

@ -46,16 +46,7 @@ module Capybara
Capybara.current_session
end
SESSION_METHODS = [
:visit, :current_url, :body, :click_link, :click_button, :drag, :fill_in,
:choose, :has_xpath?, :has_no_xpath?, :has_css?, :has_no_css?,
:check, :uncheck, :attach_file, :select, :source,
:has_content?, :has_no_content?, :within, :within_fieldset, :within_table,
:save_and_open_page, :find, :find_field, :find_link, :find_button,
:field_labeled, :all, :locate, :evaluate_script,
:click, :wait_until
]
SESSION_METHODS.each do |method|
Session::DSL_METHODS.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__+1
def #{method}(*args, &block)
page.#{method}(*args, &block)

View file

@ -18,7 +18,7 @@ module Capybara
end
def find_by_id(id)
find(Xpath.for_css("##{id}"))
find(XPath.for_css("##{id}"))
end
def all(locator, options = {})

View file

@ -4,6 +4,13 @@ module Capybara
class Session
include Searchable
DSL_METHODS = [
:all, :attach_file, :body, :check, :choose, :click, :click_button, :click_link, :current_url, :drag, :evaluate_script,
:field_labeled, :fill_in, :find, :find_button, :find_by_id, :find_field, :find_link, :has_content?, :has_css?,
:has_no_content?, :has_no_css?, :has_no_xpath?, :has_xpath?, :locate, :save_and_open_page, :select, :source, :uncheck,
:visit, :wait_until, :within, :within_fieldset, :within_table
]
attr_reader :mode, :app
def initialize(mode, app)

View file

@ -0,0 +1,18 @@
module FindByIdSpec
shared_examples_for "find_by_id" do
describe '#find_by_id' do
before do
@session.visit('/with_html')
end
it "should find any element by id" do
@session.find_by_id('red').tag_name.should == 'a'
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
end
it "should return nil if no element with id is found" do
@session.find_by_id('nothing_with_this_id').should be_nil
end
end
end
end

View file

@ -46,6 +46,7 @@ shared_examples_for "session" do
it_should_behave_like "find_button"
it_should_behave_like "find_field"
it_should_behave_like "find_link"
it_should_behave_like "find_by_id"
it_should_behave_like "find"
it_should_behave_like "has_content"
it_should_behave_like "has_css"