capybara 2.0.3 → 2.1.0

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 (82) hide show
  1. data/History.md +82 -0
  2. data/README.md +57 -52
  3. data/lib/capybara/cucumber.rb +4 -1
  4. data/lib/capybara/driver/base.rb +13 -9
  5. data/lib/capybara/driver/node.rb +18 -6
  6. data/lib/capybara/helpers.rb +111 -22
  7. data/lib/capybara/node/actions.rb +30 -25
  8. data/lib/capybara/node/base.rb +25 -32
  9. data/lib/capybara/node/document.rb +6 -2
  10. data/lib/capybara/node/element.rb +44 -7
  11. data/lib/capybara/node/finders.rb +49 -22
  12. data/lib/capybara/node/matchers.rb +38 -21
  13. data/lib/capybara/node/simple.rb +31 -9
  14. data/lib/capybara/query.rb +72 -26
  15. data/lib/capybara/rack_test/browser.rb +11 -3
  16. data/lib/capybara/rack_test/css_handlers.rb +8 -0
  17. data/lib/capybara/rack_test/driver.rb +11 -3
  18. data/lib/capybara/rack_test/form.rb +8 -1
  19. data/lib/capybara/rack_test/node.rb +91 -35
  20. data/lib/capybara/rails.rb +0 -1
  21. data/lib/capybara/result.rb +21 -37
  22. data/lib/capybara/rspec/matchers.rb +60 -31
  23. data/lib/capybara/selector.rb +46 -13
  24. data/lib/capybara/selenium/driver.rb +42 -7
  25. data/lib/capybara/selenium/node.rb +23 -5
  26. data/lib/capybara/server.rb +1 -1
  27. data/lib/capybara/session.rb +47 -12
  28. data/lib/capybara/spec/public/test.js +12 -0
  29. data/lib/capybara/spec/session/all_spec.rb +9 -8
  30. data/lib/capybara/spec/session/attach_file_spec.rb +14 -0
  31. data/lib/capybara/spec/session/check_spec.rb +14 -0
  32. data/lib/capybara/spec/session/choose_spec.rb +14 -0
  33. data/lib/capybara/spec/session/click_button_spec.rb +77 -1
  34. data/lib/capybara/spec/session/click_link_or_button_spec.rb +65 -0
  35. data/lib/capybara/spec/session/click_link_spec.rb +24 -0
  36. data/lib/capybara/spec/session/current_scope_spec.rb +29 -0
  37. data/lib/capybara/spec/session/fill_in_spec.rb +26 -0
  38. data/lib/capybara/spec/session/find_button_spec.rb +12 -0
  39. data/lib/capybara/spec/session/find_by_id_spec.rb +12 -1
  40. data/lib/capybara/spec/session/find_field_spec.rb +30 -0
  41. data/lib/capybara/spec/session/find_link_spec.rb +12 -0
  42. data/lib/capybara/spec/session/find_spec.rb +264 -16
  43. data/lib/capybara/spec/session/first_spec.rb +25 -8
  44. data/lib/capybara/spec/session/has_css_spec.rb +2 -2
  45. data/lib/capybara/spec/session/has_field_spec.rb +10 -2
  46. data/lib/capybara/spec/session/has_selector_spec.rb +9 -0
  47. data/lib/capybara/spec/session/has_text_spec.rb +96 -0
  48. data/lib/capybara/spec/session/has_title_spec.rb +47 -0
  49. data/lib/capybara/spec/session/node_spec.rb +48 -0
  50. data/lib/capybara/spec/session/reset_session_spec.rb +10 -2
  51. data/lib/capybara/spec/session/save_page_spec.rb +30 -0
  52. data/lib/capybara/spec/session/select_spec.rb +65 -0
  53. data/lib/capybara/spec/session/text_spec.rb +31 -0
  54. data/lib/capybara/spec/session/title_spec.rb +16 -0
  55. data/lib/capybara/spec/session/uncheck_spec.rb +14 -0
  56. data/lib/capybara/spec/session/unselect_spec.rb +42 -0
  57. data/lib/capybara/spec/session/visit_spec.rb +3 -3
  58. data/lib/capybara/spec/session/within_frame_spec.rb +14 -0
  59. data/lib/capybara/spec/session/within_spec.rb +3 -3
  60. data/lib/capybara/spec/spec_helper.rb +7 -2
  61. data/lib/capybara/spec/views/form.erb +39 -2
  62. data/lib/capybara/spec/views/frame_child.erb +9 -0
  63. data/lib/capybara/spec/views/frame_parent.erb +8 -0
  64. data/lib/capybara/spec/views/with_base_tag.erb +10 -0
  65. data/lib/capybara/spec/views/with_count.erb +7 -0
  66. data/lib/capybara/spec/views/with_hover.erb +17 -0
  67. data/lib/capybara/spec/views/with_html.erb +23 -2
  68. data/lib/capybara/spec/views/with_js.erb +5 -0
  69. data/lib/capybara/spec/views/with_scope.erb +6 -1
  70. data/lib/capybara/spec/views/with_title.erb +1 -0
  71. data/lib/capybara/spec/views/within_frames.erb +1 -0
  72. data/lib/capybara/version.rb +1 -1
  73. data/lib/capybara.rb +43 -62
  74. data/spec/basic_node_spec.rb +75 -24
  75. data/spec/dsl_spec.rb +2 -1
  76. data/spec/rack_test_spec.rb +4 -3
  77. data/spec/rspec/matchers_spec.rb +105 -17
  78. data/spec/server_spec.rb +15 -8
  79. data/spec/spec_helper.rb +2 -1
  80. data.tar.gz.sig +0 -0
  81. metadata +82 -22
  82. metadata.gz.sig +0 -0
