2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2018-01-08 15:23:54 -05:00
|
|
|
|
2010-01-12 17:00:01 -05:00
|
|
|
require 'capybara'
|
|
|
|
|
2009-11-16 16:02:16 -05:00
|
|
|
module Capybara
|
2011-04-11 01:58:42 -04:00
|
|
|
module DSL
|
2012-09-01 12:22:13 -04:00
|
|
|
def self.included(base)
|
2018-07-10 17:18:39 -04:00
|
|
|
warn 'including Capybara::DSL in the global scope is not recommended!' if base == Object
|
2012-09-01 12:22:13 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.extended(base)
|
2018-07-10 17:18:39 -04:00
|
|
|
warn 'extending the main object with Capybara::DSL is not recommended!' if base == TOPLEVEL_BINDING.eval('self')
|
2012-09-01 12:22:13 -04:00
|
|
|
super
|
|
|
|
end
|
2009-11-12 12:09:29 -05:00
|
|
|
|
2011-04-11 01:58:42 -04:00
|
|
|
##
|
|
|
|
#
|
2011-12-29 12:45:58 -05:00
|
|
|
# Shortcut to working in a different session.
|
2011-04-11 01:58:42 -04:00
|
|
|
#
|
2018-10-01 14:58:27 -04:00
|
|
|
def using_session(name_or_session, &block)
|
|
|
|
Capybara.using_session(name_or_session, &block)
|
2011-04-11 01:58:42 -04:00
|
|
|
end
|
2011-01-09 17:47:28 -05:00
|
|
|
|
2011-12-29 12:45:58 -05:00
|
|
|
# Shortcut to using a different wait time.
|
2011-08-30 05:07:58 -04:00
|
|
|
#
|
|
|
|
def using_wait_time(seconds, &block)
|
2016-12-15 12:04:01 -05:00
|
|
|
page.using_wait_time(seconds, &block)
|
2011-08-30 05:07:58 -04:00
|
|
|
end
|
|
|
|
|
2011-04-11 01:58:42 -04:00
|
|
|
##
|
|
|
|
#
|
2011-12-29 12:45:58 -05:00
|
|
|
# Shortcut to accessing the current session.
|
2011-04-11 01:58:42 -04: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 12:09:29 -05:00
|
|
|
|
2011-04-11 01:58:42 -04:00
|
|
|
Session::DSL_METHODS.each do |method|
|
2012-09-09 17:36:45 -04:00
|
|
|
define_method method do |*args, &block|
|
|
|
|
page.send method, *args, &block
|
|
|
|
end
|
2011-04-11 01:58:42 -04:00
|
|
|
end
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
2011-04-11 01:58:42 -04:00
|
|
|
extend(Capybara::DSL)
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|