capybara 2.0.0.beta2 → 2.0.0.beta4

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 (93) hide show
  1. data/History.txt +30 -1
  2. data/README.md +52 -31
  3. data/lib/capybara.rb +1 -0
  4. data/lib/capybara/driver/base.rb +1 -1
  5. data/lib/capybara/driver/node.rb +1 -0
  6. data/lib/capybara/dsl.rb +12 -5
  7. data/lib/capybara/helpers.rb +33 -0
  8. data/lib/capybara/node/actions.rb +4 -2
  9. data/lib/capybara/node/base.rb +52 -1
  10. data/lib/capybara/node/element.rb +0 -12
  11. data/lib/capybara/node/finders.rb +1 -1
  12. data/lib/capybara/node/matchers.rb +57 -47
  13. data/lib/capybara/node/simple.rb +4 -0
  14. data/lib/capybara/query.rb +11 -11
  15. data/lib/capybara/rack_test/browser.rb +14 -15
  16. data/lib/capybara/rack_test/driver.rb +2 -2
  17. data/lib/capybara/rack_test/node.rb +15 -2
  18. data/lib/capybara/result.rb +7 -19
  19. data/lib/capybara/rspec.rb +7 -4
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +8 -3
  22. data/lib/capybara/selector.rb +1 -2
  23. data/lib/capybara/selenium/driver.rb +2 -2
  24. data/lib/capybara/selenium/node.rb +9 -7
  25. data/lib/capybara/session.rb +47 -31
  26. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  27. data/lib/capybara/spec/public/test.js +1 -1
  28. data/lib/capybara/spec/session/all_spec.rb +60 -62
  29. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  30. data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
  31. data/lib/capybara/spec/session/body_spec.rb +21 -0
  32. data/lib/capybara/spec/session/check_spec.rb +67 -50
  33. data/lib/capybara/spec/session/choose_spec.rb +32 -21
  34. data/lib/capybara/spec/session/click_button_spec.rb +261 -221
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
  36. data/lib/capybara/spec/session/click_link_spec.rb +95 -81
  37. data/lib/capybara/spec/session/current_url_spec.rb +70 -60
  38. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  39. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  40. data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
  41. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  42. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  43. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  44. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  45. data/lib/capybara/spec/session/find_spec.rb +96 -91
  46. data/lib/capybara/spec/session/first_spec.rb +53 -55
  47. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  48. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  49. data/lib/capybara/spec/session/has_field_spec.rb +167 -169
  50. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  51. data/lib/capybara/spec/session/has_select_spec.rb +175 -176
  52. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  53. data/lib/capybara/spec/session/has_table_spec.rb +22 -26
  54. data/lib/capybara/spec/session/has_text_spec.rb +159 -132
  55. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  56. data/lib/capybara/spec/session/headers.rb +4 -17
  57. data/lib/capybara/spec/session/html_spec.rb +15 -0
  58. data/lib/capybara/spec/session/node_spec.rb +172 -82
  59. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  60. data/lib/capybara/spec/session/response_code.rb +4 -17
  61. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  62. data/lib/capybara/spec/session/screenshot.rb +8 -24
  63. data/lib/capybara/spec/session/select_spec.rb +100 -89
  64. data/lib/capybara/spec/session/source_spec.rb +12 -0
  65. data/lib/capybara/spec/session/text_spec.rb +15 -17
  66. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  67. data/lib/capybara/spec/session/unselect_spec.rb +57 -52
  68. data/lib/capybara/spec/session/visit_spec.rb +58 -60
  69. data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
  70. data/lib/capybara/spec/session/within_spec.rb +119 -121
  71. data/lib/capybara/spec/session/within_window_spec.rb +29 -31
  72. data/lib/capybara/spec/spec_helper.rb +84 -0
  73. data/lib/capybara/spec/test_app.rb +5 -3
  74. data/lib/capybara/spec/views/form.erb +1 -0
  75. data/lib/capybara/spec/views/with_html.erb +6 -1
  76. data/lib/capybara/spec/views/with_js.erb +1 -0
  77. data/lib/capybara/version.rb +1 -1
  78. data/spec/basic_node_spec.rb +2 -2
  79. data/spec/capybara_spec.rb +9 -0
  80. data/spec/dsl_spec.rb +22 -10
  81. data/spec/rack_test_spec.rb +28 -23
  82. data/spec/result_spec.rb +51 -0
  83. data/spec/rspec/features_spec.rb +19 -0
  84. data/spec/rspec/matchers_spec.rb +6 -0
  85. data/spec/rspec_spec.rb +1 -1
  86. data/spec/selenium_spec.rb +11 -25
  87. data/spec/server_spec.rb +2 -2
  88. data/spec/spec_helper.rb +1 -46
  89. metadata +41 -98
  90. data/lib/capybara/spec/session.rb +0 -183
  91. data/lib/capybara/spec/session/javascript.rb +0 -290
  92. data/lib/capybara/util/save_and_open_page.rb +0 -45
  93. data/spec/save_and_open_page_spec.rb +0 -155
