david-capybara 0.3.8

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 (88) hide show
  1. data/History.txt +87 -0
  2. data/README.rdoc +389 -0
  3. data/lib/capybara.rb +52 -0
  4. data/lib/capybara/cucumber.rb +32 -0
  5. data/lib/capybara/driver/base.rb +48 -0
  6. data/lib/capybara/driver/celerity_driver.rb +143 -0
  7. data/lib/capybara/driver/culerity_driver.rb +25 -0
  8. data/lib/capybara/driver/rack_test_driver.rb +272 -0
  9. data/lib/capybara/driver/selenium_driver.rb +156 -0
  10. data/lib/capybara/dsl.rb +60 -0
  11. data/lib/capybara/node.rb +60 -0
  12. data/lib/capybara/rails.rb +17 -0
  13. data/lib/capybara/save_and_open_page.rb +33 -0
  14. data/lib/capybara/searchable.rb +54 -0
  15. data/lib/capybara/server.rb +114 -0
  16. data/lib/capybara/session.rb +262 -0
  17. data/lib/capybara/spec/driver.rb +162 -0
  18. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  19. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  20. data/lib/capybara/spec/public/canvas.jpg +0 -0
  21. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  22. data/lib/capybara/spec/public/jquery.js +19 -0
  23. data/lib/capybara/spec/public/test.js +33 -0
  24. data/lib/capybara/spec/session.rb +81 -0
  25. data/lib/capybara/spec/session/all_spec.rb +69 -0
  26. data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
  27. data/lib/capybara/spec/session/check_spec.rb +67 -0
  28. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  29. data/lib/capybara/spec/session/click_button_spec.rb +236 -0
  30. data/lib/capybara/spec/session/click_link_spec.rb +118 -0
  31. data/lib/capybara/spec/session/click_spec.rb +24 -0
  32. data/lib/capybara/spec/session/current_url_spec.rb +8 -0
  33. data/lib/capybara/spec/session/fill_in_spec.rb +108 -0
  34. data/lib/capybara/spec/session/find_button_spec.rb +16 -0
  35. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -0
  36. data/lib/capybara/spec/session/find_field_spec.rb +22 -0
  37. data/lib/capybara/spec/session/find_link_spec.rb +17 -0
  38. data/lib/capybara/spec/session/find_spec.rb +57 -0
  39. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  40. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  41. data/lib/capybara/spec/session/has_css_spec.rb +107 -0
  42. data/lib/capybara/spec/session/has_field_spec.rb +96 -0
  43. data/lib/capybara/spec/session/has_link_spec.rb +33 -0
  44. data/lib/capybara/spec/session/has_select_spec.rb +89 -0
  45. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  46. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  47. data/lib/capybara/spec/session/headers.rb +19 -0
  48. data/lib/capybara/spec/session/javascript.rb +204 -0
  49. data/lib/capybara/spec/session/locate_spec.rb +59 -0
  50. data/lib/capybara/spec/session/select_spec.rb +83 -0
  51. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  52. data/lib/capybara/spec/session/unselect_spec.rb +54 -0
  53. data/lib/capybara/spec/session/within_spec.rb +153 -0
  54. data/lib/capybara/spec/test_app.rb +75 -0
  55. data/lib/capybara/spec/views/buttons.erb +4 -0
  56. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  57. data/lib/capybara/spec/views/form.erb +235 -0
  58. data/lib/capybara/spec/views/frame_one.erb +8 -0
  59. data/lib/capybara/spec/views/frame_two.erb +8 -0
  60. data/lib/capybara/spec/views/postback.erb +13 -0
  61. data/lib/capybara/spec/views/tables.erb +122 -0
  62. data/lib/capybara/spec/views/with_html.erb +46 -0
  63. data/lib/capybara/spec/views/with_js.erb +39 -0
  64. data/lib/capybara/spec/views/with_scope.erb +36 -0
  65. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  66. data/lib/capybara/spec/views/within_frames.erb +10 -0
  67. data/lib/capybara/version.rb +3 -0
  68. data/lib/capybara/wait_until.rb +28 -0
  69. data/lib/capybara/xpath.rb +180 -0
  70. data/spec/capybara_spec.rb +18 -0
  71. data/spec/driver/celerity_driver_spec.rb +16 -0
  72. data/spec/driver/culerity_driver_spec.rb +12 -0
  73. data/spec/driver/rack_test_driver_spec.rb +17 -0
  74. data/spec/driver/remote_culerity_driver_spec.rb +23 -0
  75. data/spec/driver/remote_selenium_driver_spec.rb +18 -0
  76. data/spec/driver/selenium_driver_spec.rb +11 -0
  77. data/spec/dsl_spec.rb +140 -0
  78. data/spec/save_and_open_page_spec.rb +43 -0
  79. data/spec/searchable_spec.rb +66 -0
  80. data/spec/server_spec.rb +53 -0
  81. data/spec/session/celerity_session_spec.rb +27 -0
  82. data/spec/session/culerity_session_spec.rb +25 -0
  83. data/spec/session/rack_test_session_spec.rb +33 -0
  84. data/spec/session/selenium_session_spec.rb +25 -0
  85. data/spec/spec_helper.rb +19 -0
  86. data/spec/wait_until_spec.rb +28 -0
  87. data/spec/xpath_spec.rb +180 -0
  88. metadata +260 -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 == '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,204 @@
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 '#find' do
12
+ it "should allow triggering of custom JS events" do
13
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
14
+ @session.visit('/with_js')
15
+ @session.find(:css, '#with_focus_event').trigger(:focus)
16
+ @session.should have_css('#focus_event_triggered')
17
+ end
18
+ end
19
+
20
+ describe '#body' do
21
+ it "should return the current state of the page" do
22
+ @session.visit('/with_js')
23
+ @session.body.should include('I changed it')
24
+ @session.body.should_not include('This is text')
25
+ end
26
+ end
27
+
28
+ describe '#source' do
29
+ it "should return the original, unmodified source of the page" do
30
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
31
+ @session.visit('/with_js')
32
+ @session.source.should include('This is text')
33
+ @session.source.should_not include('I changed it')
34
+ end
35
+ end
36
+
37
+ describe "#evaluate_script" do
38
+ it "should return the evaluated script" do
39
+ @session.visit('/with_js')
40
+ @session.evaluate_script("1+3").should == 4
41
+ end
42
+ end
43
+
44
+ describe '#locate' do
45
+ it "should wait for asynchronous load" do
46
+ @session.visit('/with_js')
47
+ @session.click_link('Click me')
48
+ @session.locate("//a[contains(.,'Has been clicked')]")[:href].should == '#'
49
+ end
50
+ end
51
+
52
+ describe '#wait_until' do
53
+ before do
54
+ @default_timeout = Capybara.default_wait_time
55
+ end
56
+
57
+ after do
58
+ Capybara.default_wait_time = @default_wait_time
59
+ end
60
+
61
+ it "should wait for block to return true" do
62
+ @session.visit('/with_js')
63
+ @session.select('My Waiting Option', :from => 'waiter')
64
+ @session.evaluate_script('activeRequests == 1').should be_true
65
+ @session.wait_until do
66
+ @session.evaluate_script('activeRequests == 0')
67
+ end
68
+ @session.evaluate_script('activeRequests == 0').should be_true
69
+ end
70
+
71
+ it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
72
+ @session.visit('/with_html')
73
+ Proc.new do
74
+ @session.wait_until(0.1) do
75
+ @session.find('//div[@id="nosuchthing"]')
76
+ end
77
+ end.should raise_error(::Capybara::TimeoutError)
78
+ end
79
+
80
+ it "should accept custom timeout in seconds" do
81
+ start = Time.now
82
+ Capybara.default_wait_time = 5
83
+ begin
84
+ @session.wait_until(0.1) { false }
85
+ rescue Capybara::TimeoutError; end
86
+ (Time.now - start).should be_close(0.1, 0.1)
87
+ end
88
+
89
+ it "should default to Capybara.default_wait_time before timeout" do
90
+ @session.driver # init the driver to exclude init timing from test
91
+ start = Time.now
92
+ Capybara.default_wait_time = 0.2
93
+ begin
94
+ @session.wait_until { false }
95
+ rescue Capybara::TimeoutError; end
96
+ if @session.driver.has_shortcircuit_timeout?
97
+ (Time.now - start).should be_close(0, 0.1)
98
+ else
99
+ (Time.now - start).should be_close(0.2, 0.1)
100
+ end
101
+ end
102
+ end
103
+
104
+ describe '#click' do
105
+ it "should wait for asynchronous load" do
106
+ @session.visit('/with_js')
107
+ @session.click_link('Click me')
108
+ @session.click('Has been clicked')
109
+ end
110
+ end
111
+
112
+ describe '#click_link' do
113
+ it "should wait for asynchronous load" do
114
+ @session.visit('/with_js')
115
+ @session.click_link('Click me')
116
+ @session.click_link('Has been clicked')
117
+ end
118
+ end
119
+
120
+ describe '#click_button' do
121
+ it "should wait for asynchronous load" do
122
+ @session.visit('/with_js')
123
+ @session.click_link('Click me')
124
+ @session.click_button('New Here')
125
+ end
126
+ end
127
+
128
+ describe '#fill_in' do
129
+ it "should wait for asynchronous load" do
130
+ @session.visit('/with_js')
131
+ @session.click_link('Click me')
132
+ @session.fill_in('new_field', :with => 'Testing...')
133
+ end
134
+ end
135
+
136
+ describe '#check' do
137
+ it "should trigger associated events" do
138
+ @session.visit('/with_js')
139
+ @session.check('checkbox_with_event')
140
+ @session.should have_css('#checkbox_event_triggered');
141
+ end
142
+ end
143
+
144
+ describe '#has_xpath?' do
145
+ it "should wait for content to appear" do
146
+ @session.visit('/with_js')
147
+ @session.click_link('Click me')
148
+ @session.should have_xpath("//input[@type='submit' and @value='New Here']")
149
+ end
150
+ end
151
+
152
+ describe '#has_no_xpath?' do
153
+ it "should wait for content to disappear" do
154
+ @session.visit('/with_js')
155
+ @session.click_link('Click me')
156
+ @session.should have_no_xpath("//p[@id='change']")
157
+ end
158
+ end
159
+
160
+ describe '#has_css?' do
161
+ it "should wait for content to appear" do
162
+ @session.visit('/with_js')
163
+ @session.click_link('Click me')
164
+ @session.should have_css("input[type='submit'][value='New Here']")
165
+ end
166
+ end
167
+
168
+ describe '#has_no_xpath?' do
169
+ it "should wait for content to disappear" do
170
+ @session.visit('/with_js')
171
+ @session.click_link('Click me')
172
+ @session.should have_no_css("p#change")
173
+ end
174
+ end
175
+
176
+ describe '#has_content?' do
177
+ it "should wait for content to appear" do
178
+ @session.visit('/with_js')
179
+ @session.click_link('Click me')
180
+ @session.should have_content("Has been clicked")
181
+ end
182
+ end
183
+
184
+ describe '#has_no_content?' do
185
+ it "should wait for content to disappear" do
186
+ @session.visit('/with_js')
187
+ @session.click_link('Click me')
188
+ @session.should have_no_content("I changed it")
189
+ end
190
+ end
191
+
192
+ end
193
+ end
194
+
195
+ shared_examples_for "session without javascript support" do
196
+ describe "#evaluate_script" do
197
+ before{ @session.visit('/with_simple_html') }
198
+ it "should raise an error" do
199
+ running {
200
+ @session.evaluate_script('3 + 3')
201
+ }.should raise_error(Capybara::NotSupportedByDriverError)
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,59 @@
1
+ shared_examples_for "locate" do
2
+ describe '#locate' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should find the first element using the given locator" do
8
+ @session.locate('//h1').text.should == 'This is a test'
9
+ @session.locate("//input[@id='test_field']")[:value].should == 'monkey'
10
+ end
11
+
12
+ context "with css selectors" do
13
+ it "should find the first element using the given locator" do
14
+ @session.locate(:css, 'h1').text.should == 'This is a test'
15
+ @session.locate(:css, "input[id='test_field']")[:value].should == 'monkey'
16
+ end
17
+ end
18
+
19
+ context "with xpath selectors" do
20
+ it "should find the first element using the given locator" do
21
+ @session.locate(:xpath, '//h1').text.should == 'This is a test'
22
+ @session.locate(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
23
+ end
24
+ end
25
+
26
+ context "with css as default selector" do
27
+ before { Capybara.default_selector = :css }
28
+ it "should find the first element using the given locator" do
29
+ @session.locate('h1').text.should == 'This is a test'
30
+ @session.locate("input[id='test_field']")[:value].should == 'monkey'
31
+ end
32
+ after { Capybara.default_selector = :xpath }
33
+ end
34
+
35
+ it "should raise ElementNotFound with specified fail message if nothing was found" do
36
+ running do
37
+ @session.locate(:xpath, '//div[@id="nosuchthing"]', 'arghh').should be_nil
38
+ end.should raise_error(Capybara::ElementNotFound, "arghh")
39
+ end
40
+
41
+ it "should accept an XPath instance and respect the order of paths" do
42
+ @session.visit('/form')
43
+ @xpath = Capybara::XPath.text_field('Name')
44
+ @session.locate(@xpath).value.should == 'John Smith'
45
+ end
46
+
47
+ context "within a scope" do
48
+ before do
49
+ @session.visit('/with_scope')
50
+ end
51
+
52
+ it "should find the first element using the given locator" do
53
+ @session.within(:xpath, "//div[@id='for_bar']") do
54
+ @session.locate('//li').text.should =~ /With Simple HTML/
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,83 @@
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 select an option from a select box by id" do
17
+ @session.select("Finish", :from => 'form_locale')
18
+ @session.click_button('awesome')
19
+ extract_results(@session)['locale'].should == 'fi'
20
+ end
21
+
22
+ it "should select an option from a select box by label" do
23
+ @session.select("Finish", :from => 'Locale')
24
+ @session.click_button('awesome')
25
+ extract_results(@session)['locale'].should == 'fi'
26
+ end
27
+
28
+ it "should favour exact matches to option labels" do
29
+ @session.select("Mr", :from => 'Title')
30
+ @session.click_button('awesome')
31
+ extract_results(@session)['title'].should == 'Mr'
32
+ end
33
+
34
+ it "should escape quotes" do
35
+ @session.select("John's made-up language", :from => 'Locale')
36
+ @session.click_button('awesome')
37
+ extract_results(@session)['locale'].should == 'jo'
38
+ end
39
+
40
+ it "match labels with preceding or trailing whitespace" do
41
+ @session.select("Lojban", :from => 'Locale')
42
+ @session.click_button('awesome')
43
+ extract_results(@session)['locale'].should == 'jbo'
44
+ end
45
+
46
+ context "with a locator that doesn't exist" do
47
+ it "should raise an error" do
48
+ running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
49
+ end
50
+ end
51
+
52
+ context "with an option that doesn't exist" do
53
+ it "should raise an error" do
54
+ running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::OptionNotFound)
55
+ end
56
+ end
57
+
58
+ context "with multiple select" do
59
+ it "should return an empty value" do
60
+ @session.find_field('Language').value.should == []
61
+ end
62
+
63
+ it "should return value of the selected options" do
64
+ @session.select("Ruby", :from => 'Language')
65
+ @session.select("Javascript", :from => 'Language')
66
+ @session.find_field('Language').value.should include('Ruby', 'Javascript')
67
+ end
68
+
69
+ it "should select one option" do
70
+ @session.select("Ruby", :from => 'Language')
71
+ @session.click_button('awesome')
72
+ extract_results(@session)['languages'].should == ['Ruby']
73
+ end
74
+
75
+ it "should select multiple options" do
76
+ @session.select("Ruby", :from => 'Language')
77
+ @session.select("Javascript", :from => 'Language')
78
+ @session.click_button('awesome')
79
+ extract_results(@session)['languages'].should include('Ruby', 'Javascript')
80
+ end
81
+ end
82
+ end
83
+ 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,54 @@
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 from a select box by label" do
16
+ @session.unselect('Commando', :from => 'Underwear')
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 favour exact matches to option labels" do
23
+ @session.unselect("Briefs", :from => 'Underwear')
24
+ @session.click_button('awesome')
25
+ extract_results(@session)['underwear'].should include('Commando', 'Boxer Briefs')
26
+ extract_results(@session)['underwear'].should_not include('Briefs')
27
+ end
28
+
29
+ it "should escape quotes" do
30
+ @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
31
+ @session.click_button('awesome')
32
+ extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
33
+ end
34
+ end
35
+
36
+ context "with single select" do
37
+ it "should raise an error" do
38
+ running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
39
+ end
40
+ end
41
+
42
+ context "with a locator that doesn't exist" do
43
+ it "should raise an error" do
44
+ running { @session.unselect('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
45
+ end
46
+ end
47
+
48
+ context "with an option that doesn't exist" do
49
+ it "should raise an error" do
50
+ running { @session.unselect('Does not Exist', :from => 'form_underwear') }.should raise_error(Capybara::OptionNotFound)
51
+ end
52
+ end
53
+ end
54
+ end