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
@@ -1,129 +1,181 @@
1
- shared_examples_for "has_select" do
2
- describe '#has_select?' do
3
- before { @session.visit('/form') }
4
-
5
- it "should be true if the field is on the page" do
6
- @session.should have_select('Locale')
7
- @session.should have_select('form_region')
8
- @session.should have_select('Languages')
9
- end
10
-
11
- it "should be false if the field is not on the page" do
12
- @session.should_not have_select('Monkey')
13
- end
14
-
15
- context 'with selected value' do
16
- it "should be true if a field with the given value is on the page" do
17
- @session.should have_select('form_locale', :selected => 'English')
18
- @session.should have_select('Region', :selected => 'Norway')
19
- @session.should have_select('Underwear', :selected => ['Briefs', 'Commando'])
20
- end
21
-
22
- it "should be false if the given field is not on the page" do
23
- @session.should_not have_select('Locale', :selected => 'Swedish')
24
- @session.should_not have_select('Does not exist', :selected => 'John')
25
- @session.should_not have_select('City', :selected => 'Not there')
26
- @session.should_not have_select('Underwear', :selected => ['Briefs', 'Nonexistant'])
27
- @session.should_not have_select('Underwear', :selected => ['Briefs', 'Boxers'])
28
- end
29
-
30
- it "should be true after the given value is selected" do
31
- @session.select('Swedish', :from => 'Locale')
32
- @session.should have_select('Locale', :selected => 'Swedish')
33
- end
34
-
35
- it "should be false after a different value is selected" do
36
- @session.select('Swedish', :from => 'Locale')
37
- @session.should_not have_select('Locale', :selected => 'English')
38
- end
39
-
40
- it "should be true after the given values are selected" do
41
- @session.select('Boxers', :from => 'Underwear')
42
- @session.should have_select('Underwear', :selected => ['Briefs', 'Boxers', 'Commando'])
43
- end
44
-
45
- it "should be false after one of the values is unselected" do
46
- @session.unselect('Briefs', :from => 'Underwear')
47
- @session.should_not have_select('Underwear', :selected => ['Briefs', 'Commando'])
48
- end
49
- end
50
-
51
- context 'with options' do
52
- it "should be true if a field with the given options is on the page" do
53
- @session.should have_select('form_locale', :options => ['English'])
54
- @session.should have_select('Region', :options => ['Norway', 'Sweden'])
55
- end
56
-
57
- it "should be false if the given field is not on the page" do
58
- @session.should_not have_select('Locale', :options => ['Not there'])
59
- @session.should_not have_select('Does not exist', :options => ['John'])
60
- @session.should_not have_select('City', :options => ['London', 'Made up city'])
61
- end
62
- end
1
+ Capybara::SpecHelper.spec '#has_select?' do
2
+ before { @session.visit('/form') }
3
+
4
+ it "should be true if the field is on the page" do
5
+ @session.should have_select('Locale')
6
+ @session.should have_select('form_region')
7
+ @session.should have_select('Languages')
8
+ @session.should have_select(:'Languages')
63
9
  end
64
10
 
65
- describe '#has_no_select?' do
66
- before { @session.visit('/form') }
11
+ it "should be false if the field is not on the page" do
12
+ @session.should_not have_select('Monkey')
13
+ end
67
14
 
68
- it "should be false if the field is on the page" do
69
- @session.should_not have_no_select('Locale')
70
- @session.should_not have_no_select('form_region')
71
- @session.should_not have_no_select('Languages')
15
+ context 'with selected value' do
16
+ it "should be true if a field with the given value is on the page" do
17
+ @session.should have_select('form_locale', :selected => 'English')
18
+ @session.should have_select('Region', :selected => 'Norway')
19
+ @session.should have_select('Underwear', :selected => [
20
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
21
+ ])
72
22
  end
73
23
 
