capybara 0.4.1.2 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/History.txt +46 -0
  2. data/README.rdoc +211 -64
  3. data/lib/capybara.rb +31 -15
  4. data/lib/capybara/cucumber.rb +12 -16
  5. data/lib/capybara/dsl.rb +65 -28
  6. data/lib/capybara/node/actions.rb +7 -5
  7. data/lib/capybara/node/document.rb +8 -0
  8. data/lib/capybara/node/finders.rb +11 -7
  9. data/lib/capybara/node/matchers.rb +32 -6
  10. data/lib/capybara/node/simple.rb +20 -0
  11. data/lib/capybara/rack_test/browser.rb +115 -0
  12. data/lib/capybara/rack_test/driver.rb +77 -0
  13. data/lib/capybara/rack_test/form.rb +80 -0
  14. data/lib/capybara/rack_test/node.rb +101 -0
  15. data/lib/capybara/rspec.rb +11 -3
  16. data/lib/capybara/rspec/features.rb +22 -0
  17. data/lib/capybara/rspec/matchers.rb +146 -0
  18. data/lib/capybara/selector.rb +27 -8
  19. data/lib/capybara/selenium/driver.rb +148 -0
  20. data/lib/capybara/selenium/node.rb +91 -0
  21. data/lib/capybara/session.rb +42 -15
  22. data/lib/capybara/spec/driver.rb +55 -1
  23. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  24. data/lib/capybara/spec/public/test.js +7 -2
  25. data/lib/capybara/spec/session.rb +51 -7
  26. data/lib/capybara/spec/session/attach_file_spec.rb +9 -6
  27. data/lib/capybara/spec/session/click_button_spec.rb +35 -0
  28. data/lib/capybara/spec/session/current_host_spec.rb +62 -0
  29. data/lib/capybara/spec/session/fill_in_spec.rb +6 -0
  30. data/lib/capybara/spec/session/find_spec.rb +23 -1
  31. data/lib/capybara/spec/session/first_spec.rb +39 -6
  32. data/lib/capybara/spec/session/has_css_spec.rb +30 -0
  33. data/lib/capybara/spec/session/has_field_spec.rb +47 -11
  34. data/lib/capybara/spec/session/javascript.rb +0 -1
  35. data/lib/capybara/spec/session/text_spec.rb +19 -0
  36. data/lib/capybara/spec/test_app.rb +9 -0
  37. data/lib/capybara/spec/views/form.erb +8 -3
  38. data/lib/capybara/spec/views/header_links.erb +7 -0
  39. data/lib/capybara/spec/views/host_links.erb +12 -0
  40. data/lib/capybara/spec/views/with_html.erb +6 -2
  41. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  42. data/lib/capybara/spec/views/with_js.erb +4 -0
  43. data/lib/capybara/util/save_and_open_page.rb +7 -3
  44. data/lib/capybara/util/timeout.rb +2 -2
  45. data/lib/capybara/version.rb +1 -1
  46. data/spec/capybara_spec.rb +1 -1
  47. data/spec/driver/rack_test_driver_spec.rb +24 -2
  48. data/spec/driver/selenium_driver_spec.rb +2 -1
  49. data/spec/dsl_spec.rb +56 -4
  50. data/spec/rspec/features_spec.rb +45 -0
  51. data/spec/rspec/matchers_spec.rb +451 -0
  52. data/spec/rspec_spec.rb +9 -2
  53. data/spec/save_and_open_page_spec.rb +9 -13
  54. data/spec/server_spec.rb +4 -0
  55. data/spec/session/rack_test_session_spec.rb +2 -2
  56. data/spec/session/selenium_session_spec.rb +1 -1
  57. data/spec/spec_helper.rb +0 -14
  58. data/spec/string_spec.rb +1 -1
  59. metadata +60 -69
  60. data/lib/capybara/driver/celerity_driver.rb +0 -164
  61. data/lib/capybara/driver/culerity_driver.rb +0 -26
  62. data/lib/capybara/driver/rack_test_driver.rb +0 -303
  63. data/lib/capybara/driver/selenium_driver.rb +0 -161
  64. data/spec/driver/celerity_driver_spec.rb +0 -13
  65. data/spec/driver/culerity_driver_spec.rb +0 -14
  66. data/spec/driver/remote_culerity_driver_spec.rb +0 -22
  67. data/spec/driver/remote_selenium_driver_spec.rb +0 -16
  68. data/spec/session/celerity_session_spec.rb +0 -24
  69. data/spec/session/culerity_session_spec.rb +0 -26
