capybara 1.1.4 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/History.txt +100 -0
  2. data/License.txt +22 -0
  3. data/README.md +829 -0
  4. data/lib/capybara.rb +124 -6
  5. data/lib/capybara/cucumber.rb +2 -5
  6. data/lib/capybara/driver/base.rb +5 -5
  7. data/lib/capybara/driver/node.rb +2 -2
  8. data/lib/capybara/dsl.rb +3 -121
  9. data/lib/capybara/node/actions.rb +12 -28
  10. data/lib/capybara/node/base.rb +5 -13
  11. data/lib/capybara/node/element.rb +21 -21
  12. data/lib/capybara/node/finders.rb +27 -89
  13. data/lib/capybara/node/matchers.rb +107 -69
  14. data/lib/capybara/node/simple.rb +11 -13
  15. data/lib/capybara/query.rb +78 -0
  16. data/lib/capybara/rack_test/browser.rb +16 -27
  17. data/lib/capybara/rack_test/driver.rb +11 -1
  18. data/lib/capybara/rack_test/node.rb +17 -1
  19. data/lib/capybara/result.rb +84 -0
  20. data/lib/capybara/rspec/matchers.rb +28 -63
  21. data/lib/capybara/selector.rb +97 -33
  22. data/lib/capybara/selenium/driver.rb +14 -61
  23. data/lib/capybara/selenium/node.rb +6 -15
  24. data/lib/capybara/server.rb +32 -27
  25. data/lib/capybara/session.rb +54 -30
  26. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  27. data/lib/capybara/spec/public/jquery.js +9046 -0
  28. data/lib/capybara/spec/public/test.js +4 -1
  29. data/lib/capybara/spec/session.rb +56 -27
  30. data/lib/capybara/spec/session/all_spec.rb +8 -4
  31. data/lib/capybara/spec/session/attach_file_spec.rb +12 -9
  32. data/lib/capybara/spec/session/check_spec.rb +6 -3
  33. data/lib/capybara/spec/session/choose_spec.rb +4 -1
  34. data/lib/capybara/spec/session/click_button_spec.rb +5 -14
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +2 -1
  36. data/lib/capybara/spec/session/click_link_spec.rb +3 -17
  37. data/lib/capybara/spec/session/current_url_spec.rb +77 -9
  38. data/lib/capybara/spec/session/fill_in_spec.rb +8 -18
  39. data/lib/capybara/spec/session/find_spec.rb +19 -46
  40. data/lib/capybara/spec/session/first_spec.rb +2 -34
  41. data/lib/capybara/spec/session/has_css_spec.rb +1 -1
  42. data/lib/capybara/spec/session/has_field_spec.rb +28 -0
  43. data/lib/capybara/spec/session/has_select_spec.rb +84 -31
  44. data/lib/capybara/spec/session/has_table_spec.rb +7 -69
  45. data/lib/capybara/spec/session/has_text_spec.rb +168 -0
  46. data/lib/capybara/spec/session/javascript.rb +65 -81
  47. data/lib/capybara/spec/session/node_spec.rb +115 -0
  48. data/lib/capybara/spec/session/screenshot.rb +29 -0
  49. data/lib/capybara/spec/session/select_spec.rb +12 -12
  50. data/lib/capybara/spec/session/text_spec.rb +9 -4
  51. data/lib/capybara/spec/session/unselect_spec.rb +12 -6
  52. data/lib/capybara/spec/session/visit_spec.rb +76 -0
  53. data/lib/capybara/spec/session/within_frame_spec.rb +33 -0
  54. data/lib/capybara/spec/session/within_spec.rb +47 -58
  55. data/lib/capybara/spec/session/within_window_spec.rb +40 -0
  56. data/lib/capybara/spec/test_app.rb +27 -3
  57. data/lib/capybara/spec/views/form.erb +11 -10
  58. data/lib/capybara/spec/views/host_links.erb +2 -2
  59. data/lib/capybara/spec/views/tables.erb +6 -66
  60. data/lib/capybara/spec/views/with_html.erb +3 -3
  61. data/lib/capybara/spec/views/with_js.erb +11 -8
  62. data/lib/capybara/util/save_and_open_page.rb +4 -3
  63. data/lib/capybara/version.rb +1 -1
  64. data/spec/basic_node_spec.rb +15 -3
  65. data/spec/dsl_spec.rb +12 -10
  66. data/spec/rack_test_spec.rb +152 -0
  67. data/spec/rspec/features_spec.rb +0 -2
  68. data/spec/rspec/matchers_spec.rb +164 -89
  69. data/spec/rspec_spec.rb +0 -2
  70. data/spec/selenium_spec.rb +67 -0
  71. data/spec/server_spec.rb +35 -23
  72. data/spec/spec_helper.rb +18 -2
  73. metadata +30 -30
  74. data/README.rdoc +0 -722
  75. data/lib/capybara/spec/driver.rb +0 -301
  76. data/lib/capybara/spec/session/current_host_spec.rb +0 -68
  77. data/lib/capybara/spec/session/has_content_spec.rb +0 -106
  78. data/lib/capybara/util/timeout.rb +0 -27
  79. data/spec/driver/rack_test_driver_spec.rb +0 -89
  80. data/spec/driver/selenium_driver_spec.rb +0 -37
  81. data/spec/session/rack_test_session_spec.rb +0 -55
  82. data/spec/session/selenium_session_spec.rb +0 -26
  83. data/spec/string_spec.rb +0 -77
  84. data/spec/timeout_spec.rb +0 -28
