capybara 1.1.4 → 2.0.0.beta2

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 (84) hide show
  1. data/History.txt +100 -0
  2. data/License.txt +22 -0
  3. data/README.md +829 -0
  4. data/lib/capybara.rb +124 -6
  5. data/lib/capybara/cucumber.rb +2 -5
  6. data/lib/capybara/driver/base.rb +5 -5
  7. data/lib/capybara/driver/node.rb +2 -2
  8. data/lib/capybara/dsl.rb +3 -121
  9. data/lib/capybara/node/actions.rb +12 -28
  10. data/lib/capybara/node/base.rb +5 -13
  11. data/lib/capybara/node/element.rb +21 -21
  12. data/lib/capybara/node/finders.rb +27 -89
  13. data/lib/capybara/node/matchers.rb +107 -69
  14. data/lib/capybara/node/simple.rb +11 -13
  15. data/lib/capybara/query.rb +78 -0
  16. data/lib/capybara/rack_test/browser.rb +16 -27
  17. data/lib/capybara/rack_test/driver.rb +11 -1
  18. data/lib/capybara/rack_test/node.rb +17 -1
  19. data/lib/capybara/result.rb +84 -0
  20. data/lib/capybara/rspec/matchers.rb +28 -63
  21. data/lib/capybara/selector.rb +97 -33
  22. data/lib/capybara/selenium/driver.rb +14 -61
  23. data/lib/capybara/selenium/node.rb +6 -15
  24. data/lib/capybara/server.rb +32 -27
  25. data/lib/capybara/session.rb +54 -30
  26. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  27. data/lib/capybara/spec/public/jquery.js +9046 -0
  28. data/lib/capybara/spec/public/test.js +4 -1
  29. data/lib/capybara/spec/session.rb +56 -27
  30. data/lib/capybara/spec/session/all_spec.rb +8 -4
  31. data/lib/capybara/spec/session/attach_file_spec.rb +12 -9
  32. data/lib/capybara/spec/session/check_spec.rb +6 -3
  33. data/lib/capybara/spec/session/choose_spec.rb +4 -1
  34. data/lib/capybara/spec/session/click_button_spec.rb +5 -14
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +2 -1
  36. data/lib/capybara/spec/session/click_link_spec.rb +3 -17
  37. data/lib/capybara/spec/session/current_url_spec.rb +77 -9
  38. data/lib/capybara/spec/session/fill_in_spec.rb +8 -18
  39. data/lib/capybara/spec/session/find_spec.rb +19 -46
  40. data/lib/capybara/spec/session/first_spec.rb +2 -34
  41. data/lib/capybara/spec/session/has_css_spec.rb +1 -1
  42. data/lib/capybara/spec/session/has_field_spec.rb +28 -0
  43. data/lib/capybara/spec/session/has_select_spec.rb +84 -31
  44. data/lib/capybara/spec/session/has_table_spec.rb +7 -69
  45. data/lib/capybara/spec/session/has_text_spec.rb +168 -0
  46. data/lib/capybara/spec/session/javascript.rb +65 -81
  47. data/lib/capybara/spec/session/node_spec.rb +115 -0
  48. data/lib/capybara/spec/session/screenshot.rb +29 -0
  49. data/lib/capybara/spec/session/select_spec.rb +12 -12
  50. data/lib/capybara/spec/session/text_spec.rb +9 -4
  51. data/lib/capybara/spec/session/unselect_spec.rb +12 -6
  52. data/lib/capybara/spec/session/visit_spec.rb +76 -0
  53. data/lib/capybara/spec/session/within_frame_spec.rb +33 -0
  54. data/lib/capybara/spec/session/within_spec.rb +47 -58
  55. data/lib/capybara/spec/session/within_window_spec.rb +40 -0
  56. data/lib/capybara/spec/test_app.rb +27 -3
  57. data/lib/capybara/spec/views/form.erb +11 -10
  58. data/lib/capybara/spec/views/host_links.erb +2 -2
  59. data/lib/capybara/spec/views/tables.erb +6 -66
  60. data/lib/capybara/spec/views/with_html.erb +3 -3
  61. data/lib/capybara/spec/views/with_js.erb +11 -8
  62. data/lib/capybara/util/save_and_open_page.rb +4 -3
  63. data/lib/capybara/version.rb +1 -1
  64. data/spec/basic_node_spec.rb +15 -3
  65. data/spec/dsl_spec.rb +12 -10
  66. data/spec/rack_test_spec.rb +152 -0
  67. data/spec/rspec/features_spec.rb +0 -2
  68. data/spec/rspec/matchers_spec.rb +164 -89
  69. data/spec/rspec_spec.rb +0 -2
  70. data/spec/selenium_spec.rb +67 -0
  71. data/spec/server_spec.rb +35 -23
  72. data/spec/spec_helper.rb +18 -2
  73. metadata +30 -30
  74. data/README.rdoc +0 -722
  75. data/lib/capybara/spec/driver.rb +0 -301
  76. data/lib/capybara/spec/session/current_host_spec.rb +0 -68
  77. data/lib/capybara/spec/session/has_content_spec.rb +0 -106
  78. data/lib/capybara/util/timeout.rb +0 -27
  79. data/spec/driver/rack_test_driver_spec.rb +0 -89
  80. data/spec/driver/selenium_driver_spec.rb +0 -37
  81. data/spec/session/rack_test_session_spec.rb +0 -55
  82. data/spec/session/selenium_session_spec.rb +0 -26
  83. data/spec/string_spec.rb +0 -77
  84. data/spec/timeout_spec.rb +0 -28
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Session do
4
+ context 'with rack test driver' do
5
+ before do
6
+ @session = TestSessions::RackTest
7
+ end
8
+
9
+ describe '#driver' do
10
+ it "should be a rack test driver" do
11
+ @session.driver.should be_an_instance_of(Capybara::RackTest::Driver)
12
+ end
13
+ end
14
+
15
+ describe '#mode' do
16
+ it "should remember the mode" do
17
+ @session.mode.should == :rack_test
18
+ end
19
+ end
20
+
21
+ describe '#click_link' do
22
+ it "should use data-method if option is true" do
23
+ @session.driver.options[:respect_data_method] = true
24
+ @session.visit "/with_html"
25
+ @session.click_link "A link with data-method"
26
+ @session.body.should include('The requested object was deleted')
27
+ end
28
+
29
+ it "should not use data-method if option is false" do
30
+ @session.driver.options[:respect_data_method] = false
31
+ @session.visit "/with_html"
32
+ @session.click_link "A link with data-method"
33
+ @session.body.should include('Not deleted')
34
+ end
35
+
36
+ it "should use data-method if available even if it's capitalized" do
37
+ @session.driver.options[:respect_data_method] = true
38
+ @session.visit "/with_html"
39
+ @session.click_link "A link with capitalized data-method"
40
+ @session.body.should include('The requested object was deleted')
41
+ end
42
+
43
+ after do
44
+ @session.driver.options[:respect_data_method] = false
45
+ end
46
+ end
47
+
48
+ describe "#attach_file" do
49
+ context "with multipart form" do
50
+ it "should submit an empty form-data section if no file is submitted" do
51
+ @session.visit("/form")
52
+ @session.click_button("Upload Empty")
53
+ @session.body.should include('Successfully ignored empty file field.')
54
+ end
55
+ end
56
+ end
57
+
58
+ it_should_behave_like "session"
59
+ it_should_behave_like "session without javascript support"
60
+ it_should_behave_like "session without screenshot support"
61
+ it_should_behave_like "session with headers support"
62
+ it_should_behave_like "session with status code support"
63
+ end
64
+ end
65
+
66
+ describe Capybara::RackTest::Driver do
67
+ before do
68
+ @driver = TestSessions::RackTest.driver
69
+ end
70
+
71
+ describe ':headers option' do
72
+ it 'should always set headers' do
73
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
74
+ @driver.visit('/get_header')
75
+ @driver.body.should include('foobar')
76
+ end
77
+
78
+ it 'should keep headers on link clicks' do
79
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
80
+ @driver.visit('/header_links')
81
+ @driver.find('.//a').first.click
82
+ @driver.body.should include('foobar')
83
+ end
84
+
85
+ it 'should keep headers on form submit' do
86
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
87
+ @driver.visit('/header_links')
88
+ @driver.find('.//input').first.click
89
+ @driver.body.should include('foobar')
90
+ end
91
+
92
+ it 'should keep headers on redirects' do
93
+ @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
94
+ @driver.visit('/get_header_via_redirect')
95
+ @driver.body.should include('foobar')
96
+ end
97
+ end
98
+
99
+ describe ':follow_redirects option' do
100
+ it "defaults to following redirects" do
101
+ @driver = Capybara::RackTest::Driver.new(TestApp)
102
+
103
+ @driver.visit('/redirect')
104
+ @driver.response.header['Location'].should be_nil
105
+ @driver.browser.current_url.should eq "#{@driver.browser.current_host}/landed"
106
+ end
107
+
108
+ it "is possible to not follow redirects" do
109
+ @driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
110
+
111
+ @driver.visit('/redirect')
112
+ @driver.response.header['Location'].should eq "#{@driver.browser.current_host}/redirect_again"
113
+ @driver.browser.current_url.should eq "#{@driver.browser.current_host}/redirect"
114
+ end
115
+ end
116
+
117
+ describe ':redirect_limit option' do
118
+ context "with default redirect limit" do
119
+ before do
120
+ @driver = Capybara::RackTest::Driver.new(TestApp)
121
+ end
122
+
123
+ it "should follow 5 redirects" do
124
+ @driver.visit("/redirect/5/times")
125
+ @driver.body.should include('redirection complete')
126
+ end
127
+
128
+ it "should not follow more than 6 redirects" do
129
+ running do
130
+ @driver.visit("/redirect/6/times")
131
+ end.should raise_error(Capybara::InfiniteRedirectError)
132
+ end
133
+ end
134
+
135
+ context "with 21 redirect limit" do
136
+ before do
137
+ @driver = Capybara::RackTest::Driver.new(TestApp, :redirect_limit => 21)
138
+ end
139
+
140
+ it "should follow 21 redirects" do
141
+ @driver.visit("/redirect/21/times")
142
+ @driver.body.should include('redirection complete')
143
+ end
144
+
145
+ it "should not follow more than 21 redirects" do
146
+ running do
147
+ @driver.visit("/redirect/22/times")
148
+ end.should raise_error(Capybara::InfiniteRedirectError)
149
+ end
150
+ end
151
+ end
152
+ end
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'capybara/rspec'
3
3
 