74
- it "should be true if the field is not on the page" do
75
- @session.should have_no_select('Monkey')
24
+ it "should be false if the given field is not on the page" do
25
+ @session.should_not have_select('Locale', :selected => 'Swedish')
26
+ @session.should_not have_select('Does not exist', :selected => 'John')
27
+ @session.should_not have_select('City', :selected => 'Not there')
28
+ @session.should_not have_select('Underwear', :selected => [
29
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistant'
30
+ ])
31
+ @session.should_not have_select('Underwear', :selected => [
32
+ 'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
33
+ ])
34
+ @session.should_not have_select('Underwear', :selected => [
35
+ 'Boxerbriefs', 'Briefs','Commando', "Frenchman's Pantalons"
36
+ ])
76
37
  end
77
38
 
78
- context 'with selected value' do
79
- it "should be false if a field with the given value is on the page" do
80
- @session.should_not have_no_select('form_locale', :selected => 'English')
81
- @session.should_not have_no_select('Region', :selected => 'Norway')
82
- @session.should_not have_no_select('Underwear', :selected => ['Briefs', 'Commando'])
83
- end
39
+ it "should be true after the given value is selected" do
40
+ @session.select('Swedish', :from => 'Locale')
41
+ @session.should have_select('Locale', :selected => 'Swedish')
42
+ end
84
43
 
85
- it "should be true if the given field is not on the page" do
86
- @session.should have_no_select('Locale', :selected => 'Swedish')
87
- @session.should have_no_select('Does not exist', :selected => 'John')
88
- @session.should have_no_select('City', :selected => 'Not there')
89
- @session.should have_no_select('Underwear', :selected => ['Briefs', 'Nonexistant'])
90
- @session.should have_no_select('Underwear', :selected => ['Briefs', 'Boxers'])
91
- end
44
+ it "should be false after a different value is selected" do
45
+ @session.select('Swedish', :from => 'Locale')
46
+ @session.should_not have_select('Locale', :selected => 'English')
47
+ end
92
48
 
93
- it "should be false after the given value is selected" do
94
- @session.select('Swedish', :from => 'Locale')
95
- @session.should_not have_no_select('Locale', :selected => 'Swedish')
96
- end
49
+ it "should be true after the given values are selected" do
50
+ @session.select('Boxers', :from => 'Underwear')
51
+ @session.should have_select('Underwear', :selected => [
52
+ 'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
53
+ ])
54
+ end
97
55
 
98
- it "should be true after a different value is selected" do
99
- @session.select('Swedish', :from => 'Locale')
100
- @session.should have_no_select('Locale', :selected => 'English')
101
- end
56
+ it "should be false after one of the values is unselected" do
57
+ @session.unselect('Briefs', :from => 'Underwear')
58
+ @session.should_not have_select('Underwear', :selected => [
59
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
60
+ ])
61
+ end
62
+ end
102
63
 
103
- it "should be false after the given values are selected" do
104
- @session.select('Boxers', :from => 'Underwear')
105
- @session.should_not have_no_select('Underwear', :selected => ['Briefs', 'Boxers', 'Commando'])
106
- end
64
+ context 'with exact options' do
65
+ it "should be true if a field with the given options is on the page" do
66
+ @session.should have_select('Region', :options => ['Norway', 'Sweden', 'Finland'])
67
+ @session.should have_select('Tendency', :options => [])
68
+ end
107
69
 
108
- it "should be true after one of the values is unselected" do
109
- @session.unselect('Briefs', :from => 'Underwear')
110
- @session.should have_no_select('Underwear', :selected => ['Briefs', 'Commando'])
111
- end
70
+ it "should be false if the given field is not on the page" do
71
+ @session.should_not have_select('Locale', :options => ['Swedish'])
72
+ @session.should_not have_select('Does not exist', :options => ['John'])
73
+ @session.should_not have_select('City', :options => ['London', 'Made up city'])
74
+ @session.should_not have_select('Region', :options => ['Norway', 'Sweden'])
75
+ @session.should_not have_select('Region', :options => ['Norway', 'Norway', 'Norway'])
112
76
  end
77
+ end
113
78
 
