2016-03-07 16:52:19 -08:00
|
|
|
# frozen_string_literal: true
|
2010-01-12 23:00:01 +01:00
|
|
|
require 'capybara'
|
|
|
|
|
2009-11-16 22:02:16 +01:00
|
|
|
module Capybara
|
2011-04-11 06:58:42 +01:00
|
|
|
module DSL
|
2012-09-01 18:22:13 +02:00
|
|
|
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 18:09:29 +01:00
|
|
|
|
2011-04-11 06:58:42 +01:00
|
|
|
##
|
|
|
|
#
|
2011-12-29 18:45:58 +01:00
|
|
|
# Shortcut to working in a different session.
|
2011-04-11 06:58:42 +01:00
|
|
|
#
|
|
|
|
def using_session(name, &block)
|
|
|
|
Capybara.using_session(name, &block)
|
|
|
|
end
|
2011-01-09 17:47:28 -05:00
|
|
|
|
2011-12-29 18:45:58 +01:00
|
|
|
# Shortcut to using a different wait time.
|
2011-08-30 11:07:58 +02:00
|
|
|
#
|
|
|
|
def using_wait_time(seconds, &block)
|
2016-12-15 09:04:01 -08:00
|
|
|
page.using_wait_time(seconds, &block)
|
2011-08-30 11:07:58 +02:00
|
|
|
end
|
|
|
|
|
2011-04-11 06:58:42 +01:00
|
|
|
##
|
|
|
|
#
|
2011-12-29 18:45:58 +01:00
|
|
|
# Shortcut to accessing the current session.
|
2011-04-11 06:58:42 +01:00
|
|
|
#
|
|
|
|
# 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 18:09:29 +01:00
|
|
|
|
2011-04-11 06:58:42 +01:00
|
|
|
Session::DSL_METHODS.each do |method|
|
2012-09-09 23:36:45 +02:00
|
|
|
define_method method do |*args, &block|
|
|
|
|
page.send method, *args, &block
|
|
|
|
end
|
2011-04-11 06:58:42 +01:00
|
|
|
end
|
2009-11-12 17:51:31 +01:00
|
|
|
end
|
|
|
|
|
2011-04-11 06:58:42 +01:00
|
|
|
extend(Capybara::DSL)
|
2009-11-12 17:51:31 +01:00
|
|
|
end
|