4
- Capybara.app = TestApp
5
-
6
4
  RSpec.configuration.before(:each, :example_group => {:file_path => "./spec/rspec/features_spec.rb"}) do
7
5
  @in_filtered_hook = true
8
6
  end
@@ -2,15 +2,13 @@ require 'spec_helper'
2
2
  require 'capybara/dsl'
3
3
  require 'capybara/rspec/matchers'
4
4
 
5
- Capybara.app = TestApp
6
-
7
5
  describe Capybara::RSpecMatchers do
8
6
  include Capybara::DSL
9
7
  include Capybara::RSpecMatchers
10
8
 
11
9
  describe "have_css matcher" do
12
10
  it "gives proper description" do
13
- have_css('h1').description.should == "has css \"h1\""
11
+ have_css('h1').description.should == "have css \"h1\""
14
12
  end
15
13
 
16
14
  context "on a string" do
@@ -22,7 +20,7 @@ describe Capybara::RSpecMatchers do
22
20
  it "fails if has_css? returns false" do
23
21
  expect do
24
22
  "<h1>Text</h1>".should have_css('h2')
25
- end.to raise_error(/expected css "h2" to return something/)
23
+ end.to raise_error(/expected to find css "h2" but there were no matches/)
26
24
  end
27
25
 
28
26
  it "passes if matched node count equals expected count" do