@@ -1,3 +1,49 @@
1
+ # Version 1.0.0
2
+
3
+ Release date:
4
+
5
+ ### Added
6
+
7
+ * Added DSL for acceptance tests, inspired by Luismi Cavallé's Steak [Luismi Cavalle and Jonas Nicklas]
8
+ * Selenium driver automatically waits for AJAX requests to finish [mgiambalvo, Nicklas Ramhöj and Jonas Nicklas]
9
+ * Support for switching between multiple named sessions [Tristan Dunn]
10
+ * failure_message can be specified for Selectors [Jonas Nicklas]
11
+ * RSpec matchers [David Chelimsky and Jonas Nicklas]
12
+ * Added save_page to save tempfile without opening in browser [Jeff Kreeftmeijer]
13
+ * Cucumber now switches automatically to a registered driver if the tag matches the name [Jonas Nicklas]
14
+ * Added Session#text [Jonas Nicklas and Scott Cytacki]
15
+ * Added Session#html as an alias for Session#body [Jo Liss]
16
+ * Added Session#current_host method [Jonas Nicklas]
17
+ * Buttons can now be clicked by title [Javier Martin]
18
+ * :headers option for RackTest driver to set custom HTTP headers [Jonas Nicklas]
19
+
20
+ ### Removed
21
+
22
+ * Culerity and Celerity drivers have been removed and split into separate gems [Gabriel Sobrinho]
23
+
24
+ ### Deprecated
25
+
26
+ * `include Capybara` has been deprecated in favour of `include Capybara::DSL` [Jonas Nicklas]
27
+
28
+ ### Changed
29
+
30
+ * Rack test driver class has been renamed from Capybara::Driver::RackTest to Capybara::RackTest::Driver [Jonas Nicklas]
31
+ * Selenium driver class has been renamed from Capybara::Driver::Selenium to Capybara::Selenium::Driver [Jonas Nicklas]
32
+ * Capybara now prefers visible elements over hidden elements, disable by setting Capybara.prefer_visible_elements = false [Jonas Nicklas and Nicklas Ramhöj]
33
+ * For RSpec, :type => :request is now supported (and preferred over :acceptance) [Jo Liss]
34
+ * Selenium driver tried to wait for AJAX requests to finish before proceeding [Jonas Nicklas and Nicklas Ramhöj]
35
+ * Session no longer uses method missing, uses explicit delegates instead [Jonas Nicklas]
36
+
37
+ ### Fixed
38
+
39
+ * The Rack::Test driver now respects maxlength on text fields [Guilherme Carvalho]
40
+ * Allow for more than one save_and_open_page call per second [Jo Liss]
41
+ * Automatically convert options to :count, :minimum, :maximum, etc. to integers [Keith Marcum]
42
+ * Rack::Test driver honours maxlength on input fields [Guilherme Carvalho]
43
+ * Rack::Test now works as expected with domains and subdomains [Jonas Nicklas]
44
+ * Session is reset more thoroughly between tests. [Jonas Nicklas]
45
+ * Raise error when uploading non-existant file [Jonas Nicklas]
46
+
1
47
  # Version 0.4.1
2
48
 
3
49
  Release date: 2011-01-21
@@ -7,12 +7,11 @@
7
7
  Capybara aims to simplify the process of integration testing Rack applications,
8
8
  such as Rails, Sinatra or Merb. Capybara simulates how a real user would
9
9
  interact with a web application. It is agnostic about the driver running your