@@ -3,8 +3,14 @@ require 'rack'
3
3
  require 'yaml'
4
4
 
5
5
  class TestApp < Sinatra::Base
6
+ class TestAppError < StandardError; end
7
+
6
8
  set :root, File.dirname(__FILE__)
7
9
  set :static, true
10
+ set :raise_errors, true
11
+ set :show_exceptions, false
12
+
13
+ # Also check lib/capybara/spec/views/*.erb for pages not listed here
8
14
 
9
15
  get '/' do
10
16
  'Hello world! <a href="with_html">Relative</a>'
@@ -22,8 +28,22 @@ class TestApp < Sinatra::Base
22
28
  redirect '/landed'
23
29
  end
24
30
 
31
+ get '/referer_base' do
32
+ '<a href="/get_referer">direct link</a>' +
33
+ '<a href="/redirect_to_get_referer">link via redirect</a>' +
34
+ '<form action="/get_referer" method="get"><input type="submit"></form>'
35
+ end
36
+
37
+ get '/redirect_to_get_referer' do
38
+ redirect '/get_referer'
39
+ end
40
+
41
+ get '/get_referer' do
42
+ request.referer.nil? ? "No referer" : "Got referer: #{request.referer}"
43
+ end
44
+
25
45
  get '/host' do
26
- "Current host is #{request.scheme}://#{request.host}"
46
+ "Current host is #{request.scheme}://#{request.host}:#{request.port}"
27
47
  end
28
48
 
29
49
  get '/redirect/:times/times' do
@@ -72,7 +92,7 @@ class TestApp < Sinatra::Base
72
92
  end
73
93
 
74
94
  get '/redirect_secure' do
75
- redirect "https://#{request.host}/host"
95
+ redirect "https://#{request.host}:#{request.port}/host"
76
96
  end
77
97
 
78
98
  get '/slow_response' do
@@ -98,6 +118,10 @@ class TestApp < Sinatra::Base
98
118
  redirect '/get_header'
99
119
  end
100
120
 
121
+ get '/error' do
122
+ raise TestAppError, "some error"
123
+ end
124
+
101
125
  get '/:view' do |view|
102
126
  erb view.to_sym
103
127
  end
@@ -107,7 +131,7 @@ class TestApp < Sinatra::Base
107
131
  end
108
132
 
109
133
  post '/upload_empty' do
110
- if params[:form].nil? || params[:form][:file].nil?
134
+ if params[:form][:file].nil?
111
135
  'Successfully ignored empty file field.'
