/usr/lib/ruby/vendor_ruby/capybara/spec/session/has_text_spec.rb is in ruby-capybara 2.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | Capybara::SpecHelper.spec '#has_text?' do
it "should be true if the given text is on the page at least once" do
@session.visit('/with_html')
expect(@session).to have_text('est')
expect(@session).to have_text('Lorem')
expect(@session).to have_text('Redirect')
expect(@session).to have_text(:'Redirect')
end
it "should be true if scoped to an element which has the text" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
expect(@session).to have_text('labore')
end
end
it "should be false if scoped to an element which does not have the text" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
expect(@session).not_to have_text('monkey')
end
end
it "should ignore tags" do
@session.visit('/with_html')
expect(@session).not_to have_text('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
expect(@session).to have_text('exercitation ullamco laboris')
end
it "should ignore extra whitespace and newlines" do
@session.visit('/with_html')
expect(@session).to have_text('text with whitespace')
end
it "should ignore whitespace and newlines in the search string" do
@session.visit('/with_html')
expect(@session).to have_text("text with \n\n whitespace")
end
it "should be false if the given text is not on the page" do
@session.visit('/with_html')
expect(@session).not_to have_text('xxxxyzzz')
expect(@session).not_to have_text('monkey')
end
it 'should handle single quotes in the text' do
@session.visit('/with-quotes')
expect(@session).to have_text("can't")
end
it 'should handle double quotes in the text' do
@session.visit('/with-quotes')
expect(@session).to have_text(%q{"No," he said})
end
it 'should handle mixed single and double quotes in the text' do
@session.visit('/with-quotes')
expect(@session).to have_text(%q{"you can't do that."})
end
it 'should be false if text is in the title tag in the head' do
@session.visit('/with_js')
expect(@session).not_to have_text('with_js')
end
it 'should be false if text is inside a script tag in the body' do
@session.visit('/with_js')
expect(@session).not_to have_text('a javascript comment')
expect(@session).not_to have_text('aVar')
end
it "should be false if the given text is on the page but not visible" do
@session.visit('/with_html')
expect(@session).not_to have_text('Inside element with hidden ancestor')
end
it "should be true if :all given and text is invisible." do
@session.visit('/with_html')
expect(@session).to have_text(:all, 'Some of this text is hidden!')
end
it "should be true if `Capybara.ignore_hidden_elements = true` and text is invisible." do
Capybara.ignore_hidden_elements = false
@session.visit('/with_html')
expect(@session).to have_text('Some of this text is hidden!')
end
it "should be true if the text in the page matches given regexp" do
@session.visit('/with_html')
expect(@session).to have_text(/Lorem/)
end
it "should be false if the text in the page doesn't match given regexp" do
@session.visit('/with_html')
expect(@session).not_to have_text(/xxxxyzzz/)
end
it "should escape any characters that would have special meaning in a regexp" do
@session.visit('/with_html')
expect(@session).not_to have_text('.orem')
end
it "should accept non-string parameters" do
@session.visit('/with_html')
expect(@session).to have_text(42)
end
it "should be true when passed nil" do
# nil is converted to '' when to_s is invoked
@session.visit('/with_html')
expect(@session).to have_text(nil)
end
it "should wait for text to appear", :requires => [:js] do
@session.visit('/with_js')
@session.click_link('Click me')
expect(@session).to have_text("Has been clicked")
end
context "with between" do
it "should be true if the text occurs within the range given" do
@session.visit('/with_count')
expect(@session).to have_text('count', between: 1..3)
expect(@session).to have_text(/count/, between: 2..2)
end
it "should be false if the text occurs more or fewer times than range" do
@session.visit('/with_count')
expect(@session).not_to have_text('count', between: 0..1)
expect(@session).not_to have_text('count', between: 3..10)
expect(@session).not_to have_text(/count/, between: 2...2)
end
end
context "with count" do
it "should be true if the text occurs the given number of times" do
@session.visit('/with_count')
expect(@session).to have_text('count', count: 2)
end
it "should be false if the text occurs a different number of times than the given" do
@session.visit('/with_count')
expect(@session).not_to have_text('count', count: 0)
expect(@session).not_to have_text('count', count: 1)
expect(@session).not_to have_text(/count/, count: 3)
end
it "should coerce count to an integer" do
@session.visit('/with_count')
expect(@session).to have_text('count', count: '2')
expect(@session).not_to have_text('count', count: '3')
end
end
context "with maximum" do
it "should be true when text occurs same or fewer times than given" do
@session.visit('/with_count')
expect(@session).to have_text('count', maximum: 2)
expect(@session).to have_text(/count/, maximum: 3)
end
it "should be false when text occurs more times than given" do
@session.visit('/with_count')
expect(@session).not_to have_text('count', maximum: 1)
expect(@session).not_to have_text('count', maximum: 0)
end
it "should coerce maximum to an integer" do
@session.visit('/with_count')
expect(@session).to have_text('count', maximum: '2')
expect(@session).not_to have_text('count', maximum: '1')
end
end
context "with minimum" do
it "should be true when text occurs same or more times than given" do
@session.visit('/with_count')
expect(@session).to have_text('count', minimum: 2)
expect(@session).to have_text(/count/, minimum: 0)
end
it "should be false when text occurs fewer times than given" do
@session.visit('/with_count')
expect(@session).not_to have_text('count', minimum: 3)
end
it "should coerce minimum to an integer" do
@session.visit('/with_count')
expect(@session).to have_text('count', minimum: '2')
expect(@session).not_to have_text('count', minimum: '3')
end
end
context "with wait", :requires => [:js] do
it "should find element if it appears before given wait duration" do
Capybara.using_wait_time(0.1) do
@session.visit('/with_js')
@session.click_link('Click me')
expect(@session).to have_text('Has been clicked', :wait => 0.9)
end
end
end
it "should raise an error if an invalid option is passed" do
@session.visit('/with_html')
expect do
expect(@session).to have_text('Lorem', exact: true)
end.to raise_error(ArgumentError)
end
end
Capybara::SpecHelper.spec '#has_no_text?' do
it "should be false if the given text is on the page at least once" do
@session.visit('/with_html')
expect(@session).not_to have_no_text('est')
expect(@session).not_to have_no_text('Lorem')
expect(@session).not_to have_no_text('Redirect')
end
it "should be false if scoped to an element which has the text" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
expect(@session).not_to have_no_text('labore')
end
end
it "should be true if scoped to an element which does not have the text" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
expect(@session).to have_no_text('monkey')
end
end
it "should ignore tags" do
@session.visit('/with_html')
expect(@session).to have_no_text('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
expect(@session).not_to have_no_text('exercitation ullamco laboris')
end
it "should be true if the given text is not on the page" do
@session.visit('/with_html')
expect(@session).to have_no_text('xxxxyzzz')
expect(@session).to have_no_text('monkey')
end
it 'should handle single quotes in the text' do
@session.visit('/with-quotes')
expect(@session).not_to have_no_text("can't")
end
it 'should handle double quotes in the text' do
@session.visit('/with-quotes')
expect(@session).not_to have_no_text(%q{"No," he said})
end
it 'should handle mixed single and double quotes in the text' do
@session.visit('/with-quotes')
expect(@session).not_to have_no_text(%q{"you can't do that."})
end
it 'should be true if text is in the title tag in the head' do
@session.visit('/with_js')
expect(@session).to have_no_text('with_js')
end
it 'should be true if text is inside a script tag in the body' do
@session.visit('/with_js')
expect(@session).to have_no_text('a javascript comment')
expect(@session).to have_no_text('aVar')
end
it "should be true if the given text is on the page but not visible" do
@session.visit('/with_html')
expect(@session).to have_no_text('Inside element with hidden ancestor')
end
it "should be false if :all given and text is invisible." do
@session.visit('/with_html')
expect(@session).not_to have_no_text(:all, 'Some of this text is hidden!')
end
it "should be false if `Capybara.ignore_hidden_elements = true` and text is invisible." do
Capybara.ignore_hidden_elements = false
@session.visit('/with_html')
expect(@session).not_to have_no_text('Some of this text is hidden!')
end
it "should be true if the text in the page doesn't match given regexp" do
@session.visit('/with_html')
expect(@session).to have_no_text(/xxxxyzzz/)
end
it "should be false if the text in the page matches given regexp" do
@session.visit('/with_html')
expect(@session).not_to have_no_text(/Lorem/)
end
it "should escape any characters that would have special meaning in a regexp" do
@session.visit('/with_html')
expect(@session).to have_no_text('.orem')
end
it "should wait for text to disappear", :requires => [:js] do
@session.visit('/with_js')
@session.click_link('Click me')
expect(@session).to have_no_text("I changed it")
end
context "with wait", :requires => [:js] do
it "should not find element if it appears after given wait duration" do
@session.visit('/with_js')
@session.click_link('Click me')
expect(@session).to have_no_text('Has been clicked', :wait => 0.1)
end
end
end
|