nimboids-capybara 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. data/History.txt +289 -0
  2. data/README.rdoc +722 -0
  3. data/lib/capybara.rb +252 -0
  4. data/lib/capybara/cucumber.rb +28 -0
  5. data/lib/capybara/driver/base.rb +64 -0
  6. data/lib/capybara/driver/node.rb +74 -0
  7. data/lib/capybara/dsl.rb +168 -0
  8. data/lib/capybara/node/actions.rb +162 -0
  9. data/lib/capybara/node/base.rb +63 -0
  10. data/lib/capybara/node/document.rb +25 -0
  11. data/lib/capybara/node/element.rb +201 -0
  12. data/lib/capybara/node/finders.rb +197 -0
  13. data/lib/capybara/node/matchers.rb +417 -0
  14. data/lib/capybara/node/simple.rb +132 -0
  15. data/lib/capybara/rack_test/browser.rb +121 -0
  16. data/lib/capybara/rack_test/driver.rb +80 -0
  17. data/lib/capybara/rack_test/form.rb +80 -0
  18. data/lib/capybara/rack_test/node.rb +105 -0
  19. data/lib/capybara/rails.rb +17 -0
  20. data/lib/capybara/rspec.rb +26 -0
  21. data/lib/capybara/rspec/features.rb +22 -0
  22. data/lib/capybara/rspec/matchers.rb +154 -0
  23. data/lib/capybara/selector.rb +89 -0
  24. data/lib/capybara/selenium/driver.rb +163 -0
  25. data/lib/capybara/selenium/node.rb +91 -0
  26. data/lib/capybara/server.rb +90 -0
  27. data/lib/capybara/session.rb +321 -0
  28. data/lib/capybara/spec/driver.rb +301 -0
  29. data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
  30. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  31. data/lib/capybara/spec/public/test.js +43 -0
  32. data/lib/capybara/spec/session.rb +154 -0
  33. data/lib/capybara/spec/session/all_spec.rb +78 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +73 -0
  35. data/lib/capybara/spec/session/check_spec.rb +65 -0
  36. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  37. data/lib/capybara/spec/session/click_button_spec.rb +304 -0
  38. data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
  39. data/lib/capybara/spec/session/click_link_spec.rb +119 -0
  40. data/lib/capybara/spec/session/current_host_spec.rb +68 -0
  41. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  42. data/lib/capybara/spec/session/fill_in_spec.rb +125 -0
  43. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  44. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  45. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  46. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  47. data/lib/capybara/spec/session/find_spec.rb +149 -0
  48. data/lib/capybara/spec/session/first_spec.rb +105 -0
  49. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  50. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  51. data/lib/capybara/spec/session/has_css_spec.rb +243 -0
  52. data/lib/capybara/spec/session/has_field_spec.rb +192 -0
  53. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  54. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  55. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  56. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  57. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  58. data/lib/capybara/spec/session/headers.rb +19 -0
  59. data/lib/capybara/spec/session/javascript.rb +289 -0
  60. data/lib/capybara/spec/session/response_code.rb +19 -0
  61. data/lib/capybara/spec/session/select_spec.rb +113 -0
  62. data/lib/capybara/spec/session/text_spec.rb +19 -0
  63. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  64. data/lib/capybara/spec/session/unselect_spec.rb +61 -0
  65. data/lib/capybara/spec/session/within_spec.rb +178 -0
  66. data/lib/capybara/spec/test_app.rb +142 -0
  67. data/lib/capybara/spec/views/buttons.erb +4 -0
  68. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  69. data/lib/capybara/spec/views/form.erb +365 -0
  70. data/lib/capybara/spec/views/frame_one.erb +8 -0
  71. data/lib/capybara/spec/views/frame_two.erb +8 -0
  72. data/lib/capybara/spec/views/header_links.erb +7 -0
  73. data/lib/capybara/spec/views/host_links.erb +12 -0
  74. data/lib/capybara/spec/views/popup_one.erb +8 -0
  75. data/lib/capybara/spec/views/popup_two.erb +8 -0
  76. data/lib/capybara/spec/views/postback.erb +13 -0
  77. data/lib/capybara/spec/views/tables.erb +122 -0
  78. data/lib/capybara/spec/views/with_html.erb +78 -0
  79. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  80. data/lib/capybara/spec/views/with_js.erb +48 -0
  81. data/lib/capybara/spec/views/with_scope.erb +36 -0
  82. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  83. data/lib/capybara/spec/views/within_frames.erb +10 -0
  84. data/lib/capybara/spec/views/within_popups.erb +25 -0
  85. data/lib/capybara/util/save_and_open_page.rb +44 -0
  86. data/lib/capybara/util/timeout.rb +27 -0
  87. data/lib/capybara/version.rb +3 -0
  88. data/spec/basic_node_spec.rb +77 -0
  89. data/spec/capybara_spec.rb +46 -0
  90. data/spec/driver/rack_test_driver_spec.rb +89 -0
  91. data/spec/driver/selenium_driver_spec.rb +50 -0
  92. data/spec/dsl_spec.rb +253 -0
  93. data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
  94. data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
  95. data/spec/rspec/features_spec.rb +45 -0
  96. data/spec/rspec/matchers_spec.rb +495 -0
  97. data/spec/rspec_spec.rb +53 -0
  98. data/spec/save_and_open_page_spec.rb +155 -0
  99. data/spec/server_spec.rb +89 -0
  100. data/spec/session/rack_test_session_spec.rb +55 -0
  101. data/spec/session/selenium_session_spec.rb +26 -0
  102. data/spec/spec_helper.rb +30 -0
  103. data/spec/string_spec.rb +77 -0
  104. data/spec/timeout_spec.rb +28 -0
  105. metadata +346 -0