@@ -32,7 +30,7 @@ describe Capybara::RSpecMatchers do
32
30
  it "fails if matched node count does not equal expected count" do
33
31
  expect do
34
32
  "<h1>Text</h1>".should have_css('h1', :count => 2)
35
- end.to raise_error(/expected css "h1" to return something/)
33
+ end.to raise_error(/expected css "h1" to be found 2 times/)
36
34
  end
37
35
  end
38
36
 
@@ -44,7 +42,7 @@ describe Capybara::RSpecMatchers do
44
42
  it "fails if has_no_css? returns false" do
45
43
  expect do
46
44
  "<h1>Text</h1>".should_not have_css('h1')
47
- end.to raise_error(/expected css "h1" not to return anything/)
45
+ end.to raise_error(/expected not to find css "h1"/)
48
46
  end
49
47
 
50
48
  it "passes if matched node count does not equal expected count" do
@@ -54,7 +52,7 @@ describe Capybara::RSpecMatchers do
54
52
  it "fails if matched node count equals expected count" do
55
53
  expect do
56
54
  "<h1>Text</h1>".should_not have_css('h1', :count => 1)
57
- end.to raise_error(/expected css "h1" not to return anything/)
55
+ end.to raise_error(/expected not to find css "h1"/)
58
56
  end