112
136
  else
113
137
  'Something went wrong.'
@@ -32,7 +32,7 @@
32
32
  <label for="form_last_name">Last Name</label>
33
33
  <input type="text" name="form[last_name]" value="Smith" id="form_last_name"/>
34
34
  </p>
35
-
35
+
36
36
  <p>
37
37
  <label for="form_name_explanation">Explanation of Name</label>
38
38
  <textarea name="form[name_explanation]" id="form_name_explanation"></textarea>
@@ -47,7 +47,7 @@
47
47
  <label for="form_schmooo">Schmooo</label>
48
48
  <input type="schmooo" name="form[schmooo]" value="This is Schmooo!" id="form_schmooo"/>
49
49
  </p>
50
-
50
+
51
51
  <p>
52
52
  <label>Street<br/>
53
53
  <input type="text" maxlength="" name="form[street]" value="Sesame street 66"/>
@@ -74,7 +74,7 @@
74
74
  <label for="form_image">Image</label>
75
75
  <input type="file" name="form[image]" id="form_image"/>
76
76
  </p>
77
-
77
+
78
78
  <p>
79
79
  <input type="hidden" name="form[token]" value="12345" id="form_token"/>
80
80
  </p>
@@ -155,7 +155,7 @@
155
155
  <p>
156
156
  <label for="form_underwear">Underwear</label>
157
157
  <select name="form[underwear][]" id="form_underwear" multiple="multiple">
158
- <option selected="selected">Boxer Briefs</option>
158
+ <option selected="selected">Boxerbriefs</option>
159
159
  <option>Boxers</option>
160
160
  <option selected="selected">Briefs</option>
161
161
  <option selected="selected">Commando</option>
@@ -163,7 +163,7 @@
163
163
  <option selected="selected" value="thermal">Long Johns</option>
164
164
  </select>
165
165
  </p>
166
-
166
+
167
167
  <p>
168
168
  <span>First address<span>
169
169
  <label for='address1_street'>Street</label>
@@ -185,7 +185,7 @@
185
185
  <input type="text" name="form[addresses][][street]" value="" id="address2_street">
186
186
 
187
187
  <label for='address2_city'>City</label>
188
- <input type="text" name="form[addresses][][city]" value="" id="address2_city">
188
+ <input type="text" name="form[addresses][][city]" value="" id="address2_city">
189
189
 
190
190
  <label for='address2_country'>Country</label>
191
191
  <select name="form[addresses][][country]" id="address2_country">
@@ -274,6 +274,7 @@
274
274
  </p>
275
275
 
276
276
  <p>
277
+ <input type="hidden" name="form[dummy]" value="ensure params[:form] exists"/>
277
278
  <input type="submit" value="Upload Empty"/>
278
279
  <p>
279
280
  </form>
@@ -285,12 +286,12 @@
285
286
  </p>
286
287
 
287
288
  <p>
288
- <label for="form_document">Document</label>
289
+ <label for="form_document">Single Document</label>
289
290
  <input type="file" name="form[document]" id="form_document"/>
290
291
  </p>
291
-
292
+
292
293
  <p>
293
- <input type="submit" value="Upload"/>
294
+ <input type="submit" value="Upload Single"/>
294
295
  <p>
295
296
  </form>
296
297
 
@@ -337,7 +338,7 @@
337
338
  <label for="html5_color">Html5 Color</label>
338
339
  <input type="color" name="form[html5_color]" value="#FFFFFF" id="html5_color"/>
339
340
  </p>
340
-
341
+
341
342
  <p>
342
343
  <input type="submit" name="form[html5_submit]" value="html5_submit"/>
343
344
  </p>
@@ -1,12 +1,12 @@
1
1
  <p>
2
2
  <a href="/host">Relative Host</a>
3
- <a href="http://capybara2.elabs.se/host">Absolute Host</a>
3
+ <a href="<%= params[:absolute_host] %>/host">Absolute Host</a>
4
4
  </p>
5
5
 
6
6
  <form action="/host">