@@ -2,7 +2,6 @@ require "rspec"
2
2
  require "capybara"
3
3
  require "capybara/rspec" # Required here instead of in rspec_spec to avoid RSpec deprecation warning
4
4
  require "capybara/spec/test_app"
5
- require "capybara/spec/spec_helper"
6
5
  require "nokogiri"
7
6
 
8
7
  module Capybara
@@ -19,6 +18,12 @@ module Capybara
19
18
  Capybara.app_host = nil
20
19
  Capybara.default_selector = :xpath
21
20
  Capybara.default_wait_time = 1
21
+ Capybara.ignore_hidden_elements = true
22
+ Capybara.exact = false
23
+ Capybara.exact_options = false
24
+ Capybara.raise_server_errors = true
25
+ Capybara.visible_text_only = false
26
+ Capybara.match = :smart
22
27
  end
23
28
 
24
29
  def filter(requires, metadata)
@@ -73,7 +78,7 @@ module Capybara
73
78
  end
74
79
 
75
80
  def extract_results(session)
76
- YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.text.lstrip
81
+ YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
77
82
  end
78
83
  end
79
84
  end
@@ -8,9 +8,21 @@
8
8
  <option>Mrs</option>
9
9
  <option>Mr</option>
10
10
  <option>Miss</option>
11
+ <option disabled="disabled">Other</option>
11
12
  </select>
13
+ </p>
14
+
15
+ <p>
16
+ <label for="customer_name">Customer Name
17
+ <input type="text" name="form[customer_name]" value="Blah" id="customer_name" disabled="disabled"/>
18
+ </label>
12
19
  </p>
13
20
 
21
+ <p>
22
+ <label for="customer_email">Customer Email
23
+ <input type="text" name="form[customer_email]" value="ben@ben.com" id="customer_email"/>
24
+ </label>
25
+ </p>
14
26
 
15
27
  <p>
16
28
  <label for="form_other_title">Other title</label>
@@ -253,10 +265,35 @@
253
265
  <button type="submit" id="click_me_123" title="Click Title button" value="click_me">Click me!</button>
254
266
  <button type="submit" name="form[no_value]">No Value!</button>
255
267
  <button id="no_type">No Type!</button>
256
- <input type="button" disabled value="Disabled button"/>
268
+ <input type="button" disabled="disabled" value="Disabled button"/>
257
269
  </p>
258
270
  </form>
259
271
 
