rcarvalho-capybara 0.4.1.1

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 (100) hide show
  1. data/History.txt +202 -0
  2. data/README.rdoc +540 -0
  3. data/lib/capybara.rb +231 -0
  4. data/lib/capybara/cucumber.rb +32 -0
  5. data/lib/capybara/driver/base.rb +60 -0
  6. data/lib/capybara/driver/celerity_driver.rb +164 -0
  7. data/lib/capybara/driver/culerity_driver.rb +26 -0
  8. data/lib/capybara/driver/node.rb +78 -0
  9. data/lib/capybara/driver/rack_test_driver.rb +303 -0
  10. data/lib/capybara/driver/selenium_driver.rb +165 -0
  11. data/lib/capybara/dsl.rb +109 -0
  12. data/lib/capybara/node/actions.rb +160 -0
  13. data/lib/capybara/node/base.rb +47 -0
  14. data/lib/capybara/node/document.rb +17 -0
  15. data/lib/capybara/node/element.rb +182 -0
  16. data/lib/capybara/node/finders.rb +201 -0
  17. data/lib/capybara/node/matchers.rb +391 -0
  18. data/lib/capybara/node/simple.rb +116 -0
  19. data/lib/capybara/rails.rb +17 -0
  20. data/lib/capybara/rspec.rb +18 -0
  21. data/lib/capybara/selector.rb +70 -0
  22. data/lib/capybara/server.rb +90 -0
  23. data/lib/capybara/session.rb +281 -0
  24. data/lib/capybara/spec/driver.rb +243 -0
  25. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  26. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  27. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  28. data/lib/capybara/spec/public/jquery.js +19 -0
  29. data/lib/capybara/spec/public/test.js +33 -0
  30. data/lib/capybara/spec/session.rb +110 -0
  31. data/lib/capybara/spec/session/all_spec.rb +78 -0
  32. data/lib/capybara/spec/session/attach_file_spec.rb +70 -0
  33. data/lib/capybara/spec/session/check_spec.rb +65 -0
  34. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  35. data/lib/capybara/spec/session/click_button_spec.rb +252 -0
  36. data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
  37. data/lib/capybara/spec/session/click_link_spec.rb +113 -0
  38. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  39. data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
  40. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  41. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  42. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  43. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  44. data/lib/capybara/spec/session/find_spec.rb +121 -0
  45. data/lib/capybara/spec/session/first_spec.rb +72 -0
  46. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  47. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  48. data/lib/capybara/spec/session/has_css_spec.rb +213 -0
  49. data/lib/capybara/spec/session/has_field_spec.rb +156 -0
  50. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  51. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  52. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  53. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  54. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  55. data/lib/capybara/spec/session/headers.rb +19 -0
  56. data/lib/capybara/spec/session/javascript.rb +223 -0
  57. data/lib/capybara/spec/session/response_code.rb +19 -0
  58. data/lib/capybara/spec/session/select_spec.rb +105 -0
  59. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  60. data/lib/capybara/spec/session/unselect_spec.rb +61 -0
  61. data/lib/capybara/spec/session/within_spec.rb +160 -0
  62. data/lib/capybara/spec/test_app.rb +117 -0
  63. data/lib/capybara/spec/views/buttons.erb +4 -0
  64. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  65. data/lib/capybara/spec/views/form.erb +348 -0
  66. data/lib/capybara/spec/views/frame_one.erb +8 -0
  67. data/lib/capybara/spec/views/frame_two.erb +8 -0
  68. data/lib/capybara/spec/views/popup_one.erb +8 -0
  69. data/lib/capybara/spec/views/popup_two.erb +8 -0
  70. data/lib/capybara/spec/views/postback.erb +13 -0
  71. data/lib/capybara/spec/views/tables.erb +122 -0
  72. data/lib/capybara/spec/views/with_html.erb +69 -0
  73. data/lib/capybara/spec/views/with_js.erb +39 -0
  74. data/lib/capybara/spec/views/with_scope.erb +36 -0
  75. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  76. data/lib/capybara/spec/views/within_frames.erb +10 -0
  77. data/lib/capybara/spec/views/within_popups.erb +25 -0
  78. data/lib/capybara/util/save_and_open_page.rb +40 -0
  79. data/lib/capybara/util/timeout.rb +27 -0
  80. data/lib/capybara/version.rb +3 -0
  81. data/spec/basic_node_spec.rb +77 -0
  82. data/spec/capybara_spec.rb +46 -0
  83. data/spec/driver/celerity_driver_spec.rb +13 -0
  84. data/spec/driver/culerity_driver_spec.rb +14 -0
  85. data/spec/driver/rack_test_driver_spec.rb +84 -0
  86. data/spec/driver/remote_culerity_driver_spec.rb +22 -0
  87. data/spec/driver/remote_selenium_driver_spec.rb +16 -0
  88. data/spec/driver/selenium_driver_spec.rb +14 -0
  89. data/spec/dsl_spec.rb +157 -0
  90. data/spec/rspec_spec.rb +47 -0
  91. data/spec/save_and_open_page_spec.rb +159 -0
  92. data/spec/server_spec.rb +85 -0
  93. data/spec/session/celerity_session_spec.rb +24 -0
  94. data/spec/session/culerity_session_spec.rb +26 -0
  95. data/spec/session/rack_test_session_spec.rb +44 -0
  96. data/spec/session/selenium_session_spec.rb +26 -0
  97. data/spec/spec_helper.rb +40 -0
  98. data/spec/string_spec.rb +77 -0
  99. data/spec/timeout_spec.rb +28 -0
  100. metadata +343 -0