7
7
  <p><input type="submit" value="Relative Host"/></p>
8
8
  </form>
9
9
 
10
- <form action="http://capybara2.elabs.se/host">
10
+ <form action="<%= params[:absolute_host] %>/host">
11
11
  <p><input type="submit" value="Absolute Host"/></p>
12
12
  </form>
@@ -1,7 +1,7 @@
1
1
  <form action="/form" method="post">
2
2
  <table id="agent_table">
3
3
  <caption>Agent</caption>
4
-
4
+
5
5
  <tr>
6
6
  <td>
7
7
  <label for="form_agent_name">Name</label>
@@ -10,7 +10,7 @@
10
10
  <input type="text" name="form[agent_name]" value="James" id="form_agent_name"/>
11
11
  </td>
12
12
  </tr>
13
-
13
+
14
14
  <tr>
15
15
  <td colspan="2">
16
16
  <input type="submit" value="Create"/>
@@ -22,7 +22,7 @@
22
22
  <form action="/form" method="post">
23
23
  <table id="girl_table">
24
24
  <caption>Girl</caption>
25
-
25
+
26
26
  <tr>
27
27
  <td>
28
28
  <label for="form_girl_name">Name</label>
@@ -31,7 +31,7 @@
31
31
  <input type="text" name="form[girl_name]" value="Vesper" id="form_girl_name"/>
32
32
  </td>
33
33
  </tr>
34
-
34
+
35
35
  <tr>
36
36
  <td colspan="2">
37
37
  <input type="submit" value="Create"/>
@@ -43,7 +43,7 @@
43
43
  <form action="/form" method="post">
44
44
  <table id="villain_table">
45
45
  <caption>Villain</caption>
46
-
46
+
47
47
  <tr>
48
48
  <td>
49
49
  <label for="form_villain_name">Name</label>
@@ -52,7 +52,7 @@
52
52
  <input type="text" name="form[villain_name]" value="Ernst" id="form_villain_name"/>
53
53
  </td>
54
54
  </tr>
55
-
55
+
56
56
  <tr>
57
57
  <td colspan="2">
58
58
  <input type="submit" value="Create"/>
@@ -60,63 +60,3 @@
60
60
  </tr>
61
61
  </table>
62
62
  </form>
63
-
64
- <table>
65
- <caption>Ransom</caption>
66
-
67
- <thead>
68
- <tr>
69
- <th>Year</th>
70
- <th>Governmental</th>
71
- <th>Private</th>
72
- </tr>
73
- </thead>
74
-
75
- <tbody>
76
- <tr>
77
- <th scope="row">2007</th>
78
- <td>$300</td>
79
- <td>$100</td>
80
- </tr>
81
- <tr>
82
- <th scope="row">2008</th>
83
- <td>$123</td>
84
- <td>$897</td>
85
- </tr>
86
- <tr>
87
- <th scope="row">2009</th>
88
- <td>$543</td>
89
- <td>$99</td>
90
- </tr>
91
- </tbody>
92
- </table>
93
-
94
- <table>
95
- <caption>Deaths</caption>
96
-
97
- <thead>
98
- <tr>
99
- <th>Year</th>
100
- <th>Sharks with lasers</th>
101
- <th>Flaming volcano</th>
102
- </tr>
103
- </thead>
104
-
105
- <tbody>
106
- <tr>
107
- <th scope="row">2007</th>
108
- <td>66</td>
109
- <td>7</td>
110
- </tr>
111
- <tr>
112
- <th scope="row">2008</th>
113
- <td>123</td>
114
- <td>12</td>
115
- </tr>
116
- <tr>
117
- <th scope="row">2009</th>
118
- <td>913</td>
119
- <td>13</td>
120
- </tr>
121
- </tbody>
122
- </table>
@@ -37,14 +37,14 @@ banana</textarea>
37
37
  <a title="twas a fine link" href="/redirect">A link came first</a>
38
38
  <a title="a fine link" href="/with_simple_html">A link</a>
