match_selector => matches_selector
This commit is contained in:
parent
8715327c43
commit
6b007f41af
|
@ -64,8 +64,8 @@ module Capybara
|
||||||
# @param (see Capybara::Node::Finders#has_selector?)
|
# @param (see Capybara::Node::Finders#has_selector?)
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
#
|
#
|
||||||
def match_selector?(*args)
|
def matches_selector?(*args)
|
||||||
assert_match_selector(*args)
|
assert_matches_selector(*args)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -79,8 +79,8 @@ module Capybara
|
||||||
# @param (see Capybara::Node::Finders#has_selector?)
|
# @param (see Capybara::Node::Finders#has_selector?)
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
#
|
#
|
||||||
def not_match_selector?(*args)
|
def not_matches_selector?(*args)
|
||||||
assert_not_match_selector(*args)
|
assert_not_matches_selector(*args)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -164,19 +164,19 @@ module Capybara
|
||||||
#
|
#
|
||||||
# Asserts that the current_node matches a given selector
|
# Asserts that the current_node matches a given selector
|
||||||
#
|
#
|
||||||
# node.assert_match_selector('p#foo')
|
# node.assert_matches_selector('p#foo')
|
||||||
# node.assert_match_selector(:xpath, '//p[@id="foo"]')
|
# node.assert_matches_selector(:xpath, '//p[@id="foo"]')
|
||||||
# node.assert_match_selector(:foo)
|
# node.assert_matches_selector(:foo)
|
||||||
#
|
#
|
||||||
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
||||||
# such as :text and :visible.
|
# such as :text and :visible.
|
||||||
#
|
#
|
||||||
# node.assert_match_selector('li', :text => 'Horse', :visible => true)
|
# node.assert_matches_selector('li', :text => 'Horse', :visible => true)
|
||||||
#
|
#
|
||||||
# @param (see Capybara::Node::Finders#all)
|
# @param (see Capybara::Node::Finders#all)
|
||||||
# @raise [Capybara::ExpectationNotMet] If the selector does not match
|
# @raise [Capybara::ExpectationNotMet] If the selector does not match
|
||||||
#
|
#
|
||||||
def assert_match_selector(*args)
|
def assert_matches_selector(*args)
|
||||||
query = Capybara::Queries::MatchQuery.new(*args)
|
query = Capybara::Queries::MatchQuery.new(*args)
|
||||||
synchronize(query.wait) do
|
synchronize(query.wait) do
|
||||||
result = query.resolve_for(self.parent)
|
result = query.resolve_for(self.parent)
|
||||||
|
@ -187,7 +187,7 @@ module Capybara
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_not_match_selector(*args)
|
def assert_not_matches_selector(*args)
|
||||||
query = Capybara::Queries::MatchQuery.new(*args)
|
query = Capybara::Queries::MatchQuery.new(*args)
|
||||||
synchronize(query.wait) do
|
synchronize(query.wait) do
|
||||||
result = query.resolve_for(self.parent)
|
result = query.resolve_for(self.parent)
|
||||||
|
@ -197,7 +197,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
alias_method :refute_match_selector, :assert_not_match_selector
|
alias_method :refute_matches_selector, :assert_not_matches_selector
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
|
|
|
@ -14,7 +14,7 @@ module Capybara
|
||||||
private
|
private
|
||||||
|
|
||||||
def valid_keys
|
def valid_keys
|
||||||
[:text, :visible, :exact, :wait] + @selector.custom_filters.keys
|
VALID_KEYS + @selector.custom_filters.keys
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -195,14 +195,14 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
actual.assert_match_selector(*@args)
|
actual.assert_matches_selector(*@args)
|
||||||
rescue Capybara::ExpectationNotMet => e
|
rescue Capybara::ExpectationNotMet => e
|
||||||
@failure_message = e.message
|
@failure_message = e.message
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
def does_not_match?(actual)
|
def does_not_match?(actual)
|
||||||
actual.assert_not_match_selector(*@args)
|
actual.assert_not_matches_selector(*@args)
|
||||||
rescue Capybara::ExpectationNotMet => e
|
rescue Capybara::ExpectationNotMet => e
|
||||||
@failure_message_when_negated = e.message
|
@failure_message_when_negated = e.message
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
Capybara::SpecHelper.spec '#assert_match_selector' do
|
Capybara::SpecHelper.spec '#assert_matches_selector' do
|
||||||
before do
|
before do
|
||||||
@session.visit('/with_html')
|
@session.visit('/with_html')
|
||||||
@element = @session.find(:css, 'span', text: '42')
|
@element = @session.find(:css, 'span', text: '42')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be true if the given selector matches the element" do
|
it "should be true if the given selector matches the element" do
|
||||||
expect(@element.assert_match_selector(:css, '.number')).to be true
|
expect(@element.assert_matches_selector(:css, '.number')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be false if the given selector does not match the element" do
|
it "should be false if the given selector does not match the element" do
|
||||||
expect { @element.assert_match_selector(:css, '.not_number') }.to raise_error(Capybara::ElementNotFound)
|
expect { @element.assert_matches_selector(:css, '.not_number') }.to raise_error(Capybara::ElementNotFound)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be callable on the session" do
|
it "should not be callable on the session" do
|
||||||
expect { @session.assert_match_selector(:css, '.number') }.to raise_error(NoMethodError)
|
expect { @session.assert_matches_selector(:css, '.number') }.to raise_error(NoMethodError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should wait for match to occur", requires: [:js] do
|
it "should wait for match to occur", requires: [:js] do
|
||||||
@session.visit('/with_js')
|
@session.visit('/with_js')
|
||||||
input = @session.find(:css, '#disable-on-click')
|
input = @session.find(:css, '#disable-on-click')
|
||||||
|
|
||||||
expect(input.assert_match_selector(:css, 'input:enabled')).to be true
|
expect(input.assert_matches_selector(:css, 'input:enabled')).to be true
|
||||||
input.click
|
input.click
|
||||||
expect(input.assert_match_selector(:css, 'input:disabled')).to be true
|
expect(input.assert_matches_selector(:css, 'input:disabled')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not accept count options" do
|
it "should not accept count options" do
|
||||||
expect { @element.assert_match_selector(:css, '.number', count: 1) }.to raise_error(ArgumentError)
|
expect { @element.assert_matches_selector(:css, '.number', count: 1) }.to raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,13 +7,13 @@ Capybara::SpecHelper.spec '#match_xpath?' do
|
||||||
it "should be true if the element matches the given selector" do
|
it "should be true if the element matches the given selector" do
|
||||||
expect(@element).to match_selector(:xpath, "//span")
|
expect(@element).to match_selector(:xpath, "//span")
|
||||||
expect(@element).to match_selector(:css, 'span.number')
|
expect(@element).to match_selector(:css, 'span.number')
|
||||||
expect(@element.match_selector?(:css, 'span.number')).to be true
|
expect(@element.matches_selector?(:css, 'span.number')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be false if the element does not match the given selector" do
|
it "should be false if the element does not match the given selector" do
|
||||||
expect(@element).not_to match_selector(:xpath, "//div")
|
expect(@element).not_to match_selector(:xpath, "//div")
|
||||||
expect(@element).not_to match_selector(:css, "span.not_a_number")
|
expect(@element).not_to match_selector(:css, "span.not_a_number")
|
||||||
expect(@element.match_selector?(:css, "span.not_a_number")).to be false
|
expect(@element.matches_selector?(:css, "span.not_a_number")).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use default selector" do
|
it "should use default selector" do
|
||||||
|
@ -30,7 +30,7 @@ Capybara::SpecHelper.spec '#match_xpath?' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Capybara::SpecHelper.spec '#not_match_selector?' do
|
Capybara::SpecHelper.spec '#not_matches_selector?' do
|
||||||
before do
|
before do
|
||||||
@session.visit('/with_html')
|
@session.visit('/with_html')
|
||||||
@element = @session.find(:css, "span", text: 42)
|
@element = @session.find(:css, "span", text: 42)
|
||||||
|
@ -39,13 +39,13 @@ Capybara::SpecHelper.spec '#not_match_selector?' do
|
||||||
it "should be false if the given selector matches the element" do
|
it "should be false if the given selector matches the element" do
|
||||||
expect(@element).not_to not_match_selector(:xpath, "//span")
|
expect(@element).not_to not_match_selector(:xpath, "//span")
|
||||||
expect(@element).not_to not_match_selector(:css, "span.number")
|
expect(@element).not_to not_match_selector(:css, "span.number")
|
||||||
expect(@element.not_match_selector?(:css, "span.number")).to be false
|
expect(@element.not_matches_selector?(:css, "span.number")).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be true if the given selector does not match the element" do
|
it "should be true if the given selector does not match the element" do
|
||||||
expect(@element).to not_match_selector(:xpath, "//abbr")
|
expect(@element).to not_match_selector(:xpath, "//abbr")
|
||||||
expect(@element).to not_match_selector(:css, "p a#doesnotexist")
|
expect(@element).to not_match_selector(:css, "p a#doesnotexist")
|
||||||
expect(@element.not_match_selector?(:css, "p a#doesnotexist")).to be true
|
expect(@element.not_matches_selector?(:css, "p a#doesnotexist")).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use default selector" do
|
it "should use default selector" do
|
||||||
|
|
Loading…
Reference in New Issue