@@ -1,40 +1,38 @@
1
- shared_examples_for "session with window support" do
2
- describe '#within_window' do
3
- before(:each) do
4
- @session.visit('/within_popups')
1
+ Capybara::SpecHelper.spec '#within_window', :requires => [:windows] do
2
+ before(:each) do
3
+ @session.visit('/within_popups')
4
+ end
5
+ after(:each) do
6
+ @session.within_window("firstPopup") do
7
+ @session.evaluate_script('window.close()')
5
8
  end
6
- after(:each) do
7
- @session.within_window("firstPopup") do
8
- @session.evaluate_script('window.close()')
9
- end
10
- @session.within_window("secondPopup") do
11
- @session.evaluate_script('window.close()')
12
- end
9
+ @session.within_window("secondPopup") do
10
+ @session.evaluate_script('window.close()')
13
11
  end
12
+ end
14
13
 
15
- it "should find the div in firstPopup" do
16
- @session.within_window("firstPopup") do
17
- @session.find("//*[@id='divInPopupOne']").text.should eql 'This is the text of divInPopupOne'
18
- end
14
+ it "should find the div in firstPopup" do
15
+ @session.within_window("firstPopup") do
16
+ @session.find("//*[@id='divInPopupOne']").text.should eql 'This is the text of divInPopupOne'
17
+ end
18
+ end
19
+ it "should find the div in secondPopup" do
20
+ @session.within_window("secondPopup") do
21
+ @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
19
22
  end
20
- it "should find the div in secondPopup" do
21
- @session.within_window("secondPopup") do
22
- @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
23
- end
23
+ end
24
+ it "should find the divs in both popups" do
25
+ @session.within_window("secondPopup") do
26
+ @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
24
27
  end
25
- it "should find the divs in both popups" do
26
- @session.within_window("secondPopup") do
27
- @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
28
- end
29
- @session.within_window("firstPopup") do
30
- @session.find("//*[@id='divInPopupOne']").text.should eql 'This is the text of divInPopupOne'
31
- end
28
+ @session.within_window("firstPopup") do
29
+ @session.find("//*[@id='divInPopupOne']").text.should eql 'This is the text of divInPopupOne'
32
30
  end
33
- it "should find the div in the main window after finding a div in a popup" do
34
- @session.within_window("secondPopup") do
35
- @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
36
- end
37
- @session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
31
+ end
32
+ it "should find the div in the main window after finding a div in a popup" do
33
+ @session.within_window("secondPopup") do
34
+ @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
38
35
  end
36
+ @session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
39
37
  end
40
38
  end