114
- context 'with options' do
115
- it "should be false if a field with the given options is on the page" do
116
- @session.should_not have_no_select('form_locale', :options => ['English'])
117
- @session.should_not have_no_select('Region', :options => ['Norway', 'Sweden'])
118
- end
79
+ context 'with partial options' do
80
+ it "should be true if a field with the given partial options is on the page" do
81
+ @session.should have_select('Region', :with_options => ['Norway', 'Sweden'])
82
+ @session.should have_select('City', :with_options => ['London'])
83
+ end
119
84
 
120
- it "should be true if the given field is not on the page" do
121
- @session.should have_no_select('Locale', :options => ['Not there'])
122
- @session.should have_no_select('Does not exist', :options => ['John'])
123
- @session.should have_no_select('City', :options => ['London', 'Made up city'])
124
- end
85
+ it "should be false if a field with the given partial options is not on the page" do
86
+ @session.should_not have_select('Locale', :with_options => ['Uruguayan'])
87
+ @session.should_not have_select('Does not exist', :with_options => ['John'])
88
+ @session.should_not have_select('Region', :with_options => ['Norway', 'Sweden', 'Finland', 'Latvia'])
125
89
  end
126
90
  end
127
91
  end
128
92
 
93
+ Capybara::SpecHelper.spec '#has_no_select?' do
94
+ before { @session.visit('/form') }
129
95
 
96
+ it "should be false if the field is on the page" do
97
+ @session.should_not have_no_select('Locale')
98
+ @session.should_not have_no_select('form_region')
99
+ @session.should_not have_no_select('Languages')
100
+ end
101
+
102
+ it "should be true if the field is not on the page" do
103
+ @session.should have_no_select('Monkey')
104
+ end
105
+
106
+ context 'with selected value' do
107
+ it "should be false if a field with the given value is on the page" do
108
+ @session.should_not have_no_select('form_locale', :selected => 'English')
109
+ @session.should_not have_no_select('Region', :selected => 'Norway')
110
+ @session.should_not have_no_select('Underwear', :selected => [
111
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
112
+ ])
113
+ end
114
+
115
+ it "should be true if the given field is not on the page" do
116
+ @session.should have_no_select('Locale', :selected => 'Swedish')
117
+ @session.should have_no_select('Does not exist', :selected => 'John')
118
+ @session.should have_no_select('City', :selected => 'Not there')
119
+ @session.should have_no_select('Underwear', :selected => [
120
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistant'
121
+ ])
122
+ @session.should have_no_select('Underwear', :selected => [
123
+ 'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
124
+ ])
125
+ @session.should have_no_select('Underwear', :selected => [
126
+ 'Boxerbriefs', 'Briefs','Commando', "Frenchman's Pantalons"
127
+ ])
128
+ end
129
+
130
+ it "should be false after the given value is selected" do
131
+ @session.select('Swedish', :from => 'Locale')
132
+ @session.should_not have_no_select('Locale', :selected => 'Swedish')
133
+ end
134
+
135
+ it "should be true after a different value is selected" do
136
+ @session.select('Swedish', :from => 'Locale')
137
+ @session.should have_no_select('Locale', :selected => 'English')
138
+ end
139
+
140
+ it "should be false after the given values are selected" do
141
+ @session.select('Boxers', :from => 'Underwear')
142
+ @session.should_not have_no_select('Underwear', :selected => [
143
+ 'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
144
+ ])
145
+ end
146
+
147
+ it "should be true after one of the values is unselected" do
148
+ @session.unselect('Briefs', :from => 'Underwear')
149
+ @session.should have_no_select('Underwear', :selected => [
150
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
151
+ ])
152
+ end
153
+ end
154
+
155
+ context 'with exact options' do
156
+ it "should be false if a field with the given options is on the page" do
157
+ @session.should_not have_no_select('Region', :options => ['Norway', 'Sweden', 'Finland'])
158
+ end
159
+
160
+ it "should be true if the given field is not on the page" do
161
+ @session.should have_no_select('Locale', :options => ['Swedish'])
162
+ @session.should have_no_select('Does not exist', :options => ['John'])
163
+ @session.should have_no_select('City', :options => ['London', 'Made up city'])
164
+ @session.should have_no_select('Region', :options => ['Norway', 'Sweden'])
165
+ @session.should have_no_select('Region', :options => ['Norway', 'Norway', 'Norway'])
166
+ end
167
+ end
168
+
169
+ context 'with partial options' do
170
+ it "should be false if a field with the given partial options is on the page" do
171
+ @session.should_not have_no_select('Region', :with_options => ['Norway', 'Sweden'])
172
+ @session.should_not have_no_select('City', :with_options => ['London'])
173
+ end
174
+
175
+ it "should be true if a field with the given partial options is not on the page" do
176
+ @session.should have_no_select('Locale', :with_options => ['Uruguayan'])
177
+ @session.should have_no_select('Does not exist', :with_options => ['John'])
178
+ @session.should have_no_select('Region', :with_options => ['Norway', 'Sweden', 'Finland', 'Latvia'])
179
+ end
180
+ end
181
+ end
@@ -1,129 +1,123 @@
1
- shared_examples_for "has_selector" do
2
- describe '#has_selector?' do
3
- before do
4
- @session.visit('/with_html')
1
+ Capybara::SpecHelper.spec '#has_selector?' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
5
+
6
+ it "should be true if the given selector is on the page" do
7
+ @session.should have_selector(:xpath, "//p")
8
+ @session.should have_selector(:css, "p a#foo")
9
+ @session.should have_selector("//p[contains(.,'est')]")
10
+ end
11
+
12
+ it "should be false if the given selector is not on the page" do
13
+ @session.should_not have_selector(:xpath, "//abbr")
14
+ @session.should_not have_selector(:css, "p a#doesnotexist")
15
+ @session.should_not have_selector("//p[contains(.,'thisstringisnotonpage')]")
16
+ end
17
+
18
+ it "should use default selector" do
19
+ Capybara.default_selector = :css
20
+ @session.should_not have_selector("p a#doesnotexist")
21
+ @session.should have_selector("p a#foo")
22
+ end
23
+
24
+ it "should respect scopes" do
25
+ @session.within "//p[@id='first']" do
26
+ @session.should have_selector(".//a[@id='foo']")
27
+ @session.should_not have_selector(".//a[@id='red']")
5
28
  end