272
+ <input type="text" name="form[outside_input]" value="outside_input" form="form1"/>
273
+
274
+ <form id="form1" action="/form" method="post">
275
+ <input type="text" name="form[which_form]" value="form1" id="form_which_form"/>
276
+ <input type="text" name="form[for_form2]" value="for_form2" form="form2"/>
277
+ <input type="submit" name="form[submit_form1]" value="submit_form1" id="submit_form1"/>
278
+ </form>
279
+
280
+ <form id="form2" action="/form" method="post">
281
+ <input type="text" name="form[which_form]" value="form2" id="form_which_form"/>
282
+ <input type="submit" name="form[unused]" value="unused"/>
283
+ <button type="submit" name="form[other_form_button]" value="other_form_button" form="form1">Form1</button>
284
+ </form>
285
+
286
+ <textarea name="form[outside_textarea]" form="form1">Some text here</textarea>
287
+ <select name="form[outside_select]" form="form1">
288
+ <option>Lisp</option>
289
+ <option selected="selected">Ruby</option>
290
+ <option>Php</option>
291
+ </select>
292
+
293
+ <input type="submit" name="form[outside_submit]" value="outside_submit" form="form1"/>
294
+ <button type="submit" name="form[outside_button]" value="outside_button" form="form2">Outside!</button>
295
+
296
+
260
297
  <form id="get-form" action="/form/get?foo=bar" method="get">
261
298
  <p>
262
299
  <label for="form_middle_name">Middle Name</label>
@@ -304,7 +341,7 @@
304
341
 
305
342
  <p>
306
343
  <label for="form_multiple_documents">Multiple Documents</label>
307
- <input type="file" name="form[multiple_documents][]" id="form_multiple_documents" multiple />
344
+ <input type="file" name="form[multiple_documents][]" id="form_multiple_documents" multiple="multiple" />
308
345
  </p>
309
346
 
310
347
  <p>
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <title>This is the child frame title</title>
4
+ </head>
5
+ <body>
6
+ <iframe src="/frame_one" id="grandchildFrame1"></iframe>
7
+ <iframe src="/frame_two" id="grandchildFrame2"></iframe>
8
+ </body>
9
+ </html>
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>This is the parent frame title</title>
4
+ </head>
5
+ <body>
6
+ <iframe src='/frame_child' id='childFrame'></iframe>
7
+ </body>
8
+ </html>
@@ -0,0 +1,10 @@
1
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4
+ <base href="http://example2.com" />
5
+ <title>with_external_source</title>
6
+ </head>
7
+ <body id="with_js">
8
+ <h1>FooBar</h1>
9
+ </body>
10
+ </html
@@ -0,0 +1,7 @@
1
+ <h1>This page is used for testing number options of has_text?</h1>
2
+
3
+ <p>count1</p>
4
+ <div>
5
+ <p>2 count</p>
6
+ <p>Count</p>
7
+ </div>
@@ -0,0 +1,17 @@
1
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4
+ <title>with_hover</title>
5
+ </head>
6
+
7
+ <body id="with_hover">
8
+ <style type="text/css">
9
+ .hidden_until_hover {display: none;}
10
+ .wrapper:hover .hidden_until_hover { display: block }
11
+ </style>
12
+ <div class="wrapper">
13
+ Some text here so the wrapper has size
14
+ <div class="hidden_until_hover">Here I am</div>
15
+ </div>
16
+ </body>
17
+ </html>
@@ -8,6 +8,8 @@
8
8
  <h2 class="head">Header Class Test Four</h2>
9
9
  <h2 class="head">Header Class Test Five</h2>
10
10
 
11
+ <span class="number">42</span>
12
+
11
13
  <p class="para" id="first">
12
14
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
13
15
  tempor incididunt ut <a href="/with_simple_html" title="awesome title" class="simple">labore</a>
@@ -28,11 +30,13 @@
28
30
 
29
31
  <p>
30
32
  <input type="text" id="test_field" value="monkey"/>
33
+ <input type="text" readonly="readonly" value="should not change" />
31
34
  <textarea id="normal">
32
35
  banana</textarea>
33
36
  <textarea id="additional_newline">
34
37
 
35
38
  banana</textarea>
39
+ <textarea readonly="readonly">textarea should not change</textarea>
36
40
  <a href="/redirect_back">BackToMyself</a>
37
41
  <a title="twas a fine link" href="/redirect">A link came first</a>
38
42
  <a title="a fine link" href="/with_simple_html">A link</a>