@@ -0,0 +1,84 @@
1
+ require "rspec"
2
+ require "capybara"
3
+ require "capybara/rspec" # Required here instead of in rspec_spec to avoid RSpec deprecation warning
4
+ require "capybara/spec/test_app"
5
+ require "capybara/spec/spec_helper"
6
+ require "nokogiri"
7
+
8
+ module Capybara
9
+ module SpecHelper
10
+ class << self
11
+ def configure(config)
12
+ filter = lambda do |requires, metadata|
13
+ if requires and metadata[:skip]
14
+ requires.any? do |require|
15
+ metadata[:skip].include?(require)
16
+ end
17
+ else
18
+ false
19
+ end
20
+ end
21
+ config.filter_run_excluding :requires => filter
22
+ config.before do
23
+ Capybara.app = TestApp
24
+
25
+ Capybara.configure do |config|
26
+ config.default_selector = :xpath
27
+ end
28
+
29
+ Capybara.default_wait_time = 1
30
+ end
31
+ end
32
+
33
+ def spec(name, options={}, &block)
34
+ @specs ||= []
35
+ @specs << [name, options, block]
36
+ end
37
+
38
+ def run_specs(session, name, options={})
39
+ specs = @specs
40
+ describe Capybara::Session, name, options do
41
+ include Capybara::SpecHelper
42
+ before do
43
+ @session = session
44
+ end
45
+ after do
46
+ @session.reset_session!
47
+ end
48
+ specs.each do |name, options, block|
49
+ describe name, options do
50
+ class_eval(&block)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end # class << self
56
+
57
+ def silence_stream(stream)
58
+ old_stream = stream.dup
59
+ stream.reopen(RbConfig::CONFIG['host_os'] =~ /rmswin|mingw/ ? 'NUL:' : '/dev/null')
60
+ stream.sync = true
61
+ yield
62
+ ensure
63
+ stream.reopen(old_stream)
64
+ end
65
+
66
+ def quietly
67
+ silence_stream(STDOUT) do
68
+ silence_stream(STDERR) do
69
+ yield
70
+ end
71
+ end
72
+ end
73
+
74
+ def extract_results(session)
75
+ YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.text.lstrip
76
+ end
77
+ end
78
+ end
79
+
80
+ RSpec.configure do |config|
81
+ Capybara::SpecHelper.configure(config)
82
+ end
83
+
84
+ Dir[File.dirname(__FILE__)+'/session/*'].each { |group| require group }
@@ -151,9 +151,11 @@ class TestApp < Sinatra::Base
151
151
 
152
152
  post '/upload_multiple' do
153
153
  begin
154
- buffer = []
155
- buffer << "Content-type: #{params[:form][:multiple_documents][0][:type]}"
156
- buffer << "File content: #{params[:form][:multiple_documents][0][:tempfile].read}"
154
+ buffer = ["#{params[:form][:multiple_documents].size}"]
155
+ params[:form][:multiple_documents].each do |doc|
156
+ buffer << "Content-type: #{doc[:type]}"
157
+ buffer << "File content: #{doc[:tempfile].read}"
158
+ end
157
159
  buffer.join(' | ')
158
160
  rescue
159
161
  'No files uploaded'
@@ -253,6 +253,7 @@
253
253
  <button type="submit" id="click_me_123" title="Click Title button" value="click_me">Click me!</button>
254
254
  <button type="submit" name="form[no_value]">No Value!</button>
255
255
  <button id="no_type">No Type!</button>
256
+ <input type="button" disabled value="Disabled button"/>
256
257
  </p>
257
258
  </form>
258
259
 
@@ -21,7 +21,7 @@
21
21
  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
22
22
  dolore eu fugiat <a href="/redirect" id="red">Redirect</a> pariatur. Excepteur sint occaecat cupidatat non proident,
23
23
  sunt in culpa qui officia
24
- text with
24
+ text with &nbsp;
25
25
  whitespace
26
26
  id est laborum.
27
27
  </p>
@@ -45,6 +45,7 @@ banana</textarea>
45
45
  <a href="/with_simple_html#anchor">Anchor on different page</a>
46
46
  <a href="/with_html#anchor">Anchor on same page</a>
47
47
  <a href="with_html">Relative</a>
48
+ <a href="//<%= request.host_with_port %>/foo">Protocol</a>
48
49
  <input type="text" checked="checked" id="checked_field">
49
50
  <a href="/redirect"><img width="20" height="20" alt="very fine image" /></a>
50
51
  <a href="/with_simple_html"><img width="20" height="20" alt="fine image" /></a>
@@ -72,6 +73,10 @@ banana</textarea>
72
73
  <a id="visible" class="visibility">visible link</a>
73
74
  </div>
74
75
 
76
+ <div>
77
+ Number 42
78
+ </div>
79
+
75
80
  <ul>
76
81
  <li id="john_monkey">Monkey John</li>
77
82
  <li id="paul_monkey">Monkey Paul</li>
@@ -45,6 +45,7 @@
45
45
 
46
46
  <p>
47
47
  <a id="reload-link" href="#">Reload!</a>
48
+ <em>this won't change</em>
48
49
  <div id="reload-me"><em>waiting to be reloaded</em></div>
49
50
  </p>
50
51
 
@@ -1,3 +1,3 @@
1
1
  module Capybara
2
- VERSION = '2.0.0.beta2'
2
+ VERSION = '2.0.0.beta4'
3
3
  end
@@ -36,8 +36,8 @@ describe Capybara do
36
36
  Capybara.add_selector :lifeform do
37
37
  xpath { |name| "//option[contains(.,'#{name}')]" }