59
57
  end
60
58
  end
@@ -72,7 +70,7 @@ describe Capybara::RSpecMatchers do
72
70
  it "fails if has_css? returns false" do
73
71
  expect do
74
72
  page.should have_css('h1#doesnotexist')
75
- end.to raise_error(/expected css "h1#doesnotexist" to return something/)
73
+ end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
76
74
  end
77
75
  end
78
76
 
@@ -84,7 +82,7 @@ describe Capybara::RSpecMatchers do
84
82
  it "fails if has_no_css? returns false" do
85
83
  expect do
86
84
  page.should_not have_css('h1')
87
- end.to raise_error(/expected css "h1" not to return anything/)
85
+ end.to raise_error(/expected not to find css "h1"/)
88
86
  end
89
87
  end
90
88
  end
@@ -92,31 +90,31 @@ describe Capybara::RSpecMatchers do
92
90
 
93
91
  describe "have_xpath matcher" do
94
92
  it "gives proper description" do
95
- have_xpath('//h1').description.should == "has xpath \"\/\/h1\""
93
+ have_xpath('//h1').description.should == "have xpath \"\/\/h1\""
96
94
  end
97
95
 
98
96
  context "on a string" do
99
97
  context "with should" do
100
- it "passes if has_css? returns true" do
98
+ it "passes if has_xpath? returns true" do
101
99
  "<h1>Text</h1>".should have_xpath('//h1')
102
100
  end
103
101
 
104
- it "fails if has_css? returns false" do
102
+ it "fails if has_xpath? returns false" do
105
103
  expect do
106
104
  "<h1>Text</h1>".should have_xpath('//h2')
107
- end.to raise_error(%r(expected xpath "//h2" to return something))
105
+ end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
108
106
  end
109
107
  end
110
108
 
111
109
  context "with should_not" do
112
- it "passes if has_no_css? returns true" do
110
+ it "passes if has_no_xpath? returns true" do
113
111
  "<h1>Text</h1>".should_not have_xpath('//h2')
114
112
  end
115
113
 
116
- it "fails if has_no_css? returns false" do
114
+ it "fails if has_no_xpath? returns false" do
117
115
  expect do
118
116
  "<h1>Text</h1>".should_not have_xpath('//h1')
119
- end.to raise_error(%r(expected xpath "//h1" not to return anything))
117
+ end.to raise_error(%r(expected not to find xpath "//h1"))
120
118
  end
121
119
  end
122
120
  end
@@ -127,26 +125,26 @@ describe Capybara::RSpecMatchers do
127
125
  end
128
126
 
129
127
  context "with should" do
130
- it "passes if has_css? returns true" do
128
+ it "passes if has_xpath? returns true" do
131
129
  page.should have_xpath('//h1')
132
130
  end
133
131
 
134
- it "fails if has_css? returns false" do
132
+ it "fails if has_xpath? returns false" do
135
133
  expect do
136
134
  page.should have_xpath("//h1[@id='doesnotexist']")
137
- end.to raise_error(%r(expected xpath "//h1\[@id='doesnotexist'\]" to return something))
135
+ end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
138
136
  end
139
137
  end
140
138
 
141
139
  context "with should_not" do
142
- it "passes if has_no_css? returns true" do
140
+ it "passes if has_no_xpath? returns true" do
143
141
  page.should_not have_xpath('//h1[@id="doesnotexist"]')
144
142
  end
145
143
 
146
- it "fails if has_no_css? returns false" do
144
+ it "fails if has_no_xpath? returns false" do
147
145
  expect do
148
146
  page.should_not have_xpath('//h1')
149
- end.to raise_error(%r(expected xpath "//h1" not to return anything))
147
+ end.to raise_error(%r(expected not to find xpath "//h1"))
150
148
  end
151
149
  end
152
150
  end
@@ -154,41 +152,33 @@ describe Capybara::RSpecMatchers do
154
152
 
155
153
  describe "have_selector matcher" do
156
154
  it "gives proper description" do
