teamcapybara--capybara/lib/capybara/dsl.rb

60 lines
1.2 KiB
Ruby
Raw Normal View History

require 'capybara'
2009-11-16 16:02:16 -05:00
module Capybara
module DSL
def self.included(base)
warn "including Capybara::DSL in the global scope is not recommended!" if base == Object
super
end
def self.extended(base)
warn "extending the main object with Capybara::DSL is not recommended!" if base == TOPLEVEL_BINDING.eval("self")
super
end
2009-11-12 12:09:29 -05:00
##
#
2011-12-29 12:45:58 -05:00
# Shortcut to working in a different session.
#
def using_session(name, &block)
Capybara.using_session(name, &block)
end
##
#
2011-12-29 12:45:58 -05:00
# Shortcut to using a different wait time.
#
def using_wait_time(seconds, &block)
Capybara.using_wait_time(seconds, &block)
end
##
#
2011-12-29 12:45:58 -05:00
# Shortcut to accessing the current session.
#
# class MyClass
# include Capybara::DSL
#
# def has_header?
# page.has_css?('h1')
# end
# end
#
# @return [Capybara::Session] The current session object
#
def page
Capybara.current_session
end
2009-11-12 12:09:29 -05:00
Session::DSL_METHODS.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__+1
def #{method}(*args, &block)
page.#{method}(*args, &block)
end
RUBY
end
2009-11-12 11:51:31 -05:00
end
extend(Capybara::DSL)
2009-11-12 11:51:31 -05:00
end