38
38
  end
39
- string.should have_selector(:page)
40
- string.should_not have_selector(:'does-not-exist')
39
+ string.should have_selector(:id, "page")
40
+ string.should_not have_selector(:id, 'does-not-exist')
41
41
  string.should have_selector(:lifeform, "Monkey")
42
42
  string.should_not have_selector(:lifeform, "Gorilla")
43
43
  end
@@ -42,5 +42,14 @@ describe Capybara do
42
42
  Capybara.server.should == server
43
43
  end
44
44
  end
45
+ end
45
46
 
47
+ describe Capybara::Session do
48
+ context 'with non-existant driver' do
49
+ it "should raise an error" do
50
+ expect {
51
+ Capybara::Session.new(:quox, TestApp).driver
52
+ }.to raise_error(Capybara::DriverNotFoundError)
53
+ end
54
+ end
46
55
  end
@@ -1,10 +1,22 @@
1
1
  require 'spec_helper'
2
2
  require 'capybara/dsl'
3
3
 
4
+ class TestClass
5
+ include Capybara::DSL
6
+ end
7
+
8
+ Capybara::SpecHelper.run_specs TestClass.new, "DSL", :skip => [
9
+ :js,
10
+ :screenshot,
11
+ :frames,
12
+ :windows
13
+ ]
14
+
4
15
  describe Capybara::DSL do
5
16
  after do
6
17
  Capybara.session_name = nil
7
18
  Capybara.default_driver = nil
19
+ Capybara.javascript_driver = nil
8
20
  Capybara.use_default_driver
9
21
  Capybara.app = TestApp
10
22
  end
@@ -98,13 +110,21 @@ describe Capybara::DSL do
98
110
  end
99
111
 
100
112
  describe '#using_wait_time' do
113
+ before do
114
+ @previous_wait_time = Capybara.default_wait_time
115
+ end
116
+
117
+ after do
118
+ Capybara.default_wait_time = @previous_wait_time
119
+ end
120
+
101
121
  it "should switch the wait time and switch it back" do
102
122
  in_block = nil
103
123
  Capybara.using_wait_time 6 do
104
124
  in_block = Capybara.default_wait_time
105
125
  end
106
126
  in_block.should == 6
107
- Capybara.default_wait_time.should == 0
127
+ Capybara.default_wait_time.should == @previous_wait_time
108
128
  end
109
129
 
110
130
  it "should ensure wait time is reset" do
@@ -113,11 +133,7 @@ describe Capybara::DSL do
113
133
  raise "hell"
114
134
  end
115
135
  end.to raise_error
116
- Capybara.default_wait_time.should == 0
117
- end
118
-
119
- after do
120
- Capybara.default_wait_time = 0
136
+ Capybara.default_wait_time.should == @previous_wait_time
121
137
  end
122
138
  end
123
139
 
@@ -211,10 +227,6 @@ describe Capybara::DSL do
211
227
  @session = Class.new { include Capybara::DSL }.new
212
228
  end
213
229
 
214
- it_should_behave_like "session"
215
- it_should_behave_like "session without javascript support"
216
- it_should_behave_like "session without screenshot support"
217
-
218
230
  it "should be possible to include it in another class" do
219
231
  klass = Class.new do
220
232
  include Capybara::DSL
@@ -1,5 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module TestSessions
4
+ RackTest = Capybara::Session.new(:rack_test, TestApp)
5
+ end
6
+
7
+ Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :skip => [
8
+ :js,
9
+ :screenshot,
10
+ :frames,
11
+ :windows
12
+ ]
13
+
3
14
  describe Capybara::Session do
4
15
  context 'with rack test driver' do
5
16
  before do
@@ -23,21 +34,21 @@ describe Capybara::Session do
23
34
  @session.driver.options[:respect_data_method] = true
24
35
  @session.visit "/with_html"
25
36
  @session.click_link "A link with data-method"
26
- @session.body.should include('The requested object was deleted')
37
+ @session.html.should include('The requested object was deleted')
27
38
  end
28
39
 
29
40
  it "should not use data-method if option is false" do
30
41
  @session.driver.options[:respect_data_method] = false
31
42
  @session.visit "/with_html"
32
43
  @session.click_link "A link with data-method"
33
- @session.body.should include('Not deleted')
44
+ @session.html.should include('Not deleted')
34
45
  end
35
46
 
36
47
  it "should use data-method if available even if it's capitalized" do