157
- have_selector('//h1').description.should == "has xpath \"//h1\""
155
+ matcher = have_selector('//h1')
156
+ "<h1>Text</h1>".should matcher
157
+ matcher.description.should == "have xpath \"//h1\""
158
158
  end
159
159
 
160
160
  context "on a string" do
161
161
  context "with should" do
162
- it "passes if has_css? returns true" do
162
+ it "passes if has_selector? returns true" do
163
163
  "<h1>Text</h1>".should have_selector('//h1')
164
164
  end
165
165
 
166
- it "fails if has_css? returns false" do
166
+ it "fails if has_selector? returns false" do
167
167
  expect do
168
168
  "<h1>Text</h1>".should have_selector('//h2')
169
- end.to raise_error(%r(expected xpath "//h2" to return something))
170
- end
171
-
172
- it "fails with the selector's failure_message if set" do
173
- Capybara.add_selector(:monkey) do
174
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
175
- failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
176
- end
177
- expect do
178
- '<h1 id="monkey_paul">Monkey John</h1>'.should have_selector(:monkey, 14)
179
- end.to raise_error("Monkey John")
169
+ end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
180
170
  end
181
171
  end
182
172
 
183
173
  context "with should_not" do
184
- it "passes if has_no_css? returns true" do
174
+ it "passes if has_no_selector? returns true" do
185
175
  "<h1>Text</h1>".should_not have_selector(:css, 'h2')
186
176
  end
187
177
 
188
- it "fails if has_no_css? returns false" do
178
+ it "fails if has_no_selector? returns false" do
189
179
  expect do
190
180
  "<h1>Text</h1>".should_not have_selector(:css, 'h1')
191
- end.to raise_error(%r(expected css "h1" not to return anything))
181
+ end.to raise_error(%r(expected not to find css "h1"))
192
182
  end
193
183
  end
194
184
  end
@@ -199,30 +189,20 @@ describe Capybara::RSpecMatchers do
199
189
  end
200
190
 
201
191
  context "with should" do
202
- it "passes if has_css? returns true" do
192
+ it "passes if has_selector? returns true" do
203
193
  page.should have_selector('//h1', :text => 'test')
204
194
  end
205
195
 
206
- it "fails if has_css? returns false" do
196
+ it "fails if has_selector? returns false" do
207
197
  expect do
208
198
  page.should have_selector("//h1[@id='doesnotexist']")
209
- end.to raise_error(%r(expected xpath "//h1\[@id='doesnotexist'\]" to return something))
199
+ end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
210
200
  end
211
201
 
212
202
  it "includes text in error message" do
213
203
  expect do
214
204
  page.should have_selector("//h1", :text => 'wrong text')
215
- end.to raise_error(%r(expected xpath "//h1" with text "wrong text" to return something))
216
- end
217
-
218
- it "fails with the selector's failure_message if set" do
219
- Capybara.add_selector(:monkey) do
220
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
221
- failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
222
- end
223
- expect do
224
- page.should have_selector(:monkey, 14)
225
- end.to raise_error("Monkey John, Monkey Paul")
205
+ end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
226
206
  end
227
207
  end
228
208
 
@@ -231,10 +211,10 @@ describe Capybara::RSpecMatchers do
231
211
  page.should_not have_selector(:css, 'h1#doesnotexist')
232
212
  end
233
213
 
234
- it "fails if has_no_css? returns false" do
214
+ it "fails if has_no_selector? returns false" do
235
215
  expect do
236
216
  page.should_not have_selector(:css, 'h1', :text => 'test')
237
- end.to raise_error(%r(expected css "h1" with text "test" not to return anything))
217
+ end.to raise_error(%r(expected not to find css "h1" with text "test"))
238
218
  end
239
219
  end
240
220
  end
@@ -242,31 +222,39 @@ describe Capybara::RSpecMatchers do
242
222
 
243
223
  describe "have_content matcher" do
244
224
  it "gives proper description" do
245
- have_content('Text').description.should == "has content \"Text\""
225
+ have_content('Text').description.should == "have text \"Text\""
246
226
  end
247
227
 
248
228
  context "on a string" do
249
229
  context "with should" do
250
- it "passes if has_css? returns true" do
230
+ it "passes if has_content? returns true" do
251
231
  "<h1>Text</h1>".should have_content('Text')
252
232
  end
253
233
 