@@ -49,6 +53,7 @@ banana</textarea>
49
53
  <input type="text" checked="checked" id="checked_field">
50
54
  <a href="/redirect"><img width="20" height="20" alt="very fine image" /></a>
51
55
  <a href="/with_simple_html"><img width="20" height="20" alt="fine image" /></a>
56
+ <a href="/with_simple_html" disabled="disabled">Disabled link</a>
52
57
 
53
58
  <a href="?query_string=true">Naked Query String</a>
54
59
  <% if params[:query_string] %>
@@ -61,6 +66,10 @@ banana</textarea>
61
66
  <a href="/with_simple_html" title="hidden link" class="simple">hidden link</a>
62
67
  </div>
63
68
 
69
+ <div id="hidden-text">
70
+ Some of this text is <em style="display:none">hidden!</em>
71
+ </div>
72
+
64
73
  <div style="display: none;">
65
74
  <a id="first_invisble" class="hidden">first hidden link</a>
66
75
  </div>
@@ -78,6 +87,18 @@ banana</textarea>
78
87
  </div>
79
88
 
80
89
  <ul>
81
- <li id="john_monkey">Monkey John</li>
82
- <li id="paul_monkey">Monkey Paul</li>
90
+ <li class="beatle guitarist" id="john">John</li>
91
+ <li class="beatle bassist drummer" id="paul">Paul</li>
92
+ <li class="beatle guitarist" id="george">George</li>
93
+ <li class="beatle drummer" id="ringo">Ringo</li>
83
94
  </ul>
95
+
96
+ <div>
97
+ <div class="singular">singular</div>
98
+ <div class="multiple">multiple one</div>
99
+ <div class="multiple">multiple two</div>
100
+ <div class="almost_singular but_not_quite">almost singular but not quite</div>
101
+ <div class="almost_singular">almost singular</div>
102
+ </div>
103
+
104
+ <input type="text" disabled="disabled" name="disabled_text" value="This is disabled"/>
@@ -19,6 +19,7 @@
19
19
  </div>
20
20
 
21
21
  <p><a href="#" id="clickable">Click me</a></p>
22
+ <p><a href="#" id="slow-click">Slowly</a></p>
22
23
 
23
24
  <p>
24
25
  <select id="waiter">
@@ -57,6 +58,10 @@
57
58
  </ul>
58
59
  </p>
59
60
 
61
+ <p>
62
+ <a href="#" id="change-title">Change title</a>
63
+ </p>
64
+
60
65
  <script type="text/javascript">
61
66
  // a javascript comment
62
67
  var aVar = 123;
@@ -4,6 +4,7 @@
4
4
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
5
5
  incididunt ut labore et dolore magna aliqua. Ut enim ad minim venia.
6
6
  <a href="/redirect">Go</a>
7
+ <input name="disabled" disabled="disabled"/>
7
8
  </p>
8
9
 
9
10
  <div id="for_bar">
@@ -23,6 +24,10 @@
23
24
  <label for="bar_first_name">First Name</label>
24
25
  <input type="text" name="form[first_name]" value="Peter" id="bar_first_name"/>
25
26
  </p>
27
+ <p>
28
+ <label for="bar_other_name">Other Name</label>
29
+ <input type="text" name="form[other_name]" value="James" id="bar_other_name" disabled="disabled"/>
30
+ </p>
26
31
  <p><input type="submit" value="Go"/></p>
27
32
  </form>
28
33
  </li>
@@ -33,4 +38,4 @@
33
38
  <ul>
34
39
  <li>With Simple HTML: <a href="/">Go</a>
35
40
  </ul>
36
- </div>
41
+ </div>
@@ -0,0 +1 @@
1
+ <title>Test Title</title>
@@ -6,5 +6,6 @@
6
6
  <div id="divInMainWindow">This is the text for divInMainWindow</div>
7
7
  <iframe src="/frame_one" id="frameOne"></iframe>
8
8
  <iframe src="/frame_two" id="frameTwo"></iframe>
9
+ <iframe src="/frame_parent" id="parentFrame"></iframe>
9
10
  </body>
10
11
  </html>
@@ -1,3 +1,3 @@
1
1
  module Capybara
2
- VERSION = '2.0.3'
2
+ VERSION = '2.1.0'
3
3
  end
