Warn when text/content is checked for nil
This commit is contained in:
parent
fbb1ee7312
commit
91bdb822fe
|
@ -6,11 +6,17 @@ module Capybara
|
|||
class TextQuery < BaseQuery
|
||||
def initialize(type = nil, expected_text, session_options:, **options) # rubocop:disable Style/OptionalArguments
|
||||
@type = type.nil? ? default_type : type
|
||||
@expected_text = expected_text.is_a?(Regexp) ? expected_text : expected_text.to_s
|
||||
@options = options
|
||||
super(@options)
|
||||
self.session_options = session_options
|
||||
|
||||
if expected_text.nil? && !exact?
|
||||
warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. '\
|
||||
'Please specify a string or regexp instead.'
|
||||
end
|
||||
|
||||
@expected_text = expected_text.is_a?(Regexp) ? expected_text : expected_text.to_s
|
||||
|
||||
@search_regexp = Capybara::Helpers.to_regexp(@expected_text, exact: exact?)
|
||||
|
||||
assert_valid_keys
|
||||
|
|
|
@ -139,6 +139,12 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|||
expect(@session).to have_text(nil)
|
||||
end
|
||||
|
||||
it 'should warn when passed nil' do
|
||||
@session.visit('/with_html')
|
||||
expect_any_instance_of(Kernel).to receive(:warn).with(/Checking for expected text of nil is confusing/) # rubocop:disable RSpec/AnyInstance
|
||||
expect(@session).to have_text(nil)
|
||||
end
|
||||
|
||||
it 'should wait for text to appear', requires: [:js] do
|
||||
Capybara.using_wait_time(3) do
|
||||
@session.visit('/with_js')
|
||||
|
|
Loading…
Reference in New Issue