254
- it "fails if has_css? returns false" do
234
+ it "passes if has_content? returns true using regexp" do
235
+ "<h1>Text</h1>".should have_content(/ext/)
236
+ end
237
+
238
+ it "fails if has_content? returns false" do
255
239
  expect do
256
240
  "<h1>Text</h1>".should have_content('No such Text')
257
- end.to raise_error(/expected there to be content "No such Text" in "Text"/)
241
+ end.to raise_error(/expected there to be text "No such Text" in "Text"/)
258
242
  end
259
243
  end
260
244
 
261
245
  context "with should_not" do
262
- it "passes if has_no_css? returns true" do
246
+ it "passes if has_no_content? returns true" do
263
247
  "<h1>Text</h1>".should_not have_content('No such Text')
264
248
  end
265
249
 
266
- it "fails if has_no_css? returns false" do
250
+ it "passes because escapes any characters that would have special meaning in a regexp" do
251
+ "<h1>Text</h1>".should_not have_content('.')
252
+ end
253
+
254
+ it "fails if has_no_content? returns false" do
267
255
  expect do
268
256
  "<h1>Text</h1>".should_not have_content('Text')
269
- end.to raise_error(/expected content "Text" not to return anything/)
257
+ end.to raise_error(/expected there not to be text "Text" in "Text"/)
270
258
  end
271
259
  end
272
260
  end
@@ -277,36 +265,124 @@ describe Capybara::RSpecMatchers do
277
265
  end
278
266
 
279
267
  context "with should" do
280
- it "passes if has_css? returns true" do
268
+ it "passes if has_content? returns true" do
281
269
  page.should have_content('This is a test')
282
270
  end
283
271
 
284
- it "fails if has_css? returns false" do
272
+ it "passes if has_content? returns true using regexp" do
273
+ page.should have_content(/test/)
274
+ end
275
+
276
+ it "fails if has_content? returns false" do
285
277
  expect do
286
278
  page.should have_content('No such Text')
287
- end.to raise_error(/expected there to be content "No such Text" in "(.*)This is a test(.*)"/)
279
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
288
280
  end
289
281
 
290
282
  context "with default selector CSS" do
291
283
  before { Capybara.default_selector = :css }
292
- it "fails if has_css? returns false" do
284
+ it "fails if has_content? returns false" do
293
285
  expect do
294
286
  page.should have_content('No such Text')
295
- end.to raise_error(/expected there to be content "No such Text" in "(.*)This is a test(.*)"/)
287
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
296
288
  end
297
289
  after { Capybara.default_selector = :xpath }
298
290
  end
299
291
  end
300
292
 
301
293
  context "with should_not" do
302
- it "passes if has_no_css? returns true" do
294
+ it "passes if has_no_content? returns true" do
303
295
  page.should_not have_content('No such Text')
304
296
  end
305
297
 
306
- it "fails if has_no_css? returns false" do
298
+ it "fails if has_no_content? returns false" do
307
299
  expect do
308
300
  page.should_not have_content('This is a test')