37
48
  @session.driver.options[:respect_data_method] = true
38
49
  @session.visit "/with_html"
39
50
  @session.click_link "A link with capitalized data-method"
40
- @session.body.should include('The requested object was deleted')
51
+ @session.html.should include('The requested object was deleted')
41
52
  end
42
53
 
43
54
  after do
@@ -50,16 +61,10 @@ describe Capybara::Session do
50
61
  it "should submit an empty form-data section if no file is submitted" do
51
62
  @session.visit("/form")
52
63
  @session.click_button("Upload Empty")
53
- @session.body.should include('Successfully ignored empty file field.')
64
+ @session.html.should include('Successfully ignored empty file field.')
54
65
  end
55
66
  end
56
67
  end
57
-
58
- it_should_behave_like "session"
59
- it_should_behave_like "session without javascript support"
60
- it_should_behave_like "session without screenshot support"
61
- it_should_behave_like "session with headers support"
62
- it_should_behave_like "session with status code support"
63
68
  end
64
69
  end
65
70
 
@@ -72,27 +77,27 @@ describe Capybara::RackTest::Driver do
72
77
  it 'should always set headers' do
73
78
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
74
79
  @driver.visit('/get_header')
75
- @driver.body.should include('foobar')
80
+ @driver.html.should include('foobar')
76
81
  end
77
82
 
78
83
  it 'should keep headers on link clicks' do
79
84
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
80
85
  @driver.visit('/header_links')
81
86
  @driver.find('.//a').first.click
82
- @driver.body.should include('foobar')
87
+ @driver.html.should include('foobar')
83
88
  end
84
89
 
85
90
  it 'should keep headers on form submit' do
86
91
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
87
92
  @driver.visit('/header_links')
88
93
  @driver.find('.//input').first.click
89
- @driver.body.should include('foobar')
94
+ @driver.html.should include('foobar')
90
95
  end
91
96
 
92
97
  it 'should keep headers on redirects' do
93
98
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
94
99
  @driver.visit('/get_header_via_redirect')
95
- @driver.body.should include('foobar')
100
+ @driver.html.should include('foobar')
96
101
  end
97
102
  end
98
103
 
@@ -102,15 +107,15 @@ describe Capybara::RackTest::Driver do
102
107
 
103
108
  @driver.visit('/redirect')
104
109
  @driver.response.header['Location'].should be_nil
105
- @driver.browser.current_url.should eq "#{@driver.browser.current_host}/landed"
110
+ @driver.browser.current_url.should match %r{/landed$}
106
111
  end
107
112
 
108
113
  it "is possible to not follow redirects" do
109
114
  @driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
110
115
 
111
116
  @driver.visit('/redirect')
112
- @driver.response.header['Location'].should eq "#{@driver.browser.current_host}/redirect_again"
113
- @driver.browser.current_url.should eq "#{@driver.browser.current_host}/redirect"
117
+ @driver.response.header['Location'].should match %r{/redirect_again$}
118
+ @driver.browser.current_url.should match %r{/redirect$}
114
119
  end
115
120
  end
116
121
 
@@ -122,13 +127,13 @@ describe Capybara::RackTest::Driver do
122
127
 
123
128
  it "should follow 5 redirects" do
124
129
  @driver.visit("/redirect/5/times")
125
- @driver.body.should include('redirection complete')
130
+ @driver.html.should include('redirection complete')
126
131
  end
127
132
 
128
133
  it "should not follow more than 6 redirects" do
129
- running do
134
+ expect do
130
135
  @driver.visit("/redirect/6/times")
131
- end.should raise_error(Capybara::InfiniteRedirectError)
136
+ end.to raise_error(Capybara::InfiniteRedirectError)
132
137
  end
133
138
  end
134
139
 
@@ -139,13 +144,13 @@ describe Capybara::RackTest::Driver do
139
144
 
140
145
  it "should follow 21 redirects" do
141
146
  @driver.visit("/redirect/21/times")
142
- @driver.body.should include('redirection complete')
147
+ @driver.html.should include('redirection complete')
143
148
  end
144
149
 
145
150
  it "should not follow more than 21 redirects" do
146
- running do
151
+ expect do
147
152
  @driver.visit("/redirect/22/times")
148
- end.should raise_error(Capybara::InfiniteRedirectError)
153
+ end.to raise_error(Capybara::InfiniteRedirectError)
149
154
  end
150
155
  end
151
156
  end