29
+ end
6
30
 
7
- it "should be true if the given selector is on the page" do
8
- @session.should have_selector(:xpath, "//p")
9
- @session.should have_selector(:css, "p a#foo")
10
- @session.should have_selector(:foo)
11
- @session.should have_selector("//p[contains(.,'est')]")
31
+ context "with count" do
32
+ it "should be true if the content is on the page the given number of times" do
33
+ @session.should have_selector("//p", :count => 3)
34
+ @session.should have_selector("//p//a[@id='foo']", :count => 1)
35
+ @session.should have_selector("//p[contains(.,'est')]", :count => 1)
12
36
  end
13
37
 
14
- it "should be false if the given selector is not on the page" do
15
- @session.should_not have_selector(:xpath, "//abbr")
16
- @session.should_not have_selector(:css, "p a#doesnotexist")
17
- @session.should_not have_selector(:doesnotexist)
18
- @session.should_not have_selector("//p[contains(.,'thisstringisnotonpage')]")
38
+ it "should be false if the content is on the page the given number of times" do
39
+ @session.should_not have_selector("//p", :count => 6)
40
+ @session.should_not have_selector("//p//a[@id='foo']", :count => 2)
41
+ @session.should_not have_selector("//p[contains(.,'est')]", :count => 5)
19
42
  end
20
43
 
21
- it "should use default selector" do
22
- Capybara.default_selector = :css
23
- @session.should_not have_selector("p a#doesnotexist")
24
- @session.should have_selector("p a#foo")
44
+ it "should be false if the content isn't on the page at all" do
45
+ @session.should_not have_selector("//abbr", :count => 2)
46
+ @session.should_not have_selector("//p//a[@id='doesnotexist']", :count => 1)
25
47
  end
48
+ end
26
49
 
