capybara 1.1.4 → 2.0.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 (111) hide show
  1. data/{History.txt → History.md} +138 -0
  2. data/License.txt +22 -0
  3. data/README.md +850 -0
  4. data/lib/capybara/cucumber.rb +2 -5
  5. data/lib/capybara/driver/base.rb +6 -6
  6. data/lib/capybara/driver/node.rb +3 -2
  7. data/lib/capybara/dsl.rb +13 -124
  8. data/lib/capybara/helpers.rb +33 -0
  9. data/lib/capybara/node/actions.rb +16 -30
  10. data/lib/capybara/node/base.rb +56 -13
  11. data/lib/capybara/node/element.rb +18 -30
  12. data/lib/capybara/node/finders.rb +28 -90
  13. data/lib/capybara/node/matchers.rb +121 -73
  14. data/lib/capybara/node/simple.rb +13 -11
  15. data/lib/capybara/query.rb +78 -0
  16. data/lib/capybara/rack_test/browser.rb +27 -39
  17. data/lib/capybara/rack_test/driver.rb +13 -3
  18. data/lib/capybara/rack_test/node.rb +31 -2
  19. data/lib/capybara/result.rb +72 -0
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +33 -63
  22. data/lib/capybara/rspec.rb +7 -4
  23. data/lib/capybara/selector.rb +97 -34
  24. data/lib/capybara/selenium/driver.rb +15 -62
  25. data/lib/capybara/selenium/node.rb +14 -21
  26. data/lib/capybara/server.rb +32 -27
  27. data/lib/capybara/session.rb +90 -50
  28. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  29. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  30. data/lib/capybara/spec/public/jquery.js +9046 -0
  31. data/lib/capybara/spec/public/test.js +3 -0
  32. data/lib/capybara/spec/session/all_spec.rb +61 -59
  33. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
  35. data/lib/capybara/spec/session/body_spec.rb +21 -0
  36. data/lib/capybara/spec/session/check_spec.rb +68 -48
  37. data/lib/capybara/spec/session/choose_spec.rb +32 -18
  38. data/lib/capybara/spec/session/click_button_spec.rb +263 -232
  39. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
  40. data/lib/capybara/spec/session/click_link_spec.rb +96 -96
  41. data/lib/capybara/spec/session/current_url_spec.rb +88 -10
  42. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  43. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  44. data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
  45. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  46. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  47. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  48. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  49. data/lib/capybara/spec/session/find_spec.rb +93 -115
  50. data/lib/capybara/spec/session/first_spec.rb +51 -85
  51. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  52. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  53. data/lib/capybara/spec/session/has_field_spec.rb +170 -144
  54. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  55. data/lib/capybara/spec/session/has_select_spec.rb +161 -109
  56. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  57. data/lib/capybara/spec/session/has_table_spec.rb +22 -88
  58. data/lib/capybara/spec/session/has_text_spec.rb +195 -0
  59. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  60. data/lib/capybara/spec/session/headers.rb +4 -17
  61. data/lib/capybara/spec/session/html_spec.rb +15 -0
  62. data/lib/capybara/spec/session/node_spec.rb +205 -0
  63. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  64. data/lib/capybara/spec/session/response_code.rb +4 -17
  65. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  66. data/lib/capybara/spec/session/screenshot.rb +13 -0
  67. data/lib/capybara/spec/session/select_spec.rb +99 -88
  68. data/lib/capybara/spec/session/source_spec.rb +12 -0
  69. data/lib/capybara/spec/session/text_spec.rb +15 -12
  70. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  71. data/lib/capybara/spec/session/unselect_spec.rb +69 -58
  72. data/lib/capybara/spec/session/visit_spec.rb +74 -0
  73. data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
  74. data/lib/capybara/spec/session/within_spec.rb +118 -131
  75. data/lib/capybara/spec/session/within_window_spec.rb +38 -0
  76. data/lib/capybara/spec/spec_helper.rb +84 -0
  77. data/lib/capybara/spec/test_app.rb +32 -6
  78. data/lib/capybara/spec/views/form.erb +12 -10
  79. data/lib/capybara/spec/views/host_links.erb +2 -2
  80. data/lib/capybara/spec/views/tables.erb +6 -66
  81. data/lib/capybara/spec/views/with_html.erb +9 -4
  82. data/lib/capybara/spec/views/with_js.erb +11 -7
  83. data/lib/capybara/version.rb +1 -1
  84. data/lib/capybara.rb +125 -6
  85. data/spec/basic_node_spec.rb +17 -5
  86. data/spec/capybara_spec.rb +9 -0
  87. data/spec/dsl_spec.rb +31 -17
  88. data/spec/rack_test_spec.rb +157 -0
  89. data/spec/result_spec.rb +51 -0
  90. data/spec/rspec/features_spec.rb +19 -2
  91. data/spec/rspec/matchers_spec.rb +170 -89
  92. data/spec/rspec_spec.rb +1 -3
  93. data/spec/selenium_spec.rb +53 -0
  94. data/spec/server_spec.rb +37 -25
  95. data/spec/spec_helper.rb +1 -30
  96. metadata +39 -31
  97. data/README.rdoc +0 -722
  98. data/lib/capybara/spec/driver.rb +0 -301
  99. data/lib/capybara/spec/session/current_host_spec.rb +0 -68
  100. data/lib/capybara/spec/session/has_content_spec.rb +0 -106
  101. data/lib/capybara/spec/session/javascript.rb +0 -306
  102. data/lib/capybara/spec/session.rb +0 -154
  103. data/lib/capybara/util/save_and_open_page.rb +0 -44
  104. data/lib/capybara/util/timeout.rb +0 -27
  105. data/spec/driver/rack_test_driver_spec.rb +0 -89
  106. data/spec/driver/selenium_driver_spec.rb +0 -37
  107. data/spec/save_and_open_page_spec.rb +0 -155
  108. data/spec/session/rack_test_session_spec.rb +0 -55
  109. data/spec/session/selenium_session_spec.rb +0 -26
  110. data/spec/string_spec.rb +0 -77
  111. data/spec/timeout_spec.rb +0 -28
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
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
+
14
+ describe Capybara::Session do
15
+ context 'with rack test driver' do
16
+ before do
17
+ @session = TestSessions::RackTest
18
+ end
19
+
20
+ describe '#driver' do
21
+ it "should be a rack test driver" do
22
+ @session.driver.should be_an_instance_of(Capybara::RackTest::Driver)
23
+ end
24
+ end
25
+
26
+ describe '#mode' do
27
+ it "should remember the mode" do
28
+ @session.mode.should == :rack_test
29
+ end
30
+ end
31
+
32
+ describe '#click_link' do
33
+ it "should use data-method if option is true" do
34
+ @session.driver.options[:respect_data_method] = true
35
+ @session.visit "/with_html"
36
+ @session.click_link "A link with data-method"
37
+ @session.html.should include('The requested object was deleted')
38
+ end
39
+
40
+ it "should not use data-method if option is false" do
41
+ @session.driver.options[:respect_data_method] = false
42
+ @session.visit "/with_html"
43
+ @session.click_link "A link with data-method"
44
+ @session.html.should include('Not deleted')
45
+ end
46
+
47
+ it "should use data-method if available even if it's capitalized" do
48
+ @session.driver.options[:respect_data_method] = true
49
+ @session.visit "/with_html"
50
+ @session.click_link "A link with capitalized data-method"
51
+ @session.html.should include('The requested object was deleted')
52
+ end
53
+
54
+ after do
55
+ @session.driver.options[:respect_data_method] = false
56
+ end
57
+ end
58
+
59
+ describe "#attach_file" do
60
+ context "with multipart form" do
61
+ it "should submit an empty form-data section if no file is submitted" do
62
+ @session.visit("/form")
63
+ @session.click_button("Upload Empty")
64
+ @session.html.should include('Successfully ignored empty file field.')
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ describe Capybara::RackTest::Driver do
72
+ before do
73
+ @driver = TestSessions::RackTest.driver
74
+ end
75
+
76
+ describe ':headers option' do
77
+ it 'should always set headers' do
78
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
79
+ @driver.visit('/get_header')
80
+ @driver.html.should include('foobar')
81
+ end
82
+
83
+ it 'should keep headers on link clicks' do
84
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
85
+ @driver.visit('/header_links')
86
+ @driver.find('.//a').first.click
87
+ @driver.html.should include('foobar')
88
+ end
89
+
90
+ it 'should keep headers on form submit' do
91
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
92
+ @driver.visit('/header_links')
93
+ @driver.find('.//input').first.click
94
+ @driver.html.should include('foobar')
95
+ end
96
+
97
+ it 'should keep headers on redirects' do
98
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
99
+ @driver.visit('/get_header_via_redirect')
100
+ @driver.html.should include('foobar')
101
+ end
102
+ end
103
+
104
+ describe ':follow_redirects option' do
105
+ it "defaults to following redirects" do
106
+ @driver = Capybara::RackTest::Driver.new(TestApp)
107
+
108
+ @driver.visit('/redirect')
109
+ @driver.response.header['Location'].should be_nil
110
+ @driver.browser.current_url.should match %r{/landed$}
111
+ end
112
+
113
+ it "is possible to not follow redirects" do
114
+ @driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
115
+
116
+ @driver.visit('/redirect')
117
+ @driver.response.header['Location'].should match %r{/redirect_again$}
118
+ @driver.browser.current_url.should match %r{/redirect$}
119
+ end
120
+ end
121
+
122
+ describe ':redirect_limit option' do
123
+ context "with default redirect limit" do
124
+ before do
125
+ @driver = Capybara::RackTest::Driver.new(TestApp)
126
+ end
127
+
128
+ it "should follow 5 redirects" do
129
+ @driver.visit("/redirect/5/times")
130
+ @driver.html.should include('redirection complete')
131
+ end
132
+
133
+ it "should not follow more than 6 redirects" do
134
+ expect do
135
+ @driver.visit("/redirect/6/times")
136
+ end.to raise_error(Capybara::InfiniteRedirectError)
137
+ end
138
+ end
139
+
140
+ context "with 21 redirect limit" do
141
+ before do
142
+ @driver = Capybara::RackTest::Driver.new(TestApp, :redirect_limit => 21)
143
+ end
144
+
145
+ it "should follow 21 redirects" do
146
+ @driver.visit("/redirect/21/times")
147
+ @driver.html.should include('redirection complete')
148
+ end
149
+
150
+ it "should not follow more than 21 redirects" do
151
+ expect do
152
+ @driver.visit("/redirect/22/times")
153
+ end.to raise_error(Capybara::InfiniteRedirectError)
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Result do
4
+ let :string do
5
+ Capybara.string <<-STRING
6
+ <ul>
7
+ <li>Alpha</li>
8
+ <li>Beta</li>
9
+ <li>Gamma</li>
10
+ <li>Delta</li>
11
+ </ul>
12
+ STRING
13
+ end
14
+
15
+ let :result do
16
+ string.all '//li'
17
+ end
18
+
19
+ it "has a length" do
20
+ result.length.should == 4
21
+ end
22
+
23
+ it "has a first element" do
24
+ result.first.text == 'Alpha'
25
+ end
26
+
27
+ it "has a last element" do
28
+ result.last.text == 'Delta'
29
+ end
30
+
31
+ it "can return an element by its index" do
32
+ result.at(1).text.should == 'Beta'
33
+ result[2].text.should == 'Gamma'
34
+ end
35
+
36
+ it "can be mapped" do
37
+ result.map(&:text).should == %w(Alpha Beta Gamma Delta)
38
+ end
39
+
40
+ it "can be selected" do
41
+ result.select do |element|
42
+ element.text.include? 't'
43
+ end.length.should == 2
44
+ end
45
+
46
+ it "can be reduced" do
47
+ result.reduce('') do |memo, element|
48
+ memo += element.text[0]
49
+ end.should == 'ABGD'
50
+ end
51
+ end
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'capybara/rspec'
3
3
 
4
- Capybara.app = TestApp
5
-
6
4
  RSpec.configuration.before(:each, :example_group => {:file_path => "./spec/rspec/features_spec.rb"}) do
7
5
  @in_filtered_hook = true
8
6
  end
@@ -38,6 +36,25 @@ feature "Capybara's feature DSL" do
38
36
  end
39
37
  end
40
38
 
39
+ feature "given and given! aliases to let and let!" do
40
+ given(:value) { :available }
41
+ given!(:value_in_background) { :available }
42
+
43
+ background do
44
+ value_in_background.should be(:available)
45
+ end
46
+
47
+ scenario "given and given! work as intended" do
48
+ value.should be(:available)
49
+ value_in_background.should be(:available)
50
+ end
51
+ end
52
+
53
+ feature "if xscenario aliases to pending then" do
54
+ xscenario "this test should be 'temporarily disabled with xscenario'" do
55
+ end
56
+ end
57
+
41
58
  feature "Capybara's feature DSL with driver", :driver => :culerity do
42
59
  scenario "switches driver" do
43
60
  Capybara.current_driver.should == :culerity