data/lib/capybara.rb CHANGED
@@ -15,10 +15,10 @@ module Capybara
15
15
  class InfiniteRedirectError < CapybaraError; end
16
16
 
17
17
  class << self
18
- attr_accessor :asset_root, :app_host, :run_server, :default_host, :always_include_port
19
- attr_accessor :server_host, :server_port
18
+ attr_accessor :asset_host, :app_host, :run_server, :default_host, :always_include_port
19
+ attr_accessor :server_host, :server_port, :exact, :match, :exact_options, :visible_text_only
20
20
  attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements
21
- attr_accessor :save_and_open_page_path, :automatic_reload
21
+ attr_accessor :save_and_open_page_path, :automatic_reload, :raise_server_errors
22
22
  attr_writer :default_driver, :current_driver, :javascript_driver, :session_name
23
23
  attr_accessor :app
24
24
 
@@ -33,9 +33,9 @@ module Capybara
33
33
  #
34
34
  # === Configurable options
35
35
  #
36
- # [asset_root = String] Where static assets are located, used by save_and_open_page
37
36
  # [app_host = String] The default host to use when giving a relative URL to visit
38
37
  # [always_include_port = Boolean] Whether the Rack server's port should automatically be inserted into every visited URL (Default: false)
38
+ # [asset_host = String] Where dynamic assets are hosted - will be prepended to relative asset locations if present (Default: nil)
39
39
  # [run_server = Boolean] Whether to start a Rack server for the given Rack app (Default: true)
40
40
  # [default_selector = :css/:xpath] Methods which take a selector use the given type by default (Default: CSS)
41
41
  # [default_wait_time = Integer] The number of seconds to wait for asynchronous processes to finish (Default: 2)
@@ -88,20 +88,12 @@ module Capybara
88
88
  # page.find('table#myTable').has_selector?(:row, 3)
89
89
  # within(:row, 3) { page.should have_content('$100.000') }
90
90
  #
91
- # It might be convenient to specify that the selector is automatically chosen for certain
92
- # values. This way you don't have to explicitly specify that you are looking for a row, or
93
- # an id. Let's say we want Capybara to treat any Symbols sent into methods like find to be
94
- # treated as though they were element ids. We could achieve this like so:
91
+ # Here is another example:
95
92
  #
96
93
  # Capybara.add_selector(:id) do
97
94
  # xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
98
- # match { |value| value.is_a?(Symbol) }
99
95
  # end
100
96
  #
101
- # Now we can retrieve elements by id like this:
102
- #
103
- # find(:post_123)
104
- #
105
97
  # Note that this particular selector already ships with Capybara.
106
98
  #
107
99
  # @param [Symbol] name The name of the selector to add
@@ -124,7 +116,7 @@ module Capybara
124
116
  # Rack::Handler::Mongrel.run(app, :Port => port)
125
117
  # end
126
118
  #
127
- # By default, Capybara will try to run thin, falling back to webrick.
119
+ # By default, Capybara will try to run webrick.
128
120
  #
129
121
  # @yield [app, port] This block recieves a rack app and port and should run a Rack handler
130
122
  #
@@ -294,53 +286,38 @@ module Capybara
294
286
  self.default_driver = nil
295
287
  self.current_driver = nil
296
288
 