27
- it "should respect scopes" do
28
- @session.within "//p[@id='first']" do
29
- @session.should have_selector(".//a[@id='foo']")
30
- @session.should_not have_selector(".//a[@id='red']")
31
- end
50
+ context "with text" do
51
+ it "should discard all matches where the given string is not contained" do
52
+ @session.should have_selector("//p//a", :text => "Redirect", :count => 1)
53
+ @session.should_not have_selector("//p", :text => "Doesnotexist")
32
54
  end
33
55
 
34
- context "with count" do
35
- it "should be true if the content is on the page the given number of times" do
36
- @session.should have_selector("//p", :count => 3)
37
- @session.should have_selector("//p//a[@id='foo']", :count => 1)
38
- @session.should have_selector("//p[contains(.,'est')]", :count => 1)
39
- end
40
-
41
- it "should be false if the content is on the page the given number of times" do
42
- @session.should_not have_selector("//p", :count => 6)
43
- @session.should_not have_selector("//p//a[@id='foo']", :count => 2)
44
- @session.should_not have_selector("//p[contains(.,'est')]", :count => 5)
45
- end
46
-
47
- it "should be false if the content isn't on the page at all" do
48
- @session.should_not have_selector("//abbr", :count => 2)
49
- @session.should_not have_selector("//p//a[@id='doesnotexist']", :count => 1)
50
- end
56
+ it "should discard all matches where the given regexp is not matched" do
57
+ @session.should have_selector("//p//a", :text => /re[dab]i/i, :count => 1)
58
+ @session.should_not have_selector("//p//a", :text => /Red$/)
51
59
  end
60
+ end
61
+ end
52
62
 
53
- context "with text" do
54
- it "should discard all matches where the given string is not contained" do
55
- @session.should have_selector("//p//a", :text => "Redirect", :count => 1)
56
- @session.should_not have_selector("//p", :text => "Doesnotexist")
57
- end
63
+ Capybara::SpecHelper.spec '#has_no_selector?' do
64
+ before do
65
+ @session.visit('/with_html')
66
+ end
58
67
 
59
- it "should discard all matches where the given regexp is not matched" do
60
- @session.should have_selector("//p//a", :text => /re[dab]i/i, :count => 1)
61
- @session.should_not have_selector("//p//a", :text => /Red$/)
62
- end
63
- end
68
+ it "should be false if the given selector is on the page" do
69
+ @session.should_not have_no_selector(:xpath, "//p")
70
+ @session.should_not have_no_selector(:css, "p a#foo")
71
+ @session.should_not have_no_selector("//p[contains(.,'est')]")
64
72
  end
65
73
 
66
- describe '#has_no_selector?' do
67
- before do
68
- @session.visit('/with_html')
69
- end
74
+ it "should be true if the given selector is not on the page" do
75
+ @session.should have_no_selector(:xpath, "//abbr")
76
+ @session.should have_no_selector(:css, "p a#doesnotexist")
77
+ @session.should have_no_selector("//p[contains(.,'thisstringisnotonpage')]")
78
+ end
70
79
 
71
- it "should be false if the given selector is on the page" do
72
- @session.should_not have_no_selector(:xpath, "//p")
73
- @session.should_not have_no_selector(:css, "p a#foo")
74
- @session.should_not have_no_selector(:foo)
75
- @session.should_not have_no_selector("//p[contains(.,'est')]")
76
- end
80
+ it "should use default selector" do
81
+ Capybara.default_selector = :css
82
+ @session.should have_no_selector("p a#doesnotexist")
83
+ @session.should_not have_no_selector("p a#foo")
84
+ end
77
85
 
78
- it "should be true if the given selector is not on the page" do
79
- @session.should have_no_selector(:xpath, "//abbr")
80
- @session.should have_no_selector(:css, "p a#doesnotexist")
81
- @session.should have_no_selector(:doesnotexist)
82
- @session.should have_no_selector("//p[contains(.,'thisstringisnotonpage')]")
86
+ it "should respect scopes" do
87
+ @session.within "//p[@id='first']" do
88
+ @session.should_not have_no_selector(".//a[@id='foo']")
89
+ @session.should have_no_selector(".//a[@id='red']")
83
90
  end