@@ -0,0 +1,19 @@
1
+ shared_examples_for "session with headers support" do
2
+ describe '#response_headers' do
3
+ it "should return response headers" do
4
+ @session.visit('/with_simple_html')
5
+ @session.response_headers['Content-Type'].should =~ %r(text/html)
6
+ end
7
+ end
8
+ end
9
+
10
+ shared_examples_for "session without headers support" do
11
+ describe "#response_headers" do
12
+ before{ @session.visit('/with_simple_html') }
13
+ it "should raise an error" do
14
+ running {
15
+ @session.response_headers
16
+ }.should raise_error(Capybara::NotSupportedByDriverError)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,223 @@
1
+ shared_examples_for "session with javascript support" do
2
+ describe 'all JS specs' do
3
+ before do
4
+ Capybara.default_wait_time = 1
5
+ end
6
+
7
+ after do
8
+ Capybara.default_wait_time = 0
9
+ end
10
+
11
+ describe 'Node#drag_to' do
12
+ it "should drag and drop an object" do
13
+ pending "drag/drop is currently broken under celerity/culerity" if @session.driver.is_a?(Capybara::Driver::Celerity)
14
+ @session.visit('/with_js')
15
+ element = @session.find('//div[@id="drag"]')
16
+ target = @session.find('//div[@id="drop"]')
17
+ element.drag_to(target)
18
+ @session.find('//div[contains(., "Dropped!")]').should_not be_nil
19
+ end
20
+ end
21
+
22
+ describe '#find' do
23
+ it "should allow triggering of custom JS events" do
24
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
25
+ @session.visit('/with_js')
26
+ @session.find(:css, '#with_focus_event').trigger(:focus)
27
+ @session.should have_css('#focus_event_triggered')
28
+ end
29
+ end
30
+
31
+ describe '#body' do
32
+ it "should return the current state of the page" do
33
+ @session.visit('/with_js')
34
+ @session.body.should include('I changed it')
35
+ @session.body.should_not include('This is text')
36
+ end
37
+ end
38
+
39
+ describe '#source' do
40
+ it "should return the original, unmodified source of the page" do
41
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
42
+ @session.visit('/with_js')
43
+ @session.source.should include('This is text')
44
+ @session.source.should_not include('I changed it')
45
+ end
46
+ end
47
+
48
+ describe "#evaluate_script" do
49
+ it "should evaluate the given script and return whatever it produces" do
50
+ @session.visit('/with_js')
51
+ @session.evaluate_script("1+3").should == 4
52
+ end
53
+ end
54
+
55
+ describe "#execute_script" do
56
+ it "should execute the given script and return nothing" do
57
+ @session.visit('/with_js')
58
+ @session.execute_script("$('#change').text('Funky Doodle')").should be_nil
59
+ @session.should have_css('#change', :text => 'Funky Doodle')
60
+ end
61
+ end
62
+
63
+ describe '#find' do
64
+ it "should wait for asynchronous load" do
65
+ @session.visit('/with_js')
66
+ @session.click_link('Click me')
67
+ @session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
68
+ end
69
+ end
70
+
71
+ describe '#wait_until' do
72
+ before do
73
+ @default_timeout = Capybara.default_wait_time
74
+ end
75
+
76
+ after do
77
+ Capybara.default_wait_time = @default_wait_time
78
+ end
79
+
80
+ it "should wait for block to return true" do
81
+ @session.visit('/with_js')
82
+ @session.select('My Waiting Option', :from => 'waiter')
83
+ @session.evaluate_script('activeRequests == 1').should be_true
84
+ @session.wait_until do
85
+ @session.evaluate_script('activeRequests == 0')
86
+ end
87
+ @session.evaluate_script('activeRequests == 0').should be_true
88
+ end
89
+
90
+ it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
91
+ @session.visit('/with_html')
92
+ Proc.new do
93
+ @session.wait_until(0.1) do
94
+ @session.all('//div[@id="nosuchthing"]').first
95
+ end
96
+ end.should raise_error(::Capybara::TimeoutError)
97
+ end
98
+
99
+ it "should accept custom timeout in seconds" do
100
+ start = Time.now
101
+ Capybara.default_wait_time = 5
102
+ begin
103
+ @session.wait_until(0.1) { false }
104
+ rescue Capybara::TimeoutError; end
105
+ (Time.now - start).should be_within(0.1).of(0.1)
106
+ end
107
+
108
+ it "should default to Capybara.default_wait_time before timeout" do
109
+ @session.driver # init the driver to exclude init timing from test
110
+ start = Time.now
111
+ Capybara.default_wait_time = 0.2
112
+ begin
113
+ @session.wait_until { false }
114
+ rescue Capybara::TimeoutError; end
115
+ if @session.driver.has_shortcircuit_timeout?
116
+ (Time.now - start).should be_within(0.1).of(0)
117
+ else
118
+ (Time.now - start).should be_within(0.1).of(0.2)
119
+ end
120
+ end
121
+ end
122
+
123
+ describe '#click_link_or_button' do
124
+ it "should wait for asynchronous load" do
125
+ @session.visit('/with_js')
126
+ @session.click_link('Click me')
127
+ @session.click_link_or_button('Has been clicked')
128
+ end
129
+ end
130
+
131
+ describe '#click_link' do
132
+ it "should wait for asynchronous load" do
133
+ @session.visit('/with_js')
134
+ @session.click_link('Click me')
135
+ @session.click_link('Has been clicked')
136
+ end
137
+ end
138
+
139
+ describe '#click_button' do
140
+ it "should wait for asynchronous load" do
141
+ @session.visit('/with_js')
142
+ @session.click_link('Click me')
143
+ @session.click_button('New Here')
144
+ end
145
+ end
146
+
147
+ describe '#fill_in' do
148
+ it "should wait for asynchronous load" do
149
+ @session.visit('/with_js')
150
+ @session.click_link('Click me')
151
+ @session.fill_in('new_field', :with => 'Testing...')
152
+ end
153
+ end
154
+
155
+ describe '#check' do
156
+ it "should trigger associated events" do
157
+ @session.visit('/with_js')
158
+ @session.check('checkbox_with_event')
159
+ @session.should have_css('#checkbox_event_triggered');
160
+ end
161
+ end
162
+
163
+ describe '#has_xpath?' do
164
+ it "should wait for content to appear" do
165
+ @session.visit('/with_js')
166
+ @session.click_link('Click me')
167
+ @session.should have_xpath("//input[@type='submit' and @value='New Here']")
168
+ end
169
+ end
170
+
171
+ describe '#has_no_xpath?' do
172
+ it "should wait for content to disappear" do
173
+ @session.visit('/with_js')
174
+ @session.click_link('Click me')
175
+ @session.should have_no_xpath("//p[@id='change']")
176
+ end
177
+ end
178
+
179
+ describe '#has_css?' do
180
+ it "should wait for content to appear" do
181
+ @session.visit('/with_js')
182
+ @session.click_link('Click me')
183
+ @session.should have_css("input[type='submit'][value='New Here']")
184
+ end
185
+ end
186
+
187
+ describe '#has_no_xpath?' do
188
+ it "should wait for content to disappear" do
189
+ @session.visit('/with_js')
190
+ @session.click_link('Click me')
191
+ @session.should have_no_css("p#change")
192
+ end
193
+ end
194
+
195
+ describe '#has_content?' do
196
+ it "should wait for content to appear" do
197
+ @session.visit('/with_js')
198
+ @session.click_link('Click me')
199
+ @session.should have_content("Has been clicked")
200
+ end
201
+ end
202
+
203
+ describe '#has_no_content?' do
204
+ it "should wait for content to disappear" do
205
+ @session.visit('/with_js')
206
+ @session.click_link('Click me')
207
+ @session.should have_no_content("I changed it")
208
+ end
209
+ end
210
+
211
+ end
212
+ end
213
+
214
+ shared_examples_for "session without javascript support" do
215
+ describe "#evaluate_script" do
216
+ before{ @session.visit('/with_simple_html') }
217
+ it "should raise an error" do
218
+ running {
219
+ @session.evaluate_script('3 + 3')
220
+ }.should raise_error(Capybara::NotSupportedByDriverError)
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples_for "session with status code support" do
2
+ describe '#status_code' do
3
+ it "should return response codes" do
4
+ @session.visit('/with_simple_html')
5
+ @session.status_code.should == 200
6
+ end
7
+ end
8
+ end
9
+
10
+ shared_examples_for "session without status code support" do
11
+ describe "#status_code" do
12
+ before{ @session.visit('/with_simple_html') }
13
+ it "should raise an error" do
14
+ running {
15
+ @session.status_code
16
+ }.should raise_error(Capybara::NotSupportedByDriverError)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,105 @@
1
+ shared_examples_for "select" do
2
+ describe "#select" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should return value of the first option" do
8
+ @session.find_field('Title').value.should == 'Mrs'
9
+ end
10
+
11
+ it "should return value of the selected option" do
12
+ @session.select("Miss", :from => 'Title')
13
+ @session.find_field('Title').value.should == 'Miss'
14
+ end
15
+
16
+ it "should return the value attribute rather than content if present" do
17
+ @session.find_field('Locale').value.should == 'en'
18
+ end
19
+
20
+ it "should select an option from a select box by id" do
21
+ @session.select("Finish", :from => 'form_locale')
22
+ @session.click_button('awesome')
23
+ extract_results(@session)['locale'].should == 'fi'
24
+ end
25
+
26
+ it "should select an option from a select box by label" do
27
+ @session.select("Finish", :from => 'Locale')
28
+ @session.click_button('awesome')
29
+ extract_results(@session)['locale'].should == 'fi'
30
+ end
31
+
32
+ it "should select an option without giving a select box" do
33
+ @session.select("Mr")
34
+ @session.click_button('awesome')
35
+ extract_results(@session)['title'].should == 'Mr'
36
+ end
37
+
38
+ it "should favour exact matches to option labels" do
39
+ @session.select("Mr", :from => 'Title')
40
+ @session.click_button('awesome')
41
+ extract_results(@session)['title'].should == 'Mr'
42
+ end
43
+
44
+ it "should escape quotes" do
45
+ @session.select("John's made-up language", :from => 'Locale')
46
+ @session.click_button('awesome')
47
+ extract_results(@session)['locale'].should == 'jo'
48
+ end
49
+
50
+ it "should obey from" do
51
+ @session.select("Miss", :from => "Other title")
52
+ @session.click_button('awesome')
53
+ results = extract_results(@session)
54
+ results['other_title'].should == "Miss"
55
+ results['title'].should_not == "Miss"
56
+ end
57
+
58
+ it "show match labels with preceding or trailing whitespace" do
59
+ @session.select("Lojban", :from => 'Locale')
60
+ @session.click_button('awesome')
61
+ extract_results(@session)['locale'].should == 'jbo'
62
+ end
63
+
64
+ context "with a locator that doesn't exist" do
65
+ it "should raise an error" do
66
+ running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
67
+ end
68
+ end
69
+
70
+ context "with an option that doesn't exist" do
71
+ it "should raise an error" do
72
+ running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::ElementNotFound)
73
+ end
74
+ end
75
+
76
+ context "with multiple select" do
77
+ it "should return an empty value" do
78
+ @session.find_field('Language').value.should == []
79
+ end
80
+
81
+ it "should return value of the selected options" do
82
+ @session.select("Ruby", :from => 'Language')
83
+ @session.select("Javascript", :from => 'Language')
84
+ @session.find_field('Language').value.should include('Ruby', 'Javascript')
85
+ end
86
+
87
+ it "should select one option" do
88
+ @session.select("Ruby", :from => 'Language')
89
+ @session.click_button('awesome')
90
+ extract_results(@session)['languages'].should == ['Ruby']
91
+ end
92
+
93
+ it "should select multiple options" do
94
+ @session.select("Ruby", :from => 'Language')
95
+ @session.select("Javascript", :from => 'Language')
96
+ @session.click_button('awesome')
97
+ extract_results(@session)['languages'].should include('Ruby', 'Javascript')
98
+ end
99
+
100
+ it "should return value attribute rather than content if present" do
101
+ @session.find_field('Underwear').value.should include('thermal')
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,21 @@
1
+ shared_examples_for "uncheck" do
2
+ describe "#uncheck" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should uncheck a checkbox by id" do
8
+ @session.uncheck("form_pets_hamster")
9
+ @session.click_button('awesome')
10
+ extract_results(@session)['pets'].should include('dog')
11
+ extract_results(@session)['pets'].should_not include('hamster')
12
+ end
13
+
14
+ it "should uncheck a checkbox by label" do
15
+ @session.uncheck("Hamster")
16
+ @session.click_button('awesome')
17
+ extract_results(@session)['pets'].should include('dog')
18
+ extract_results(@session)['pets'].should_not include('hamster')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ shared_examples_for "unselect" do
2
+ describe "#unselect" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ context "with multiple select" do
8
+ it "should unselect an option from a select box by id" do
9
+ @session.unselect('Commando', :from => 'form_underwear')
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
12
+ extract_results(@session)['underwear'].should_not include('Commando')
13
+ end
14
+
15
+ it "should unselect an option without a select box" do
16
+ @session.unselect('Commando')
17
+ @session.click_button('awesome')
18
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
19
+ extract_results(@session)['underwear'].should_not include('Commando')
20
+ end
21
+
22
+ it "should unselect an option from a select box by label" do
23
+ @session.unselect('Commando', :from => 'Underwear')
24
+ @session.click_button('awesome')
25
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
26
+ extract_results(@session)['underwear'].should_not include('Commando')
27
+ end
28
+
29
+ it "should favour exact matches to option labels" do
30
+ @session.unselect("Briefs", :from => 'Underwear')
31
+ @session.click_button('awesome')
32
+ extract_results(@session)['underwear'].should include('Commando', 'Boxer Briefs')
33
+ extract_results(@session)['underwear'].should_not include('Briefs')
34
+ end
35
+
36
+ it "should escape quotes" do
37
+ @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
38
+ @session.click_button('awesome')
39
+ extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
40
+ end
41
+ end
42
+
43
+ context "with single select" do
44
+ it "should raise an error" do
45
+ running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
46
+ end
47
+ end
48
+
49
+ context "with a locator that doesn't exist" do
50
+ it "should raise an error" do
51
+ running { @session.unselect('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
52
+ end
53
+ end
54
+
55
+ context "with an option that doesn't exist" do
56
+ it "should raise an error" do
57
+ running { @session.unselect('Does not Exist', :from => 'form_underwear') }.should raise_error(Capybara::ElementNotFound)
58
+ end
59
+ end
60
+ end
61
+ end