bbc-capybara 1.1.2

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 (107) hide show
  1. data/History.txt +325 -0
  2. data/License.txt +22 -0
  3. data/README.md +815 -0
  4. data/lib/capybara.rb +368 -0
  5. data/lib/capybara/cucumber.rb +25 -0
  6. data/lib/capybara/driver/base.rb +64 -0
  7. data/lib/capybara/driver/node.rb +74 -0
  8. data/lib/capybara/dsl.rb +50 -0
  9. data/lib/capybara/node/actions.rb +146 -0
  10. data/lib/capybara/node/base.rb +63 -0
  11. data/lib/capybara/node/document.rb +25 -0
  12. data/lib/capybara/node/element.rb +201 -0
  13. data/lib/capybara/node/finders.rb +154 -0
  14. data/lib/capybara/node/matchers.rb +442 -0
  15. data/lib/capybara/node/simple.rb +132 -0
  16. data/lib/capybara/query.rb +63 -0
  17. data/lib/capybara/rack_test/browser.rb +126 -0
  18. data/lib/capybara/rack_test/driver.rb +80 -0
  19. data/lib/capybara/rack_test/form.rb +80 -0
  20. data/lib/capybara/rack_test/node.rb +121 -0
  21. data/lib/capybara/rails.rb +17 -0
  22. data/lib/capybara/rspec.rb +26 -0
  23. data/lib/capybara/rspec/features.rb +22 -0
  24. data/lib/capybara/rspec/matchers.rb +152 -0
  25. data/lib/capybara/selector.rb +156 -0
  26. data/lib/capybara/selenium/driver.rb +169 -0
  27. data/lib/capybara/selenium/node.rb +91 -0
  28. data/lib/capybara/server.rb +87 -0
  29. data/lib/capybara/session.rb +322 -0
  30. data/lib/capybara/spec/driver.rb +329 -0
  31. data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
  32. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  33. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  34. data/lib/capybara/spec/public/jquery.js +9046 -0
  35. data/lib/capybara/spec/public/test.js +43 -0
  36. data/lib/capybara/spec/session.rb +148 -0
  37. data/lib/capybara/spec/session/all_spec.rb +78 -0
  38. data/lib/capybara/spec/session/attach_file_spec.rb +76 -0
  39. data/lib/capybara/spec/session/check_spec.rb +68 -0
  40. data/lib/capybara/spec/session/choose_spec.rb +29 -0
  41. data/lib/capybara/spec/session/click_button_spec.rb +305 -0
  42. data/lib/capybara/spec/session/click_link_or_button_spec.rb +37 -0
  43. data/lib/capybara/spec/session/click_link_spec.rb +120 -0
  44. data/lib/capybara/spec/session/current_url_spec.rb +83 -0
  45. data/lib/capybara/spec/session/fill_in_spec.rb +127 -0
  46. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  47. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  48. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  49. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  50. data/lib/capybara/spec/session/find_spec.rb +168 -0
  51. data/lib/capybara/spec/session/first_spec.rb +105 -0
  52. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  53. data/lib/capybara/spec/session/has_css_spec.rb +243 -0
  54. data/lib/capybara/spec/session/has_field_spec.rb +192 -0
  55. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  56. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  57. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  58. data/lib/capybara/spec/session/has_table_spec.rb +34 -0
  59. data/lib/capybara/spec/session/has_text_spec.rb +138 -0
  60. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  61. data/lib/capybara/spec/session/headers.rb +19 -0
  62. data/lib/capybara/spec/session/javascript.rb +312 -0
  63. data/lib/capybara/spec/session/response_code.rb +19 -0
  64. data/lib/capybara/spec/session/select_spec.rb +119 -0
  65. data/lib/capybara/spec/session/text_spec.rb +24 -0
  66. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  67. data/lib/capybara/spec/session/unselect_spec.rb +67 -0
  68. data/lib/capybara/spec/session/within_spec.rb +178 -0
  69. data/lib/capybara/spec/test_app.rb +156 -0
  70. data/lib/capybara/spec/views/buttons.erb +4 -0
  71. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  72. data/lib/capybara/spec/views/form.erb +366 -0
  73. data/lib/capybara/spec/views/frame_one.erb +8 -0
  74. data/lib/capybara/spec/views/frame_two.erb +8 -0
  75. data/lib/capybara/spec/views/header_links.erb +7 -0
  76. data/lib/capybara/spec/views/host_links.erb +12 -0
  77. data/lib/capybara/spec/views/popup_one.erb +8 -0
  78. data/lib/capybara/spec/views/popup_two.erb +8 -0
  79. data/lib/capybara/spec/views/postback.erb +13 -0
  80. data/lib/capybara/spec/views/tables.erb +62 -0
  81. data/lib/capybara/spec/views/with_html.erb +75 -0
  82. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  83. data/lib/capybara/spec/views/with_js.erb +53 -0
  84. data/lib/capybara/spec/views/with_scope.erb +36 -0
  85. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  86. data/lib/capybara/spec/views/within_frames.erb +10 -0
  87. data/lib/capybara/spec/views/within_popups.erb +25 -0
  88. data/lib/capybara/util/save_and_open_page.rb +45 -0
  89. data/lib/capybara/util/timeout.rb +27 -0
  90. data/lib/capybara/version.rb +3 -0
  91. data/spec/basic_node_spec.rb +89 -0
  92. data/spec/capybara_spec.rb +46 -0
  93. data/spec/driver/rack_test_driver_spec.rb +90 -0
  94. data/spec/driver/selenium_driver_spec.rb +55 -0
  95. data/spec/dsl_spec.rb +255 -0
  96. data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
  97. data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
  98. data/spec/rspec/features_spec.rb +43 -0
  99. data/spec/rspec/matchers_spec.rb +564 -0
  100. data/spec/rspec_spec.rb +51 -0
  101. data/spec/save_and_open_page_spec.rb +155 -0
  102. data/spec/server_spec.rb +74 -0
  103. data/spec/session/rack_test_session_spec.rb +61 -0
  104. data/spec/session/selenium_session_spec.rb +26 -0
  105. data/spec/spec_helper.rb +31 -0
  106. data/spec/timeout_spec.rb +28 -0
  107. metadata +297 -0
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara do
4
+
5
+ describe 'default_wait_time' do
6
+ after do
7
+ Capybara.default_wait_time = @previous_default_time
8
+ end
9
+
10
+ it "should be changeable" do
11
+ @previous_default_time = Capybara.default_wait_time
12
+ Capybara.default_wait_time = 5
13
+ Capybara.default_wait_time.should == 5
14
+ end
15
+ end
16
+
17
+ describe '.register_driver' do
18
+ it "should add a new driver" do
19
+ Capybara.register_driver :schmoo do |app|
20
+ Capybara::RackTest::Driver.new(app)
21
+ end
22
+ session = Capybara::Session.new(:schmoo, TestApp)
23
+ session.visit('/')
24
+ session.body.should include("Hello world!")
25
+ end
26
+ end
27
+
28
+ describe ".server" do
29
+ after do
30
+ Capybara.server {|app, port| Capybara.run_default_server(app, port)}
31
+ end
32
+
33
+ it "should default to a proc that calls run_default_server" do
34
+ mock_app = mock('app')
35
+ Capybara.should_receive(:run_default_server).with(mock_app, 8000)
36
+ Capybara.server.call(mock_app, 8000)
37
+ end
38
+
39
+ it "should return a custom server proc" do
40
+ server = lambda {|app, port|}
41
+ Capybara.server(&server)
42
+ Capybara.server.should == server
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'stringio'
4
+
5
+ def capture(*streams)
6
+ streams.map! { |stream| stream.to_s }
7
+ begin
8
+ result = StringIO.new
9
+ streams.each { |stream| eval "$#{stream} = result" }
10
+ yield
11
+ ensure
12
+ streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
13
+ end
14
+ result.string
15
+ end
16
+
17
+ describe Capybara::RackTest::Driver do
18
+ before do
19
+ @driver = TestSessions::RackTest.driver
20
+ end
21
+
22
+ it "should throw an error when no rack app is given" do
23
+ running do
24
+ Capybara::RackTest::Driver.new(nil)
25
+ end.should raise_error(ArgumentError)
26
+ end
27
+
28
+ it_should_behave_like "driver"
29
+ it_should_behave_like "driver with header support"
30
+ it_should_behave_like "driver with status code support"
31
+ it_should_behave_like "driver with cookies support"
32
+ it_should_behave_like "driver with infinite redirect detection"
33
+ it_should_behave_like "driver with referer support"
34
+
35
+ describe '#reset!' do
36
+ it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
37
+
38
+ it 'should reset headers' do
39
+ @driver.header('FOO', 'BAR')
40
+ @driver.visit('/get_header')
41
+ @driver.body.should include('BAR')
42
+
43
+ @driver.reset!
44
+ @driver.visit('/get_header')
45
+ @driver.body.should_not include('BAR')
46
+ end
47
+
48
+ it 'should reset response' do
49
+ @driver.visit('/foo')
50
+ lambda { @driver.response }.should_not raise_error
51
+ @driver.reset!
52
+ lambda { @driver.response }.should raise_error
53
+ end
54
+
55
+ it 'should request response' do
56
+ @driver.visit('/foo')
57
+ lambda { @driver.request }.should_not raise_error
58
+ @driver.reset!
59
+ lambda { @driver.request }.should raise_error
60
+ end
61
+ end
62
+
63
+ describe ':headers option' do
64
+ it 'should always set headers' do
65
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
66
+ @driver.visit('/get_header')
67
+ @driver.body.should include('foobar')
68
+ end
69
+
70
+ it 'should keep headers on link clicks' do
71
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
72
+ @driver.visit('/header_links')
73
+ @driver.find('.//a').first.click
74
+ @driver.body.should include('foobar')
75
+ end
76
+
77
+ it 'should keep headers on form submit' do
78
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
79
+ @driver.visit('/header_links')
80
+ @driver.find('.//input').first.click
81
+ @driver.body.should include('foobar')
82
+ end
83
+
84
+ it 'should keep headers on redirects' do
85
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
86
+ @driver.visit('/get_header_via_redirect')
87
+ @driver.body.should include('foobar')
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'rbconfig'
3
+
4
+ describe Capybara::Selenium::Driver do
5
+ before do
6
+ @driver = TestSessions::Selenium.driver
7
+ end
8
+
9
+ it_should_behave_like "driver"
10
+ it_should_behave_like "driver with javascript support"
11
+ it_should_behave_like "driver with resynchronization support"
12
+ it_should_behave_like "driver with frame support"
13
+ it_should_behave_like "driver with support for window switching"
14
+ it_should_behave_like "driver without status code support"
15
+ it_should_behave_like "driver with cookies support"
16
+ it_should_behave_like "driver with referer support"
17
+
18
+ unless Config::CONFIG['host_os'] =~ /mswin|mingw/
19
+ it "should not interfere with forking child processes" do
20
+ # Launch a browser, which registers the at_exit hook
21
+ browser = Capybara::Selenium::Driver.new(TestApp).browser
22
+
23
+ # Fork an unrelated child process. This should not run the code in the at_exit hook.
24
+ begin
25
+ pid = fork { "child" }
26
+ Process.wait2(pid)[1].exitstatus.should == 0
27
+ rescue NotImplementedError
28
+ # Fork unsupported (e.g. on JRuby)
29
+ end
30
+
31
+ browser.quit
32
+ end
33
+ end
34
+
35
+ describe "exit codes" do
36
+ before do
37
+ @current_dir = Dir.getwd
38
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
39
+ end
40
+
41
+ after do
42
+ Dir.chdir(@current_dir)
43
+ end
44
+
45
+ it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
46
+ `rspec spec/fixtures/selenium_driver_rspec_failure.rb`
47
+ $?.exitstatus.should be 1
48
+ end
49
+
50
+ it "should have return code 0 when running selenium_driver_rspec_success.rb" do
51
+ `rspec spec/fixtures/selenium_driver_rspec_success.rb`
52
+ $?.exitstatus.should be 0
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,255 @@
1
+ require 'spec_helper'
2
+ require 'capybara/dsl'
3
+
4
+ describe Capybara::DSL do
5
+ after do
6
+ Capybara.session_name = nil
7
+ Capybara.default_driver = nil
8
+ Capybara.use_default_driver
9
+ Capybara.app = TestApp
10
+ end
11
+
12
+ describe '#default_driver' do
13
+ it "should default to rack_test" do
14
+ Capybara.default_driver.should == :rack_test
15
+ end
16
+
17
+ it "should be changeable" do
18
+ Capybara.default_driver = :culerity
19
+ Capybara.default_driver.should == :culerity
20
+ end
21
+ end
22
+
23
+ describe '#current_driver' do
24
+ it "should default to the default driver" do
25
+ Capybara.current_driver.should == :rack_test
26
+ Capybara.default_driver = :culerity
27
+ Capybara.current_driver.should == :culerity
28
+ end
29
+
30
+ it "should be changeable" do
31
+ Capybara.current_driver = :culerity
32
+ Capybara.current_driver.should == :culerity
33
+ end
34
+ end
35
+
36
+ describe '#javascript_driver' do
37
+ it "should default to selenium" do
38
+ Capybara.javascript_driver.should == :selenium
39
+ end
40
+
41
+ it "should be changeable" do
42
+ Capybara.javascript_driver = :culerity
43
+ Capybara.javascript_driver.should == :culerity
44
+ end
45
+ end
46
+
47
+ describe '#use_default_driver' do
48
+ it "should restore the default driver" do
49
+ Capybara.current_driver = :culerity
50
+ Capybara.use_default_driver
51
+ Capybara.current_driver.should == :rack_test
52
+ end
53
+ end
54
+
55
+ describe '#using_driver' do
56
+ before do
57
+ Capybara.current_driver.should_not == :selenium
58
+ end
59
+
60
+ it 'should set the driver using Capybara.current_driver=' do
61
+ driver = nil
62
+ Capybara.using_driver(:selenium) { driver = Capybara.current_driver }
63
+ driver.should == :selenium
64
+ end
65
+
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
75
+ begin
76
+ Capybara.using_driver(:selenium) { raise "ohnoes!" }
77
+ rescue Exception
78
+ end
79
+ Capybara.current_driver.should == driver_before_block
80
+ end
81
+
82
+ it 'should return the driver to what it was previously' do
83
+ Capybara.current_driver = :selenium
84
+ Capybara.using_driver(:culerity) do
85
+ Capybara.using_driver(:rack_test) do
86
+ Capybara.current_driver.should == :rack_test
87
+ end
88
+ Capybara.current_driver.should == :culerity
89
+ end
90
+ Capybara.current_driver.should == :selenium
91
+ end
92
+
93
+ it 'should yield the passed block' do
94
+ called = false
95
+ Capybara.using_driver(:selenium) { called = true }
96
+ called.should == true
97
+ end
98
+ end
99
+
100
+ describe '#using_wait_time' do
101
+ it "should switch the wait time and switch it back" do
102
+ in_block = nil
103
+ Capybara.using_wait_time 6 do
104
+ in_block = Capybara.default_wait_time
105
+ end
106
+ in_block.should == 6
107
+ Capybara.default_wait_time.should == 0
108
+ end
109
+
110
+ it "should ensure wait time is reset" do
111
+ expect do
112
+ Capybara.using_wait_time 6 do
113
+ raise "hell"
114
+ end
115
+ end.to raise_error
116
+ Capybara.default_wait_time.should == 0
117
+ end
118
+
119
+ after do
120
+ Capybara.default_wait_time = 0
121
+ end
122
+ end
123
+
124
+ describe '#app' do
125
+ it "should be changeable" do
126
+ Capybara.app = "foobar"
127
+ Capybara.app.should == 'foobar'
128
+ end
129
+ end
130
+
131
+ describe '#current_session' do
132
+ it "should choose a session object of the current driver type" do
133
+ Capybara.current_session.should be_a(Capybara::Session)
134
+ end
135
+
136
+ it "should use #app as the application" do
137
+ Capybara.app = proc {}
138
+ Capybara.current_session.app.should == Capybara.app
139
+ end
140
+
141
+ it "should change with the current driver" do
142
+ Capybara.current_session.mode.should == :rack_test
143
+ Capybara.current_driver = :selenium
144
+ Capybara.current_session.mode.should == :selenium
145
+ end
146
+
147
+ it "should be persistent even across driver changes" do
148
+ object_id = Capybara.current_session.object_id
149
+ Capybara.current_session.object_id.should == object_id
150
+ Capybara.current_driver = :selenium
151
+ Capybara.current_session.mode.should == :selenium
152
+ Capybara.current_session.object_id.should_not == object_id
153
+
154
+ Capybara.current_driver = :rack_test
155
+ Capybara.current_session.object_id.should == object_id
156
+ end
157
+
158
+ it "should change when changing application" do
159
+ object_id = Capybara.current_session.object_id
160
+ Capybara.current_session.object_id.should == object_id
161
+ Capybara.app = proc {}
162
+ Capybara.current_session.object_id.should_not == object_id
163
+ Capybara.current_session.app.should == Capybara.app
164
+ end
165
+
166
+ it "should change when the session name changes" do
167
+ object_id = Capybara.current_session.object_id
168
+ Capybara.session_name = :administrator
169
+ Capybara.session_name.should == :administrator
170
+ Capybara.current_session.object_id.should_not == object_id
171
+ Capybara.session_name = :default
172
+ Capybara.session_name.should == :default
173
+ Capybara.current_session.object_id.should == object_id
174
+ end
175
+ end
176
+
177
+ describe "#using_session" do
178
+ it "should change the session name for the duration of the block" do
179
+ Capybara.session_name.should == :default
180
+ Capybara.using_session(:administrator) do
181
+ Capybara.session_name.should == :administrator
182
+ end
183
+ Capybara.session_name.should == :default
184
+ end
185
+
186
+ it "should reset the session to the default, even if an exception occurs" do
187
+ begin
188
+ Capybara.using_session(:raise) do
189
+ raise
190
+ end
191
+ rescue Exception
192
+ end
193
+ Capybara.session_name.should == :default
194
+ end
195
+
196
+ it "should yield the passed block" do
197
+ called = false
198
+ Capybara.using_session(:administrator) { called = true }
199
+ called.should == true
200
+ end
201
+ end
202
+
203
+ describe "#session_name" do
204
+ it "should default to :default" do
205
+ Capybara.session_name.should == :default
206
+ end
207
+ end
208
+
209
+ describe 'the DSL' do
210
+ before do
211
+ @session = Class.new { include Capybara::DSL }.new
212
+ end
213
+
214
+ it_should_behave_like "session"
215
+ it_should_behave_like "session without javascript support"
216
+
217
+ it "should be possible to include it in another class" do
218
+ klass = Class.new do
219
+ include Capybara::DSL
220
+ end
221
+ foo = klass.new
222
+ foo.visit('/with_html')
223
+ foo.click_link('ullamco')
224
+ foo.body.should include('Another World')
225
+ end
226
+
227
+ it "should provide a 'page' shortcut for more expressive tests" do
228
+ klass = Class.new do
229
+ include Capybara::DSL
230
+ end
231
+ foo = klass.new
232
+ foo.page.visit('/with_html')
233
+ foo.page.click_link('ullamco')
234
+ foo.page.body.should include('Another World')
235
+ end
236
+
237
+ it "should provide an 'using_session' shortcut" do
238
+ klass = Class.new do
239
+ include Capybara::DSL
240
+ end
241
+ Capybara.should_receive(:using_session).with(:name)
242
+ foo = klass.new
243
+ foo.using_session(:name)
244
+ end
245
+
246
+ it "should provide a 'using_wait_time' shortcut" do
247
+ klass = Class.new do
248
+ include Capybara::DSL
249
+ end
250
+ Capybara.should_receive(:using_wait_time).with(6)
251
+ foo = klass.new
252
+ foo.using_wait_time(6)
253
+ end
254
+ end
255
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Selenium::Driver do
4
+ it "should exit with a non-zero exit status" do
5
+ browser = Capybara::Selenium::Driver.new(TestApp).browser
6
+ true.should == false
7
+ end
8
+ end