39
39
  <a title="a fine link with data method" data-method="delete" href="/delete">A link with data-method</a>
40
+ <a title="a fine link with capitalized data method" data-method="DELETE" href="/delete">A link with capitalized data-method</a>
40
41
  <a>No Href</a>
41
42
  <a href="">Blank Href</a>
42
43
  <a href="#">Blank Anchor</a>
43
- <a href="#anchor">Anchor</a>
44
+ <a href="#anchor">Normal Anchor</a>
44
45
  <a href="/with_simple_html#anchor">Anchor on different page</a>
45
46
  <a href="/with_html#anchor">Anchor on same page</a>
46
47
  <a href="with_html">Relative</a>
47
- <input type="text" value="" id="test_field">
48
48
  <input type="text" checked="checked" id="checked_field">
49
49
  <a href="/redirect"><img width="20" height="20" alt="very fine image" /></a>
50
50
  <a href="/with_simple_html"><img width="20" height="20" alt="fine image" /></a>
@@ -57,7 +57,7 @@ banana</textarea>
57
57
 
58
58
  <div id="hidden" style="display: none;">
59
59
  <div id="hidden_via_ancestor">Inside element with hidden ancestor</div>
60
- <a href="/with_simple_html" title="awesome title" class="simple">hidden link</a>
60
+ <a href="/with_simple_html" title="hidden link" class="simple">hidden link</a>
61
61
  </div>
62
62
 
63
63
  <div style="display: none;">
@@ -2,14 +2,14 @@
2
2
  <head>
3
3
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4
4
  <title>with_js</title>
5
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
6
- <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
5
+ <script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
6
+ <script src="/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
7
7
  <script src="/test.js" type="text/javascript" charset="utf-8"></script>
8
8
  </head>
9
-
9
+
10
10
  <body id="with_js">
11
11
  <h1>FooBar</h1>
12
-
12
+
13
13
  <p id="change">This is text</p>
14
14
  <div id="drag">
15
15
  <p>This is a draggable element.</p>
@@ -17,20 +17,24 @@
17
17
  <div id="drop">
18
18
  <p>It should be dropped here.</p>
19
19
  </div>
20
-
20
+
21
21
  <p><a href="#" id="clickable">Click me</a></p>
22
-
22
+
23
23
  <p>
24
24
  <select id="waiter">
25
25
  <option>Foo</option>
26
26
  <option>My Waiting Option</option>
27
27
  </select>
28
28
  </p>
29
-
29
+
30
30
  <p>
31
31
  <input type="text" name="with_focus_event" value="" id="with_focus_event"/>
32
32
  </p>
33
33
 
34
+ <p>
35
+ <input type="text" name="with_change_event" value="default value" id="with_change_event"/>
36
+ </p>
37
+
34
38
  <p>
35
39
  <input type="checkbox" id="checkbox_with_event"/>
36
40
  </p>
@@ -41,7 +45,6 @@
41
45
 
42
46
  <p>
43
47
  <a id="reload-link" href="#">Reload!</a>
44
- <em>this won't change</em>
45
48
  <div id="reload-me"><em>waiting to be reloaded</em></div>
46
49
  </p>
47
50
 
@@ -22,11 +22,12 @@ module Capybara
22
22
  protected
23
23
 
24
24
  def open_in_browser(path) # :nodoc
25
- require "launchy"
25
+ require "launchy" # could raise LoadError
26
+ raise LoadError unless Launchy::Version::MAJOR >= 2
26
27
  Launchy.open(path)
27
28
  rescue LoadError
28
- warn "Sorry, you need to install launchy (`gem install launchy`) and " <<
29
- "make sure it's available to open pages with `save_and_open_page`."
29
+ warn "You need launchy >=2.0.0 to open pages with `save_and_open_page`:\n" <<
30
+ "gem 'launchy', '>= 2.0.0', :require => false, :group => :test"
30
31
  end
31
32
 
32
33
  def rewrite_css_and_image_references(response_html) # :nodoc:
@@ -1,3 +1,3 @@
1
1
  module Capybara