309
- end.to raise_error(/expected content "This is a test" not to return anything/)
301
+ end.to raise_error(/expected there not to be text "This is a test"/)
302
+ end
303
+ end
304
+ end
305
+ end
306
+
307
+ describe "have_text matcher" do
308
+ it "gives proper description" do
309
+ have_text('Text').description.should == "have text \"Text\""
310
+ end
311
+
312
+ context "on a string" do
313
+ context "with should" do
314
+ it "passes if has_text? returns true" do
315
+ "<h1>Text</h1>".should have_text('Text')
316
+ end
317
+
318
+ it "passes if has_text? returns true using regexp" do
319
+ "<h1>Text</h1>".should have_text(/ext/)
320
+ end
321
+
322
+ it "fails if has_text? returns false" do
323
+ expect do
324
+ "<h1>Text</h1>".should have_text('No such Text')
325
+ end.to raise_error(/expected there to be text "No such Text" in "Text"/)
326
+ end
327
+ end
328
+
329
+ context "with should_not" do
330
+ it "passes if has_no_text? returns true" do
331
+ "<h1>Text</h1>".should_not have_text('No such Text')
332
+ end
333
+
334
+ it "passes because escapes any characters that would have special meaning in a regexp" do
335
+ "<h1>Text</h1>".should_not have_text('.')
336
+ end
337
+
338
+ it "fails if has_no_text? returns false" do
339
+ expect do
340
+ "<h1>Text</h1>".should_not have_text('Text')
341
+ end.to raise_error(/expected there not to be text "Text" in "Text"/)
342
+ end
343
+ end
344
+ end
345
+
346
+ context "on a page or node" do
347
+ before do
348
+ visit('/with_html')
349
+ end
350
+
351
+ context "with should" do
352
+ it "passes if has_text? returns true" do
353
+ page.should have_text('This is a test')
354
+ end
355
+
356
+ it "passes if has_text? returns true using regexp" do
357
+ page.should have_text(/test/)
358
+ end
359
+
360
+ it "fails if has_text? returns false" do
361
+ expect do
362
+ page.should have_text('No such Text')
363
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
364
+ end
365
+
366
+ context "with default selector CSS" do
367
+ before { Capybara.default_selector = :css }
368
+ it "fails if has_text? returns false" do
369
+ expect do
370
+ page.should have_text('No such Text')
371
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
372
+ end
373
+ after { Capybara.default_selector = :xpath }
374
+ end
375
+ end
376
+
377
+ context "with should_not" do
378
+ it "passes if has_no_text? returns true" do
379
+ page.should_not have_text('No such Text')
380
+ end
381
+
382
+ it "fails if has_no_text? returns false" do
383
+ expect do
384
+ page.should_not have_text('This is a test')
385
+ end.to raise_error(/expected there not to be text "This is a test"/)
310
386
  end
311
387
  end
312
388
  end
@@ -316,7 +392,7 @@ describe Capybara::RSpecMatchers do
316
392
  let(:html) { '<a href="#">Just a link</a>' }
317
393
 
318
394
  it "gives proper description" do
319
- have_link('Just a link').description.should == "has link \"Just a link\""
395
+ have_link('Just a link').description.should == "have link \"Just a link\""
320
396
  end
321
397
 
322
398
  it "passes if there is such a button" do
@@ -326,7 +402,7 @@ describe Capybara::RSpecMatchers do
326
402
  it "fails if there is no such button" do
327
403
  expect do
328
404
  html.should have_link('No such Link')
329
- end.to raise_error(/expected link "No such Link"/)
405
+ end.to raise_error(/expected to find link "No such Link"/)
330
406
  end
331
407
  end
332
408
 
@@ -334,7 +410,7 @@ describe Capybara::RSpecMatchers do
334
410
  let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
335
411
 
336
412
  it "gives proper description" do
337
- have_button('A button').description.should == "has button \"A button\""
413
+ have_button('A button').description.should == "have button \"A button\""
338
414
  end
339
415
 
340
416
  it "passes if there is such a button" do
@@ -344,7 +420,7 @@ describe Capybara::RSpecMatchers do
344
420
  it "fails if there is no such button" do
345
421
  expect do
346
422
  html.should have_button('No such Button')
347
- end.to raise_error(/expected button "No such Button"/)
423
+ end.to raise_error(/expected to find button "No such Button"/)
348
424
  end
349
425
  end
350
426
 
@@ -352,7 +428,7 @@ describe Capybara::RSpecMatchers do
352
428
  let(:html) { '<p><label>Text field<input type="text"/></label></p>' }
353
429
 
354
430
  it "gives proper description" do
355
- have_field('Text field').description.should == "has field \"Text field\""
431
+ have_field('Text field').description.should == "have field \"Text field\""
356
432
  end
357
433
 
358
434
  it "passes if there is such a field" do
@@ -362,7 +438,7 @@ describe Capybara::RSpecMatchers do
362
438
  it "fails if there is no such field" do
363
439
  expect do
364
440
  html.should have_field('No such Field')
365
- end.to raise_error(/expected field "No such Field"/)
441
+ end.to raise_error(/expected to find field "No such Field"/)
366
442
  end
367
443
  end
368
444
 
@@ -373,7 +449,7 @@ describe Capybara::RSpecMatchers do
373
449
  end
374
450
 
375
451
  it "gives proper description" do
376
- have_checked_field('it is checked').description.should == "has checked_field \"it is checked\""
452
+ have_checked_field('it is checked').description.should == "have field \"it is checked\""
377
453
  end
378
454
 
379
455
  context "with should" do