91
+ end
84
92
 
85
- it "should use default selector" do
86
- Capybara.default_selector = :css
87
- @session.should have_no_selector("p a#doesnotexist")
88
- @session.should_not have_no_selector("p a#foo")
93
+ context "with count" do
94
+ it "should be false if the content is on the page the given number of times" do
95
+ @session.should_not have_no_selector("//p", :count => 3)
96
+ @session.should_not have_no_selector("//p//a[@id='foo']", :count => 1)
97
+ @session.should_not have_no_selector("//p[contains(.,'est')]", :count => 1)
89
98
  end
90
99
 
91
- it "should respect scopes" do
92
- @session.within "//p[@id='first']" do
93
- @session.should_not have_no_selector(".//a[@id='foo']")
94
- @session.should have_no_selector(".//a[@id='red']")
95
- end
100
+ it "should be true if the content is on the page the wrong number of times" do
101
+ @session.should have_no_selector("//p", :count => 6)
102
+ @session.should have_no_selector("//p//a[@id='foo']", :count => 2)
103
+ @session.should have_no_selector("//p[contains(.,'est')]", :count => 5)
96
104
  end
97
105
 
98
- context "with count" do
99
- it "should be false if the content is on the page the given number of times" do
100
- @session.should_not have_no_selector("//p", :count => 3)
101
- @session.should_not have_no_selector("//p//a[@id='foo']", :count => 1)
102
- @session.should_not have_no_selector("//p[contains(.,'est')]", :count => 1)
103
- end
104
-
105
- it "should be true if the content is on the page the wrong number of times" do
106
- @session.should have_no_selector("//p", :count => 6)
107
- @session.should have_no_selector("//p//a[@id='foo']", :count => 2)
108
- @session.should have_no_selector("//p[contains(.,'est')]", :count => 5)
109
- end
110
-
111
- it "should be true if the content isn't on the page at all" do
112
- @session.should have_no_selector("//abbr", :count => 2)
113
- @session.should have_no_selector("//p//a[@id='doesnotexist']", :count => 1)
114
- end
106
+ it "should be true if the content isn't on the page at all" do
107
+ @session.should have_no_selector("//abbr", :count => 2)
108
+ @session.should have_no_selector("//p//a[@id='doesnotexist']", :count => 1)
115
109
  end
110
+ end
116
111
 
117
- context "with text" do
118
- it "should discard all matches where the given string is contained" do
119
- @session.should_not have_no_selector("//p//a", :text => "Redirect", :count => 1)
120
- @session.should have_no_selector("//p", :text => "Doesnotexist")
121
- end
112
+ context "with text" do
113
+ it "should discard all matches where the given string is contained" do
114
+ @session.should_not have_no_selector("//p//a", :text => "Redirect", :count => 1)
115
+ @session.should have_no_selector("//p", :text => "Doesnotexist")
116
+ end
122
117
 
123
- it "should discard all matches where the given regexp is matched" do
124
- @session.should_not have_no_selector("//p//a", :text => /re[dab]i/i, :count => 1)
125
- @session.should have_no_selector("//p//a", :text => /Red$/)
126
- end
118
+ it "should discard all matches where the given regexp is matched" do
119
+ @session.should_not have_no_selector("//p//a", :text => /re[dab]i/i, :count => 1)
120
+ @session.should have_no_selector("//p//a", :text => /Red$/)
127
121
  end
128
122
  end
129
123
  end