2
- VERSION = '1.1.4'
2
+ VERSION = '2.0.0.beta2'
3
3
  end
@@ -6,7 +6,7 @@ describe Capybara do
6
6
  Capybara.string <<-STRING
7
7
  <div id="page">
8
8
  <div id="content">
9
- <h1 data="fantastic">Awesome</h1>
9
+ <h1 data="fantastic">Totally awesome</h1>
10
10
  <p>Yes it is</p>
11
11
  </div>
12
12
 
@@ -19,6 +19,10 @@ describe Capybara do
19
19
  <option selected="selected">Capybara</option>
20
20
  </select>
21
21
  </div>
22
+
23
+ <section>
24
+ <div class="subsection"></div>
25
+ </div>
22
26
  </div>
23
27
  STRING
24
28
  end
@@ -38,8 +42,16 @@ describe Capybara do
38
42
  string.should_not have_selector(:lifeform, "Gorilla")
39
43
  end
40
44
 
45
+ it 'allows custom matcher using css' do
46
+ Capybara.add_selector :section do
47
+ css { |css_class| "section .#{css_class}" }
48
+ end
49
+ string.should have_selector(:section, 'subsection')
50
+ string.should_not have_selector(:section, 'section_8')
51
+ end
52
+
41
53
  it "allows using matchers with text option" do
42
- string.should have_css('h1', :text => 'Awesome')
54
+ string.should have_css('h1', :text => 'Totally awesome')
43
55
  string.should_not have_css('h1', :text => 'Not so awesome')
44
56
  end
45
57
 
@@ -49,7 +61,7 @@ describe Capybara do
49
61
  end
50
62
 
51
63
  it "allows finding elements and extracting text from them" do
52
- string.find('//h1').text.should == 'Awesome'
64
+ string.find('//h1').text.should == 'Totally awesome'
53
65
  end
54
66
 
55
67
  it "allows finding elements and extracting attributes from them" do
@@ -1,18 +1,12 @@
1
1
  require 'spec_helper'
2
-
3
2
  require 'capybara/dsl'
4
3
 
5
4
  describe Capybara::DSL do
6
-
7
- before do
8
- Capybara.app = TestApp
9
- end
10
-
11
5
  after do
12
6
  Capybara.session_name = nil
13
7
  Capybara.default_driver = nil
14
- Capybara.javascript_driver = nil
15
8
  Capybara.use_default_driver
9
+ Capybara.app = TestApp
16
10
  end
17
11
 
18
12
  describe '#default_driver' do
@@ -69,12 +63,20 @@ describe Capybara::DSL do
69
63
  driver.should == :selenium
70
64
  end
71
65
 
72
- it 'should reset the driver using Capybara.use_default_driver, even if an exception occurs' do
66
+ it 'should return the driver to default if it has not been changed' do
67
+ Capybara.using_driver(:selenium) do
68
+ Capybara.current_driver.should == :selenium
69
+ end
70
+ Capybara.current_driver.should == Capybara.default_driver
71
+ end
72
+
73
+ it 'should reset the driver even if an exception occurs' do
74
+ driver_before_block = Capybara.current_driver
73
75
  begin
74
76
  Capybara.using_driver(:selenium) { raise "ohnoes!" }
75
77
  rescue Exception
76
78
  end
77
- Capybara.current_driver.should == Capybara.default_driver
79
+ Capybara.current_driver.should == driver_before_block
78
80
  end
79
81
 
80
82
  it 'should return the driver to what it was previously' do
@@ -211,6 +213,7 @@ describe Capybara::DSL do
211
213
 
212
214
  it_should_behave_like "session"
213
215
  it_should_behave_like "session without javascript support"
216
+ it_should_behave_like "session without screenshot support"
214
217
 
215
218
  it "should be possible to include it in another class" do
216
219
  klass = Class.new do
@@ -250,5 +253,4 @@ describe Capybara::DSL do
250
253
  foo.using_wait_time(6)
251
254
  end
252
255
  end
253
-
254
256
  end