@@ -384,13 +460,13 @@ describe Capybara::RSpecMatchers do
384
460
  it "fails if there is such a field but it is not checked" do
385
461
  expect do
386
462
  html.should have_checked_field('unchecked field')
387
- end.to raise_error(/expected checked_field "unchecked field"/)
463
+ end.to raise_error(/expected to find field "unchecked field"/)
388
464
  end
389
465
 
390
466
  it "fails if there is no such field" do
391
467
  expect do
392
468
  html.should have_checked_field('no such field')
393
- end.to raise_error(/expected checked_field "no such field"/)
469
+ end.to raise_error(/expected to find field "no such field"/)
394
470
  end
395
471
  end
396
472
 
@@ -398,7 +474,7 @@ describe Capybara::RSpecMatchers do
398
474
  it "fails if there is such a field and it is checked" do
399
475
  expect do
400
476
  html.should_not have_checked_field('it is checked')
401
- end.to raise_error(/expected checked_field "it is checked" not to return anything/)
477
+ end.to raise_error(/expected not to find field "it is checked"/)
402
478
  end
403
479
 
404
480
  it "passes if there is such a field but it is not checked" do
@@ -418,7 +494,7 @@ describe Capybara::RSpecMatchers do
418
494
  end
419
495
 
420
496
  it "gives proper description" do
421
- have_unchecked_field('unchecked field').description.should == "has unchecked_field \"unchecked field\""
497
+ have_unchecked_field('unchecked field').description.should == "have field \"unchecked field\""
422
498
  end
423
499
 
424
500
  context "with should" do
@@ -429,13 +505,13 @@ describe Capybara::RSpecMatchers do
429
505
  it "fails if there is such a field but it is checked" do
430
506
  expect do
431
507
  html.should have_unchecked_field('it is checked')
432
- end.to raise_error(/expected unchecked_field "it is checked"/)
508
+ end.to raise_error(/expected to find field "it is checked"/)
433
509
  end
434
510
 
435
511
  it "fails if there is no such field" do
436
512
  expect do
437
513
  html.should have_unchecked_field('no such field')
438
- end.to raise_error(/expected unchecked_field "no such field"/)
514
+ end.to raise_error(/expected to find field "no such field"/)
439
515
  end
440
516
  end
441
517
 
@@ -443,7 +519,7 @@ describe Capybara::RSpecMatchers do
443
519
  it "fails if there is such a field and it is not checked" do
444
520
  expect do
445
521
  html.should_not have_unchecked_field('unchecked field')
446
- end.to raise_error(/expected unchecked_field "unchecked field" not to return anything/)
522
+ end.to raise_error(/expected not to find field "unchecked field"/)
447
523
  end
448
524
 
449
525
  it "passes if there is such a field but it is checked" do
@@ -460,7 +536,7 @@ describe Capybara::RSpecMatchers do
460
536
  let(:html) { '<label>Select Box<select></select></label>' }
461
537
 
462
538
  it "gives proper description" do
463
- have_select('Select Box').description.should == "has select \"Select Box\""
539
+ have_select('Select Box').description.should == "have select box \"Select Box\""
464
540
  end
465
541
 
466
542
  it "passes if there is such a select" do
@@ -470,7 +546,7 @@ describe Capybara::RSpecMatchers do
470
546
  it "fails if there is no such select" do
471
547
  expect do
472
548
  html.should have_select('No such Select box')
473
- end.to raise_error(/expected select "No such Select box"/)
549
+ end.to raise_error(/expected to find select box "No such Select box"/)
474
550
  end
475
551
  end
476
552
 
@@ -478,7 +554,7 @@ describe Capybara::RSpecMatchers do
478
554
  let(:html) { '<table><caption>Lovely table</caption></table>' }
479
555
 
480
556
  it "gives proper description" do
481
- have_table('Lovely table').description.should == "has table \"Lovely table\""
557
+ have_table('Lovely table').description.should == "have table \"Lovely table\""
482
558
  end
483
559
 
484
560
  it "passes if there is such a select" do
@@ -488,8 +564,7 @@ describe Capybara::RSpecMatchers do
488
564
  it "fails if there is no such select" do
489
565
  expect do
490
566
  html.should have_table('No such Table')
491
- end.to raise_error(/expected table "No such Table"/)
567
+ end.to raise_error(/expected to find table "No such Table"/)
492
568
  end
493
569
  end
494
570
  end
495
-