@@ -1,96 +1,30 @@
1
- shared_examples_for "has_table" do
2
- describe '#has_table?' do
3
- before do
4
- @session.visit('/tables')
5
- end
6
-
7
- it "should be true if the field is on the page" do
8
- @session.should have_table('Deaths')
9
- @session.should have_table('villain_table')
10
- end
11
-
12
- it "should be false if the field is not on the page" do
13
- @session.should_not have_table('Monkey')
14
- end
15
-
16
- context 'with rows' do
17
- it "should be true if a table with the given rows is on the page" do
18
- @session.should have_table('Ransom', :rows => [['2007', '$300', '$100']])
19
- @session.should have_table('Deaths', :rows => [['2007', '66', '7'], ['2008', '123', '12']])
20
- end
21
-
22
- it "should be true if the given rows are incomplete" do
23
- @session.should have_table('Ransom', :rows => [['$300', '$100']])
24
- end
25
-
26
- it "should be false if the given table is not on the page" do
27
- @session.should_not have_table('Does not exist', :selected => 'John')
28
- end
29
-
30
- it "should be false if the given rows contain incorrect elements" do
31
- @session.should_not have_table('Ransom', :rows => [['2007', '$1000000000', '$100']])
32
- end
33
-
34
- it "should be false if the given rows are incorrectly ordered" do
35
- @session.should_not have_table('Ransom', :rows => [['2007', '$100', '$300']])
36
- end
37
-
38
- it "should be false if the only some of the given rows are correct" do
39
- @session.should_not have_table('Deaths', :rows => [['2007', '66', '7'], ['2007', '99999999', '12']])
40
- end
41
-
42
- it "should be false if the given rows are out of order" do
43
- @session.should_not have_table('Deaths', :rows => [['2007', '123', '12'], ['2007', '66', '7']])
44
- end
45
- end
1
+ Capybara::SpecHelper.spec '#has_table?' do
2
+ before do
3
+ @session.visit('/tables')
46
4
  end
47
5
 
48
- describe '#has_no_table?' do
49
- before do
50
- @session.visit('/tables')
51
- end
52
-
53
- it "should be false if the field is on the page" do
54
- @session.should_not have_no_table('Deaths')
55
- @session.should_not have_no_table('villain_table')
56
- end
57
-
58
- it "should be true if the field is not on the page" do
59
- @session.should have_no_table('Monkey')
60
- end
61
-
62
- context 'with rows' do
63
- it "should be false if a table with the given rows is on the page" do
64
- @session.should_not have_no_table('Ransom', :rows => [['2007', '$300', '$100']])
65
- @session.should_not have_no_table('Deaths', :rows => [['2007', '66', '7'], ['2008', '123', '12']])
66
- end
67
-
68
- it "should be false if the given rows are incomplete" do
69
- @session.should_not have_no_table('Ransom', :rows => [['$300', '$100']])
70
- end
71
-
72
- it "should be true if the given table is not on the page" do
73
- @session.should have_no_table('Does not exist', :selected => 'John')
74
- end
75
-
76
- it "should be true if the given rows contain incorrect elements" do
77
- @session.should have_no_table('Ransom', :rows => [['2007', '$1000000000', '$100']])
78
- end
79
-
80
- it "should be true if the given rows are incorrectly ordered" do
81
- @session.should have_no_table('Ransom', :rows => [['2007', '$100', '$300']])
82
- end
83
-
84
- it "should be true if the only some of the given rows are correct" do
85
- @session.should have_no_table('Deaths', :rows => [['2007', '66', '7'], ['2007', '99999999', '12']])
86
- end
6
+ it "should be true if the table is on the page" do
7
+ @session.should have_table('Villain')
8
+ @session.should have_table('villain_table')
9
+ @session.should have_table(:'villain_table')
10
+ end
87
11
 
88
- it "should be true if the given rows are out of order" do
89
- @session.should have_no_table('Deaths', :rows => [['2007', '123', '12'], ['2007', '66', '7']])
90
- end
91
- end
12
+ it "should be false if the table is not on the page" do
13
+ @session.should_not have_table('Monkey')
92
14
  end
93
15
  end
94
16
 
17
+ Capybara::SpecHelper.spec '#has_no_table?' do
18
+ before do
19
+ @session.visit('/tables')
20
+ end
95
21
 
22
+ it "should be false if the table is on the page" do
23
+ @session.should_not have_no_table('Villain')
24
+ @session.should_not have_no_table('villain_table')
25
+ end
96
26
 
27
+ it "should be true if the table is not on the page" do
28
+ @session.should have_no_table('Monkey')
29
+ end
30
+ end