297
- autoload :DSL, 'capybara/dsl'
298
- autoload :Server, 'capybara/server'
299
- autoload :Session, 'capybara/session'
300
- autoload :Selector, 'capybara/selector'
301
- autoload :Query, 'capybara/query'
302
- autoload :Result, 'capybara/result'
303
- autoload :Helpers, 'capybara/helpers'
304
- autoload :VERSION, 'capybara/version'
305
-
306
- module Node
307
- autoload :Base, 'capybara/node/base'
308
- autoload :Simple, 'capybara/node/simple'
309
- autoload :Element, 'capybara/node/element'
310
- autoload :Document, 'capybara/node/document'
311
- autoload :Finders, 'capybara/node/finders'
312
- autoload :Matchers, 'capybara/node/matchers'
313
- autoload :Actions, 'capybara/node/actions'
314
- end
315
-
316
- module Driver
317
- autoload :Base, 'capybara/driver/base'
318
- autoload :Node, 'capybara/driver/node'
319
-
320
- class Selenium
321
- def initialize(*args)
322
- raise "Capybara::Driver::Selenium has been renamed to Capybara::Selenium::Driver"
323
- end
324
- end
325
-
326
- class RackTest
327
- def initialize(*args)
328
- raise "Capybara::Driver::RackTest has been renamed to Capybara::RackTest::Driver"
329
- end
330
- end
331
- end
332
-
333
- module RackTest
334
- autoload :Driver, 'capybara/rack_test/driver'
335
- autoload :Node, 'capybara/rack_test/node'
336
- autoload :Form, 'capybara/rack_test/form'
337
- autoload :Browser, 'capybara/rack_test/browser'
338
- end
339
-
340
- module Selenium
341
- autoload :Node, 'capybara/selenium/node'
342
- autoload :Driver, 'capybara/selenium/driver'
343
- end
289
+ module Driver; end
290
+ module RackTest; end
291
+ module Selenium; end
292
+
293
+ require 'capybara/helpers'
294
+ require 'capybara/session'
295
+ require 'capybara/dsl'
296
+ require 'capybara/server'
297
+ require 'capybara/selector'
298
+ require 'capybara/query'
299
+ require 'capybara/result'
300
+ require 'capybara/version'
301
+
302
+ require 'capybara/node/finders'
303
+ require 'capybara/node/matchers'
304
+ require 'capybara/node/actions'
305
+ require 'capybara/node/simple'
306
+ require 'capybara/node/base'
307
+ require 'capybara/node/element'
308
+ require 'capybara/node/document'
309
+
310
+ require 'capybara/driver/base'
311
+ require 'capybara/driver/node'
312
+
313
+ require 'capybara/rack_test/driver'
314
+ require 'capybara/rack_test/node'
315
+ require 'capybara/rack_test/form'
316
+ require 'capybara/rack_test/browser'
317
+ require 'capybara/rack_test/css_handlers.rb'
318
+
319
+ require 'capybara/selenium/node'
320
+ require 'capybara/selenium/driver'
344
321
  end
345
322
 
346
323
  Capybara.configure do |config|
@@ -349,9 +326,13 @@ Capybara.configure do |config|
349
326
  config.server {|app, port| Capybara.run_default_server(app, port)}
350
327
  config.default_selector = :css
351
328
  config.default_wait_time = 2
352
- config.ignore_hidden_elements = false
329
+ config.ignore_hidden_elements = true
353
330
  config.default_host = "http://www.example.com"
354
331
  config.automatic_reload = true
332
+ config.match = :smart
333
+ config.exact = false
334
+ config.raise_server_errors = true
335
+ config.visible_text_only = false
355
336
  end
356
337
 
357
338
  Capybara.register_driver :rack_test do |app|
@@ -4,26 +4,42 @@ describe Capybara do
4
4
  describe '.string' do
5
5
  let :string do
6
6
  Capybara.string <<-STRING
7
- <div id="page">
8
- <div id="content">
9
- <h1 data="fantastic">Totally awesome</h1>
10
- <p>Yes it is</p>
11
- </div>
12
-
13
- <div id="footer" style="display: none">
14
- <p>c2010</p>
15
- <p>Jonas Nicklas</p>
16
- <input type="text" name="foo" value="bar"/>
17
- <select name="animal">
18
- <option>Monkey</option>
19
- <option selected="selected">Capybara</option>
20
- </select>
21
- </div>
22
-
23
- <section>
24
- <div class="subsection"></div>
25
- </div>
26
- </div>
7
+ <html>
8
+ <head>
9
+ <title>simple_node</title>
10
+ </head>
11
+ <body>
12
+ <div id="page">
13
+ <div id="content">
14
+ <h1 data="fantastic">Totally awesome</h1>
15
+ <p>Yes it is</p>
16
+ </div>
17
+
18
+ <form>
19
+ <input type="text" name="bleh" disabled="disabled"/>
20
+ <input type="text" name="meh"/>
21
+ </form>
22
+
23
+ <div id="footer">
24
+ <p>c2010</p>
25
+ <p>Jonas Nicklas</p>
26
+ <input type="text" name="foo" value="bar"/>
27
+ <select name="animal">
28
+ <option>Monkey</option>
29
+ <option selected="selected">Capybara</option>
30
+ </select>
31
+ </div>
32
+
33
+ <div id="hidden" style="display: none">
34
+ <p id="secret">Secret</p>
35
+ </div>
36
+
37
+ <section>
38
+ <div class="subsection"></div>
39
+ </section>
40
+ </div>
41
+ </body>
42
+ </html>
27
43
  STRING