@@ -0,0 +1,252 @@
1
+ require 'timeout'
2
+ require 'nokogiri'
3
+ require 'xpath'
4
+ module Capybara
5
+ class CapybaraError < StandardError; end
6
+ class DriverNotFoundError < CapybaraError; end
7
+ class FrozenInTime < CapybaraError; end
8
+ class ElementNotFound < CapybaraError; end
9
+ class ExpectationNotMet < ElementNotFound; end
10
+ class FileNotFound < CapybaraError; end
11
+ class UnselectNotAllowed < CapybaraError; end
12
+ class NotSupportedByDriverError < CapybaraError; end
13
+ class TimeoutError < CapybaraError; end
14
+ class LocateHiddenElementError < CapybaraError; end
15
+ class InfiniteRedirectError < TimeoutError; end
16
+
17
+ class << self
18
+ attr_accessor :asset_root, :app_host, :run_server, :default_host
19
+ attr_accessor :server_port, :server_boot_timeout
20
+ attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements, :prefer_visible_elements
21
+ attr_accessor :save_and_open_page_path, :automatic_reload
22
+
23
+ ##
24
+ #
25
+ # Configure Capybara to suit your needs.
26
+ #
27
+ # Capybara.configure do |config|
28
+ # config.run_server = false
29
+ # config.app_host = 'http://www.google.com'
30
+ # end
31
+ #
32
+ # === Configurable options
33
+ #
34
+ # [asset_root = String] Where static assets are located, used by save_and_open_page
35
+ # [app_host = String] The default host to use when giving a relative URL to visit
36
+ # [run_server = Boolean] Whether to start a Rack server for the given Rack app (Default: true)
37
+ # [default_selector = :css/:xpath] Methods which take a selector use the given type by default (Default: CSS)
38
+ # [default_wait_time = Integer] The number of seconds to wait for asynchronous processes to finish (Default: 2)
39
+ # [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: false)
40
+ # [prefer_visible_elements = Boolean] Whether to prefer visible elements over hidden elements (Default: true)
41
+ # [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true)
42
+ # [save_and_open_page_path = String] Where to put pages saved through save_and_open_page (Default: Dir.pwd)
43
+ #
44
+ # === DSL Options
45
+ #
46
+ # when using capybara/dsl, the following options are also available:
47
+ #
48
+ # [default_driver = Symbol] The name of the driver to use by default. (Default: :rack_test)
49
+ # [javascript_driver = Symbol] The name of a driver to use for JavaScript enabled tests. (Default: :selenium)
50
+ #
51
+ def configure
52
+ yield self
53
+ end
54
+
55
+ ##
56
+ #
57
+ # Register a new driver for Capybara.
58
+ #
59
+ # Capybara.register_driver :rack_test do |app|
60
+ # Capybara::Driver::RackTest.new(app)
61
+ # end
62
+ #
63
+ # @param [Symbol] name The name of the new driver
64
+ # @yield [app] This block takes a rack app and returns a Capybara driver
65
+ # @yieldparam [<Rack>] app The rack application that this driver runs agains. May be nil.
66
+ # @yieldreturn [Capybara::Driver::Base] A Capybara driver instance
67
+ #
68
+ def register_driver(name, &block)
69
+ drivers[name] = block
70
+ end
71
+
72
+ ##
73
+ #
74
+ # Add a new selector to Capybara. Selectors can be used by various methods in Capybara
75
+ # to find certain elements on the page in a more convenient way. For example adding a
76
+ # selector to find certain table rows might look like this:
77
+ #
78
+ # Capybara.add_selector(:row) do
79
+ # xpath { |num| ".//tbody/tr[#{num}]" }
80
+ # end
81
+ #
82
+ # This makes it possible to use this selector in a variety of ways:
83
+ #
84
+ # find(:row, 3)
85
+ # page.find('table#myTable').find(:row, 3).text
86
+ # page.find('table#myTable').has_selector?(:row, 3)
87
+ # within(:row, 3) { page.should have_content('$100.000') }
88
+ #
89
+ # It might be convenient to specify that the selector is automatically chosen for certain
90
+ # values. This way you don't have to explicitly specify that you are looking for a row, or
91
+ # an id. Let's say we want Capybara to treat any Symbols sent into methods like find to be
92
+ # treated as though they were element ids. We could achieve this like so:
93
+ #
94
+ # Capybara.add_selector(:id) do
95
+ # xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
96
+ # match { |value| value.is_a?(Symbol) }
97
+ # end
98
+ #
99
+ # Now we can retrieve elements by id like this:
100
+ #
101
+ # find(:post_123)
102
+ #
103
+ # Note that this particular selector already ships with Capybara.
104
+ #
105
+ # @param [Symbol] name The name of the selector to add
106
+ # @yield A block executed in the context of the new {Capybara::Selector}
107
+ #
108
+ def add_selector(name, &block)
109
+ Capybara::Selector.add(name, &block)
110
+ end
111
+
112
+ def drivers
113
+ @drivers ||= {}
114
+ end
115
+
116
+ ##
117
+ #
118
+ # Register a proc that Capybara will call to run the Rack application.
119
+ #
120
+ # Capybara.server do |app, port|
121
+ # require 'rack/handler/mongrel'
122
+ # Rack::Handler::Mongrel.run(app, :Port => port)
123
+ # end
124
+ #
125
+ # By default, Capybara will try to run thin, falling back to webrick.
126
+ #
127
+ # @yield [app, port] This block recieves a rack app and port and should run a Rack handler
128
+ #
129
+ def server(&block)
130
+ if block_given?
131
+ @server = block
132
+ else
133
+ @server
134
+ end
135
+ end
136
+
137
+ ##
138
+ #
139
+ # Wraps the given string, which should contain an HTML document or fragment
140
+ # in a {Capybara::Node::Simple} which exposes all {Capybara::Node::Matchers} and
141
+ # {Capybara::Node::Finders}. This allows you to query any string containing
142
+ # HTML in the exact same way you would query the current document in a Capybara
143
+ # session. For example:
144
+ #
145
+ # node = Capybara.string <<-HTML
146
+ # <ul>
147
+ # <li id="home">Home</li>
148
+ # <li id="projects">Projects</li>
149
+ # </ul>
150
+ # HTML
151
+ #
152
+ # node.find('#projects').text # => 'Projects'
153
+ # node.has_selector?('li#home', :text => 'Home')
154
+ # node.has_selector?(:projects)
155
+ # node.find('ul').find('li').text # => 'Home'
156
+ #
157
+ # @param [String] html An html fragment or document
158
+ # @return [Capybara::Node::Simple] A node which has Capybara's finders and matchers
159
+ #
160
+ def string(html)
161
+ Capybara::Node::Simple.new(html)
162
+ end
163
+
164
+ ##
165
+ #
166
+ # Runs Capybara's default server for the given application and port
167
+ # under most circumstances you should not have to call this method
168
+ # manually.
169
+ #
170
+ # @param [Rack Application] app The rack application to run
171
+ # @param [Fixnum] port The port to run the application on
172
+ #
173
+ def run_default_server(app, port)
174
+ begin
175
+ require 'rack/handler/thin'
176
+ Thin::Logging.silent = true
177
+ Rack::Handler::Thin.run(app, :Port => port)
178
+ rescue LoadError
179
+ require 'rack/handler/webrick'
180
+ Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
181
+ end
182
+ end
183
+
184
+ def deprecate(method, alternate_method)
185
+ warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead"
186
+ end
187
+ end
188
+
189
+ autoload :Server, 'capybara/server'
190
+ autoload :Session, 'capybara/session'
191
+ autoload :Selector, 'capybara/selector'
192
+ autoload :VERSION, 'capybara/version'
193
+
194
+ module Node
195
+ autoload :Base, 'capybara/node/base'
196
+ autoload :Simple, 'capybara/node/simple'
197
+ autoload :Element, 'capybara/node/element'
198
+ autoload :Document, 'capybara/node/document'
199
+ autoload :Finders, 'capybara/node/finders'
200
+ autoload :Matchers, 'capybara/node/matchers'
201
+ autoload :Actions, 'capybara/node/actions'
202
+ end
203
+
204
+ module Driver
205
+ autoload :Base, 'capybara/driver/base'
206
+ autoload :Node, 'capybara/driver/node'
207
+
208
+ class Selenium
209
+ def initialize(*args)
210
+ raise "Capybara::Driver::Selenium has been renamed to Capybara::Selenium::Driver"
211
+ end
212
+ end
213
+
214
+ class RackTest
215
+ def initialize(*args)
216
+ raise "Capybara::Driver::RackTest has been renamed to Capybara::RackTest::Driver"
217
+ end
218
+ end
219
+ end
220
+
221
+ module RackTest
222
+ autoload :Driver, 'capybara/rack_test/driver'
223
+ autoload :Node, 'capybara/rack_test/node'
224
+ autoload :Form, 'capybara/rack_test/form'
225
+ autoload :Browser, 'capybara/rack_test/browser'
226
+ end
227
+
228
+ module Selenium
229
+ autoload :Node, 'capybara/selenium/node'
230
+ autoload :Driver, 'capybara/selenium/driver'
231
+ end
232
+ end
233
+
234
+ Capybara.configure do |config|
235
+ config.run_server = true
236
+ config.server {|app, port| Capybara.run_default_server(app, port)}
237
+ config.server_boot_timeout = 10
238
+ config.default_selector = :css
239
+ config.default_wait_time = 2
240
+ config.ignore_hidden_elements = false
241
+ config.prefer_visible_elements = true
242
+ config.default_host = "http://www.example.com"
243
+ config.automatic_reload = true
244
+ end
245
+
246
+ Capybara.register_driver :rack_test do |app|
247
+ Capybara::RackTest::Driver.new(app)
248
+ end
249
+
250
+ Capybara.register_driver :selenium do |app|
251
+ Capybara::Selenium::Driver.new(app)
252
+ end
@@ -0,0 +1,28 @@
1
+ require 'capybara'
2
+
3
+ require 'capybara/dsl'
4
+ require 'capybara/rspec/matchers'
5
+
6
+ World(Capybara::DSL)
7
+ World(Capybara::RSpecMatchers)
8
+
9
+ After do
10
+ Capybara.reset_sessions!
11
+ end
12
+
13
+ Before '@javascript' do
14
+ Capybara.current_driver = Capybara.javascript_driver
15
+ end
16
+
17
+ Before do |scenario|
18
+ scenario.source_tag_names.each do |tag|
19
+ driver_name = tag.sub(/^@/, '').to_sym
20
+ if Capybara.drivers.has_key?(driver_name)
21
+ Capybara.current_driver = driver_name
22
+ end
23
+ end
24
+ end
25
+
26
+ After do
27
+ Capybara.use_default_driver
28
+ end
@@ -0,0 +1,64 @@
1
+ class Capybara::Driver::Base
2
+ def current_url
3
+ raise NotImplementedError
4
+ end
5
+
6
+ def visit(path)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ def find(query)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def source
15
+ raise NotImplementedError
16
+ end
17
+
18
+ def body
19
+ raise NotImplementedError
20
+ end
21
+
22
+ def execute_script(script)
23
+ raise Capybara::NotSupportedByDriverError
24
+ end
25
+
26
+ def evaluate_script(script)
27
+ raise Capybara::NotSupportedByDriverError
28
+ end
29
+
30
+ def response_headers
31
+ raise Capybara::NotSupportedByDriverError
32
+ end
33
+
34
+ def status_code
35
+ raise Capybara::NotSupportedByDriverError
36
+ end
37
+
38
+ def within_frame(frame_id)
39
+ raise Capybara::NotSupportedByDriverError
40
+ end
41
+
42
+ def within_window(handle)
43
+ raise Capybara::NotSupportedByDriverError
44
+ end
45
+
46
+ def invalid_element_errors
47
+ []
48
+ end
49
+
50
+ def wait?
51
+ false
52
+ end
53
+
54
+ def wait_until(*args)
55
+ end
56
+
57
+ def reset!
58
+ end
59
+
60
+ def has_shortcircuit_timeout?
61
+ false
62
+ end
63
+
64
+ end
@@ -0,0 +1,74 @@
1
+ module Capybara
2
+ module Driver
3
+ class Node
4
+ attr_reader :driver, :native
5
+
6
+ def initialize(driver, native)
7
+ @driver = driver
8
+ @native = native
9
+ end
10
+
11
+ def text
12
+ raise NotImplementedError
13
+ end
14
+
15
+ def [](name)
16
+ raise NotImplementedError
17
+ end
18
+
19
+ def value
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def set(value)
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def select_option
28
+ raise NotImplementedError
29
+ end
30
+
31
+ def unselect_option
32
+ raise NotImplementedError
33
+ end
34
+
35
+ def click
36
+ raise NotImplementedError
37
+ end
38
+
39
+ def drag_to(element)
40
+ raise NotImplementedError
41
+ end
42
+
43
+ def tag_name
44
+ raise NotImplementedError
45
+ end
46
+
47
+ def visible?
48
+ raise NotImplementedError
49
+ end
50
+
51
+ def checked?
52
+ raise NotImplementedError
53
+ end
54
+
55
+ def selected?
56
+ raise NotImplementedError
57
+ end
58
+
59
+ def path
60
+ raise NotSupportedByDriverError
61
+ end
62
+
63
+ def trigger(event)
64
+ raise NotSupportedByDriverError
65
+ end
66
+
67
+ def inspect
68
+ %(#<Capybara::Driver::Node tag="#{tag_name}" path="#{path}">)
69
+ rescue NotSupportedByDriverError
70
+ %(#<Capybara::Driver::Node tag="#{tag_name}">)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,168 @@
1
+ require 'capybara'
2
+
3
+ module Capybara
4
+ def self.included(base)
5
+ base.send(:include, Capybara::DSL)
6
+ warn "`include Capybara` is deprecated please use `include Capybara::DSL` instead."
7
+ end
8
+
9
+ class << self
10
+ attr_writer :default_driver, :current_driver, :javascript_driver, :session_name
11
+
12
+ attr_accessor :app
13
+
14
+ ##
15
+ #
16
+ # @return [Symbol] The name of the driver to use by default
17
+ #
18
+ def default_driver
19
+ @default_driver || :rack_test
20
+ end
21
+
22
+ ##
23
+ #
24
+ # @return [Symbol] The name of the driver currently in use
25
+ #
26
+ def current_driver
27
+ @current_driver || default_driver
28
+ end
29
+ alias_method :mode, :current_driver
30
+
31
+ ##
32
+ #
33
+ # @return [Symbol] The name of the driver used when JavaScript is needed
34
+ #
35
+ def javascript_driver
36
+ @javascript_driver || :selenium
37
+ end
38
+
39
+ ##
40
+ #
41
+ # Use the default driver as the current driver
42
+ #
43
+ def use_default_driver
44
+ @current_driver = nil
45
+ end
46
+
47
+ ##
48
+ #
49
+ # Yield a block using a specific driver
50
+ #
51
+ def using_driver(driver)
52
+ previous_driver = Capybara.current_driver
53
+ Capybara.current_driver = driver
54
+ yield
55
+ ensure
56
+ @current_driver = previous_driver
57
+ end
58
+
59
+ ##
60
+ #
61
+ # Yield a block using a specific wait time
62
+ #
63
+ def using_wait_time(seconds)
64
+ previous_wait_time = Capybara.default_wait_time
65
+ Capybara.default_wait_time = seconds
66
+ yield
67
+ ensure
68
+ Capybara.default_wait_time = previous_wait_time
69
+ end
70
+
71
+ ##
72
+ #
73
+ # The current Capybara::Session base on what is set as Capybara.app and Capybara.current_driver
74
+ #
75
+ # @return [Capybara::Session] The currently used session
76
+ #
77
+ def current_session
78
+ session_pool["#{current_driver}:#{session_name}:#{app.object_id}"] ||= Capybara::Session.new(current_driver, app)
79
+ end
80
+
81
+ ##
82
+ #
83
+ # Reset sessions, cleaning out the pool of sessions. This will remove any session information such
84
+ # as cookies.
85
+ #
86
+ def reset_sessions!
87
+ session_pool.each { |mode, session| session.reset! }
88
+ end
89
+ alias_method :reset!, :reset_sessions!
90
+
91
+ ##
92
+ #
93
+ # The current session name.
94
+ #
95
+ # @return [Symbol] The name of the currently used session.
96
+ #
97
+ def session_name
98
+ @session_name ||= :default
99
+ end
100
+
101
+ ##
102
+ #
103
+ # Yield a block using a specific session name.
104
+ #
105
+ def using_session(name)
106
+ self.session_name = name
107
+ yield
108
+ ensure
109
+ self.session_name = :default
110
+ end
111
+
112
+ private
113
+
114
+ def session_pool
115
+ @session_pool ||= {}
116
+ end
117
+ end
118
+
119
+ module DSL
120
+
121
+ ##
122
+ #
123
+ # Shortcut to working in a different session. This is useful when Capybara is included
124
+ # in a class or module.
125
+ #
126
+ def using_session(name, &block)
127
+ Capybara.using_session(name, &block)
128
+ end
129
+
130
+ ##
131
+ #
132
+ # Shortcut to working in a different session. This is useful when Capybara is included
133
+ # in a class or module.
134
+ #
135
+ def using_wait_time(seconds, &block)
136
+ Capybara.using_wait_time(seconds, &block)
137
+ end
138
+
139
+ ##
140
+ #
141
+ # Shortcut to accessing the current session. This is useful when Capybara is included in a
142
+ # class or module.
143
+ #
144
+ # class MyClass
145
+ # include Capybara::DSL
146
+ #
147
+ # def has_header?
148
+ # page.has_css?('h1')
149
+ # end
150
+ # end
151
+ #
152
+ # @return [Capybara::Session] The current session object
153
+ #
154
+ def page
155
+ Capybara.current_session
156
+ end
157
+
158
+ Session::DSL_METHODS.each do |method|
159
+ class_eval <<-RUBY, __FILE__, __LINE__+1
160
+ def #{method}(*args, &block)
161
+ page.#{method}(*args, &block)
162
+ end
163
+ RUBY
164
+ end
165
+ end
166
+
167
+ extend(Capybara::DSL)
168
+ end