10
- tests and currently comes bundled with rack-test, Culerity, Celerity and Selenium
11
- support built in. env.js support is available as the
12
- {capybara-envjs gem}[http://github.com/smparkes/capybara-envjs].
10
+ tests and currently comes with Rack::Test and Selenium support built in.
11
+ HtmlUnit and env.js are supported through external gems.
13
12
 
14
- Online documentation is availbable
15
- {at rdoc.info}[http://rdoc.info/projects/jnicklas/capybara].
13
+ A complete reference is available at
14
+ {at rubydoc.info}[http://rubydoc.info/github/jnicklas/capybara/master].
16
15
 
17
16
  == Install:
18
17
 
@@ -36,6 +35,7 @@ you make.
36
35
 
37
36
  Capybara uses bundler in development. To set up a development environment, simply do:
38
37
 
38
+ git submodule update --init
39
39
  gem install bundler --pre
40
40
  bundle install
41
41
 
@@ -70,8 +70,8 @@ driver that supports JavaScript, Capybara makes this easy: simply tag the
70
70
  scenario (or feature) with <tt>@javascript</tt>:
71
71
 
72
72
  @javascript
73
- Scenario: do something AJAXy
74
- When I click the AJAX link
73
+ Scenario: do something Ajaxy
74
+ When I click the Ajax link
75
75
  ...
76
76
 
77
77
  You can change which driver Capybara uses for JavaScript:
@@ -83,14 +83,18 @@ There are also explicit <tt>@selenium</tt>, <tt>@culerity</tt> and
83
83
 
84
84
  == Using Capybara with RSpec
85
85
 
86
- If you prefer RSpec to using Cucumber, you can use the built in RSpec support:
86
+ If you prefer RSpec to using Cucumber, you can use the built in RSpec support
87
+ by adding the following line (typically to your <tt>spec_helper.rb</tt> file):
87
88
 
88
89
  require 'capybara/rspec'
89
- Capybara.app = MyRackApp
90
90
 
91
91
  You can now use it in your examples:
92
92
 
93
- describe "the signup process", :type => :acceptance do
93
+ describe "the signup process", :type => :request do
94
+ before :each do
95
+ User.make(:email => 'user@example.com', :password => 'caplin')
96
+ end
97
+
94
98
  it "signs me in" do
95
99
  within("#session") do
96
100
  fill_in 'Login', :with => 'user@example.com'
@@ -100,8 +104,16 @@ You can now use it in your examples:
100
104
  end
101
105
  end
102
106
 
103
- Capybara is only included for examples which have the type
104
- <tt>:acceptance</tt>.
107
+ Capybara is only included for examples with <tt>:type => :request</tt> (or
108
+ <tt>:acceptance</tt> for compatibility).
109
+
110
+ If you use the <tt>rspec-rails</tt> gem, <tt>:type => :request</tt> is
111
+ automatically set on all files under <tt>spec/requests</tt>. Essentially, these
112
+ are Capybara-enhanced Rails request specs, so it's a good idea to place your
113
+ Capybara specs here because within request specs you gain a few additional
114
+ features, such as the ability to refer to named route helpers. If you do not
115
+ need these, then you may simply use <tt>spec/acceptance</tt> and you will still
116
+ get access to Capybara methods.
105
117
 
106
118
  RSpec's metadata feature can be used to switch to a different driver. Use
107
119
  <tt>:js => true</tt> to switch to the javascript driver, or provide a
@@ -112,46 +124,146 @@ RSpec's metadata feature can be used to switch to a different driver. Use
112
124
  it 'will switch to one specific driver', :driver => :celerity
113
125
  end
114
126
 
127
+ Capybara also comes with a built in DSL for creating descriptive acceptance tests:
128
+
129
+ feature "Signing up" do
130
+ background do
131
+ User.make(:email => 'user@example.com', :password => 'caplin')
132
+ end
133
+
134
+ scenario "Signing in with correct credentials" do
135
+ within("#session") do
136
+ fill_in 'Login', :with => 'user@example.com'
137
+ fill_in 'Password', :with => 'caplin'
138
+ end
139
+ click_link 'Sign in'
140
+ end
141
+ end
142
+
143
+ Essentially, this is just a shortcut for making a request spec, where
144
+ <tt>feature</tt> is a shortcut for <tt>describe ..., :type => :request</tt>,
145
+ <tt>background</tt> is an alias for <tt>before :each</tt>, and <tt>scenario</tt>
146
+ is an alias for <tt>it</tt>/<tt>example</tt>. Again, you are encouraged to place
147
+ these within <tt>spec/requests</tt> rather than <tt>spec/acceptance</tt>.
148
+
115
149
  Note that Capybara's built in RSpec support only works with RSpec 2.0 or later.
116
150
  You'll need to roll your own for earlier versions of RSpec.
117
151
 
118
- == Default and current driver
152
+ == Using Capybara with Test::Unit
153
+
154
+ To use Capybara with Test::Unit, include the DSL (<tt>include Capybara</tt> up
155
+ until version 0.4.x, <tt>include Capybara::DSL</tt> for newer versions) in
156
+ whatever test class you are using. For example, if your classes derive from
157
+ <tt>ActionDispatch::IntegrationTest</tt>, use
158
+
159
+ class ActionDispatch::IntegrationTest
160
+ include Capybara::DSL
161
+ end
162
+
163
+ Test::Unit does not support selecting the driver through test metadata, but you
164
+ can switch the driver for specific classes using the <tt>setup</tt> and
165
+ <tt>teardown</tt> methods. See the section "Selecting the Driver".
166
+
167
+ == Using Capybara with Ruby on Rails
119
168
 
120
- You can set up a default driver for your features. For example if you'd prefer
121
- to run Selenium, you could do:
169
+ If you are using the Rails framework, add this line to automatically configure
170
+ Capybara to test against your Rails application:
122
171
 
123
172
  require 'capybara/rails'
124
- require 'capybara/cucumber'
173
+
174
+ == Using Capybara with Rack
175
+
176
+ If you're using Capybara with a non-Rails Rack application, set
177
+ <tt>Capybara.app</tt> to your application class:
178
+
179
+ Capybara.app = MyRackApp
180
+
181
+ == Drivers
182
+
183
+ Capybara uses the same DSL to drive a variety of browser and headless drivers.
184
+
185
+ === Selecting the Driver
186
+
187
+ By default, Capybara uses the <tt>:rack_test</tt> driver, which is fast but does not
188
+ support JavaScript. You can set up a different default driver for your
189
+ features. For example if you'd prefer to run everything in Selenium, you could
190
+ do:
191
+
125
192
  Capybara.default_driver = :selenium
126
193
 
127
- You can change the driver temporarily:
194
+ However, if you are using RSpec or Cucumber, you may instead want to consider
195
+ leaving the faster <tt>:rack_test</tt> as the +default_driver+, and marking only those
196
+ tests that require a JavaScript-capable driver using <tt>:js => true</tt> or
197
+ <tt>@javascript</tt>, respectively. By default, JavaScript tests are run using the
198
+ <tt>:selenium</tt> driver. You can change this by setting
199
+ <tt>Capybara.javascript_driver</tt>.
200
+
201
+ You can also change the driver temporarily (typically in the Before/setup and
202
+ After/teardown blocks):
203
+
204
+ Capybara.current_driver = :culerity # temporarily select different driver
205
+ ... tests ...
206
+ Capybara.use_default_driver # switch back to default driver
207
+
208
+ Note that switching the driver creates a new session, so you may not be able to
209
+ switch in the middle of a test.
210
+
211
+ === RackTest
212
+
213
+ RackTest is Capybara's default driver. It is written in pure Ruby and does not
214
+ have any support for executing JavaScript. Since the RackTest driver works
215
+ directly agains the Rack interface, it does not need any server to be started,
216
+ it can work directly work against any Rack app. This means that if your
217
+ application is not a Rack application (Rails, Sinatra and most other Ruby
218
+ frameworks are Rack applications) then you cannot use this driver. You cannot
219
+ use the RackTest driver to test a remote application.
220
+ {capybara-mechanize}[https://github.com/jeroenvandijk/capybara-mechanize]
221
+ intends to provide a similar driver which works against remote servers, it is a
222
+ separate project.
223
+
224
+ RackTest can be configured with a set of headers like this:
225
+
226
+ Capybara.register_driver :rack_test do |app|
227
+ Capybara::RackTest::Driver.new(app, :browser => :chrome)
228
+ end
229
+
230
+ See the section on adding and configuring drivers.
128
231
 
129
- Capybara.current_driver = :culerity
130
- Capybara.use_default_driver
232
+ === Selenium
131
233
 
132
- You can do this in Before and After blocks to temporarily switch to a different
133
- driver. Note that switching driver creates a new session, so you may not be able
134
- to switch in the middle of a Scenario.
234
+ At the moment, Capybara supports {Selenium 2.0
235
+ (Webdriver)}[http://seleniumhq.org/docs/01_introducing_selenium.html#selenium-2-aka-selenium-webdriver],
236
+ *not* Selenium RC. Provided Firefox is installed, everything is set up for you,
237
+ and you should be able to start using Selenium right away.
135
238
 
136
- == Selenium
239
+ By default Capybara tries to synchronize Ajax requests, so it will wait for
240
+ Ajax requests to finish after you've interacted with the page. You can switch
241
+ off this behaviour by setting the driver option <tt>:resynchronize</tt> to
242
+ <tt>false</tt>. See the section on configuring drivers.
137
243
 
138
- At the moment, Capybara supports Webdriver, also called Selenium 2.0, *not*
139
- Selenium RC. Provided Firefox is installed, everything is set up for you, and
140
- you should be able to start using Selenium right away.
244
+ Note: Selenium does not support transactional fixtures; see the section
245
+ "Transactional Fixtures" below.
141
246
 
142
- == Celerity
247
+ === HtmlUnit
143
248
 
144
- Celerity only runs on JRuby, so you'll need to install the celerity gem under
145
- JRuby:
249
+ There are three different drivers, maintained as external gems, that you can
250
+ use to drive {HtmlUnit}[http://htmlunit.sourceforge.net/]:
146
251
 
147
- jruby -S gem install celerity
252
+ * {Akephalos}[https://github.com/bernerdschaefer/akephalos] might be the best
253
+ HtmlUnit driver right now.
148
254
 
149
- == Culerity
255
+ * {Celerity}[https://github.com/sobrinho/capybara-celerity] only runs on JRuby,
256
+ so you'll need to install the celerity gem under JRuby: <tt>jruby -S gem
257
+ install celerity</tt>
150
258
 
151
- Install celerity as noted above, make sure JRuby is in your path. Note that
152
- Culerity doesn't seem to be working under Ruby 1.9 at the moment.
259
+ * {Culerity}[https://github.com/sobrinho/capybara-culerity]: Install celerity
260
+ as noted above, and make sure that JRuby is in your path. Note that Culerity
261
+ does not seem to be working under Ruby 1.9 at the moment.
153
262
 
154
- == env.js
263
+ Note: HtmlUnit does not support transactional fixtures; see the section
264
+ "Transactional Fixtures" below.
265
+
266
+ === env.js
155
267
 
156
268
  The {capybara-envjs driver}[http://github.com/smparkes/capybara-envjs]
157
269
  uses the envjs gem ({GitHub}[http://github.com/smparkes/env-js],
@@ -163,17 +275,22 @@ JavaScript outside the browser. The driver is installed by installing the capyba
163
275
  More info about the driver and env.js are available through the links above. The envjs gem only supports
164
276
  Ruby 1.8.7 at this time.
165
277
 
166
- == The DSL
278
+ Note: Envjs does not support transactional fixtures; see the section
279
+ "Transactional Fixtures" below.
167
280
 
168
- Capybara's DSL is inspired by Webrat. While backwards compatibility is retained
169
- in a lot of cases, there are certain important differences.
281
+ == The DSL
170
282
 
171
- Unlike in Webrat, all searches in Capybara are *case sensitive*. This is because
172
- Capybara heavily uses XPath, which doesn't support case insensitivity.
283
+ Capybara's DSL (domain-specific language) is inspired by Webrat. While
284
+ backwards compatibility is retained in a lot of cases, there are certain
285
+ important differences. Unlike in Webrat, all searches in Capybara are *case
286
+ sensitive*. This is because Capybara heavily uses XPath, which doesn't support
287
+ case insensitivity.
173
288
 
174
289
  === Navigating
175
290
 
176
- You can use the <tt>visit</tt> method to navigate to other pages:
291
+ You can use the
292
+ <tt>{visit}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#visit-instance_method]</tt>
293
+ method to navigate to other pages:
177
294
 
178
295
  visit('/projects')
179
296
  visit(post_comments_path(post))
@@ -181,29 +298,34 @@ You can use the <tt>visit</tt> method to navigate to other pages:
181
298
  The visit method only takes a single parameter, the request method is *always*
182
299
  GET.
183
300
 
184
- You can get the current path of the browsing session for test assertions:
301
+ You can get the {current
302
+ path}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#current_path-instance_method]
303
+ of the browsing session for test assertions:
185
304
 
186
305
  current_path.should == post_comments_path(post)
187
306
 
188
307
  === Clicking links and buttons
189
308
 
309
+ <em>Full reference: {Capybara::Node::Actions}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions]</em>
310
+
190
311
  You can interact with the webapp by following links and buttons. Capybara
191
312
  automatically follows any redirects, and submits forms associated with buttons.
192
313
 
193
314
  click_link('id-of-link')
194
315
  click_link('Link Text')
195
316
  click_button('Save')
196
- click_link_or_button('Link Text')
197
- click_link_or_button('Button Value')
317
+ click_on('Link Text') # clicks on either links or buttons
318
+ click_on('Button Value')
198
319
 
199
320
  === Interacting with forms
200
321
 
201
- Forms are everywhere in webapps, there are a number of tools for interacting
202
- with the various form elements:
322
+ <em>Full reference: {Capybara::Node::Actions}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions]</em>
323
+
324
+ There are a number of tools for interacting with form elements:
203
325
 
204
326
  fill_in('First Name', :with => 'John')
205
327
  fill_in('Password', :with => 'Seekrit')
206
- fill_in('Description', :with => 'Really Long Text')
328
+ fill_in('Description', :with => 'Really Long Text...')
207
329
  choose('A Radio Button')
208
330
  check('A Checkbox')
209
331
  uncheck('A Checkbox')
@@ -212,6 +334,8 @@ with the various form elements:
212
334
 
213
335
  === Querying
214
336
 
337
+ <em>Full reference: {Capybara::Node::Matchers}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers]</em>
338
+
215
339
  Capybara has a rich set of options for querying the page for the existence of
216
340
  certain elements, and working with and manipulating those elements.
217
341
 
@@ -223,7 +347,7 @@ certain elements, and working with and manipulating those elements.
223
347
  page.has_css?('table tr.foo')
224
348
  page.has_content?('foo')
225
349
 
226
- You can these use with RSpec's magic matchers:
350
+ You can use these with RSpec's magic matchers:
227
351
 
228
352
  page.should have_selector('table tr')
229
353
  page.should have_selector(:xpath, '//table/tr')
@@ -238,8 +362,16 @@ Note that <tt>page.should have_no_xpath</tt> is preferred over
238
362
  <tt>page.should_not have_xpath</tt>. Read the section on asynchronous JavaScript
239
363
  for an explanation.
240
364
 
365
+ If all else fails, you can also use the
366
+ <tt>{page.html}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#html-instance_method]</tt>
367
+ method to test against the raw HTML:
368
+
369
+ page.html.should match /<span>.../i
370
+
241
371
  === Finding
242
372
 
373
+ <em>Full reference: {Capybara::Node::Finders}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders]</em>
374
+
243
375
  You can also find specific elements, in order to manipulate them:
244
376
 
245
377
  find_field('First Name').value
@@ -251,7 +383,7 @@ You can also find specific elements, in order to manipulate them:
251
383
  all('a').each { |a| a[:href] }
252
384
 
253
385
  Note that <tt>find</tt> will wait for an element to appear on the page, as explained in the
254
- AJAX section. If the element does not appear it will raise an error.
386
+ Ajax section. If the element does not appear it will raise an error.
255
387
 
256
388
  These elements all have all the Capybara DSL methods available, so you can restrict them
257
389
  to specific parts of the page:
@@ -263,8 +395,9 @@ to specific parts of the page:
263
395
 
264
396
  Capybara makes it possible to restrict certain actions, such as interacting with
265
397
  forms or clicking links and buttons, to within a specific area of the page. For
266
- this purpose you can use the generic <tt>within</tt> method. Optionally you can
267
- specify which kind of selector to use.
398
+ this purpose you can use the generic
399
+ <tt>{within}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#within-instance_method]</tt>
400
+ method. Optionally you can specify which kind of selector to use.
268
401
 
269
402
  within("li#employee") do
270
403
  fill_in 'Name', :with => 'Jimmy'
@@ -304,7 +437,18 @@ look at it:
304
437
 
305
438
  save_and_open_page
306
439
 
307
- == Asynchronous JavaScript (AJAX and friends)
440
+ == Transactional fixtures
441
+
442
+ Transactional fixtures only work in the default Rack::Test driver, but not for
443
+ other drivers like Selenium. Cucumber takes care of this automatically, but
444
+ with Test::Unit or RSpec, you may have to use the
445
+ {database_cleaner}[https://github.com/bmabey/database_cleaner] gem. See {this
446
+ explanation}[https://groups.google.com/d/msg/ruby-capybara/JI6JrirL9gM/R6YiXj4gi_UJ]
447
+ (and code for {solution
448
+ 2}[http://opinionated-programmer.com/2011/02/capybara-and-selenium-with-rspec-and-rails-3/#comment-220]
449
+ and {solution 3}[http://pastie.org/1745020]) for details.
450
+
451
+ == Asynchronous JavaScript (Ajax and friends)
308
452
 
309
453
  When working with asynchronous JavaScript, you might come across situations
310
454
  where you are attempting to interact with an element which is not yet present
@@ -318,7 +462,7 @@ When issuing instructions to the DSL such as:
318
462
  page.should have_content('baz')
319
463
 
320
464
  If clicking on the *foo* link causes triggers an asynchronous process, such as
321
- an AJAX request, which, when complete will add the *bar* link to the page,
465
+ an Ajax request, which, when complete will add the *bar* link to the page,
322
466
  clicking on the *bar* link would be expeced to fail, since that link doesn't
323
467
  exist yet. However Capybara is smart enought to retry finding the link for a
324
468
  brief period of time before giving up and throwing an error. The same is true of
@@ -339,10 +483,10 @@ asynchronous process has not yet removed the element from the page, it would
339
483
  therefore fail, even though the code might be working correctly. The latter
340
484
  correctly waits for the element to disappear from the page.
341
485
 
342
- == Using the DSL outside cucumber
486
+ == Using the DSL in unsupported testing frameworks
487
+
488
+ You can mix the DSL into any context by including +Capybara::DSL+:
343
489
 
344
- You can mix the DSL into any context, for example you could use it in RSpec
345
- examples. Just load the DSL and include it anywhere:
346
490
 
347
491
  require 'capybara'
348
492
  require 'capybara/dsl'
@@ -350,7 +494,7 @@ examples. Just load the DSL and include it anywhere:
350
494
  Capybara.default_driver = :culerity
351
495
 
352
496
  module MyModule
353
- include Capybara
497
+ include Capybara::DSL
354
498
 
355
499
  def login!
356
500
  within("//form[@id='session']") do
@@ -372,8 +516,9 @@ setting app_host:
372
516
  ...
373
517
  visit('/')
374
518
 
375
- Note that rack-test does not support running against a remote server. With
376
- drivers that support it, you can also visit any URL directly:
519
+ Note that the default driver (<tt>:rack_test</tt>) does not support running
520
+ against a remote server. With drivers that support it, you can also visit any
521
+ URL directly:
377
522
 
378
523
  visit('http://www.google.com')
379
524
 
@@ -385,7 +530,9 @@ remote application:
385
530
 
386
531
  == Using the sessions manually
387
532
 
388
- For ultimate control, you can instantiate and use a session manually.
533
+ For ultimate control, you can instantiate and use a
534
+ {Session}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session]
535
+ manually.
389
536
 
390
537
  require 'capybara'
391
538
 
@@ -399,8 +546,8 @@ For ultimate control, you can instantiate and use a session manually.
399
546
  == XPath, CSS and selectors
400
547
 
401
548
  Capybara does not try to guess what kind of selector you are going to give it,
402
- if you want to use XPath with your 'within' declarations for example, you'll need
403
- to do:
549
+ and will always use CSS by default. If you want to use XPath, you'll need to
550
+ do:
404
551
 
405
552
  within(:xpath, '//ul/li') { ... }
406
553
  find(:xpath, '//ul/li').text
@@ -474,14 +621,14 @@ an API to tweak those drivers with whatever settings you want, or to add your ow
474
621
  drivers. This is how to switch the selenium driver to use chrome:
475
622
 
476
623
  Capybara.register_driver :selenium do |app|
477
- Capybara::Driver::Selenium.new(app, :browser => :chrome)
624
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
478
625
  end
479
626
 
480
627
  However, it's also possible to give this a different name, so tests can switch
481
628
  between using different browsers effortlessly:
482
629
 
483
630
  Capybara.register_driver :selenium_chrome do |app|
484
- Capybara::Driver::Selenium.new(app, :browser => :chrome)
631
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
485
632
  end
486
633
 
487
634
  Whatever is returned from the block should conform to the API described by
@@ -503,7 +650,7 @@ additional info about how the underlying driver can be configured.
503
650
 
504
651
  * Freezing time: It's common practice to mock out the Time so that features
505
652
  that depend on the current Date work as expected. This can be problematic,
506
- since Capybara's AJAX timing uses the system time, resulting in Capybara
653
+ since Capybara's Ajax timing uses the system time, resulting in Capybara
507
654
  never timing out and just hanging when a failure occurs. It's still possible to
508
655
  use plugins which allow you to travel in time, rather than freeze time.
509
656
  One such plugin is {Timecop}[http://github.com/jtrupiano/timecop].