28
44
  end
29
45
 
@@ -56,8 +72,8 @@ describe Capybara do
56
72
  end
57
73
 
58
74
  it "allows finding only visible nodes" do
59
- string.all('//p', :text => 'c2010', :visible => true).should be_empty
60
- string.all('//p', :text => 'c2010', :visible => false).should have(1).element
75
+ string.all(:css, '#secret', :visible => true).should be_empty
76
+ string.all(:css, '#secret', :visible => false).should have(1).element
61
77
  end
62
78
 
63
79
  it "allows finding elements and extracting text from them" do
@@ -77,13 +93,48 @@ describe Capybara do
77
93
  end
78
94
 
79
95
  it "allows finding elements and extracting the path" do
80
- string.find('//input').value.should == 'bar'
96
+ string.find('//div/input').value.should == 'bar'
81
97
  string.find('//select').value.should == 'Capybara'
82
98
  end
83
99
 
84
100
  it "allows finding elements and checking if they are visible" do
85
101
  string.find('//h1').should be_visible
86
- string.find('//input').should_not be_visible
102
+ string.find(:css, "#secret", :visible => false).should_not be_visible
103
+ end
104
+
105
+ it "allows finding elements and checking if they are disabled" do
106
+ string.find('//form/input[@name="bleh"]').should be_disabled
107
+ string.find('//form/input[@name="meh"]').should_not be_disabled
108
+ end
109
+
110
+ describe "#title" do
111
+ it "returns the page title" do
112
+ string.title.should == "simple_node"
113
+ end
114
+ end
115
+
116
+ describe "#has_title?" do
117
+ it "returns whether the page has the given title" do
118
+ string.has_title?('simple_node').should be_true
119
+ string.has_title?('monkey').should be_false
120
+ end
121
+
122
+ it "allows regexp matches" do
123
+ string.has_title?(/s[a-z]+_node/).should be_true
124
+ string.has_title?(/monkey/).should be_false
125
+ end
126
+ end
127
+
128
+ describe '#has_no_title?' do
129
+ it "returns whether the page does not have the given title" do
130
+ string.has_no_title?('simple_node').should be_false
131
+ string.has_no_title?('monkey').should be_true
132
+ end
133
+
134
+ it "allows regexp matches" do
135
+ string.has_no_title?(/s[a-z]+_node/).should be_false
136
+ string.has_no_title?(/monkey/).should be_true
137
+ end
87
138
  end
88
139
  end
89
140
  end
data/spec/dsl_spec.rb CHANGED
@@ -10,7 +10,8 @@ Capybara::SpecHelper.run_specs TestClass.new, "DSL", :skip => [
10
10
  :screenshot,
11
11
  :frames,
12
12
  :windows,
13
- :server
13
+ :server,
14
+ :hover
14
15
  ]
15
16
 
16
17
  describe Capybara::DSL do
@@ -9,7 +9,8 @@ Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :skip => [
9
9
  :screenshot,
10
10
  :frames,
11
11
  :windows,
12
- :server
12
+ :server,
13
+ :hover
13
14
  ]
14
15
 
15
16
  describe Capybara::Session do
@@ -84,14 +85,14 @@ describe Capybara::RackTest::Driver do
84
85
  it 'should keep headers on link clicks' do
85
86
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
86
87
  @driver.visit('/header_links')
87
- @driver.find('.//a').first.click
88
+ @driver.find_xpath('.//a').first.click
88
89
  @driver.html.should include('foobar')
89
90
  end
90
91
 
91
92
  it 'should keep headers on form submit' do
92
93
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
93
94
  @driver.visit('/header_links')
94
- @driver.find('.//input').first.click
95
+ @driver.find_xpath('.//input').first.click
95
96
  @driver.html.should include('foobar')
96
97
  end
97
98