mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Remove some duplication in Matcher derived classes
This commit is contained in:
parent
4ca2614e34
commit
67f9842b91
1 changed files with 27 additions and 39 deletions
|
@ -9,6 +9,11 @@ module Capybara
|
||||||
|
|
||||||
attr_reader :failure_message, :failure_message_when_negated
|
attr_reader :failure_message, :failure_message_when_negated
|
||||||
|
|
||||||
|
def initialize(*args, &filter_block)
|
||||||
|
@args = args.dup
|
||||||
|
@filter_block = filter_block
|
||||||
|
end
|
||||||
|
|
||||||
def wrap(actual)
|
def wrap(actual)
|
||||||
actual = actual.to_capybara_node if actual.respond_to?(:to_capybara_node)
|
actual = actual.to_capybara_node if actual.respond_to?(:to_capybara_node)
|
||||||
@context_el = if actual.respond_to?(:has_selector?)
|
@context_el = if actual.respond_to?(:has_selector?)
|
||||||
|
@ -56,11 +61,6 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
class HaveSelector < Matcher
|
class HaveSelector < Matcher
|
||||||
def initialize(*args, &filter_block)
|
|
||||||
@args = args
|
|
||||||
@filter_block = filter_block
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
wrap_matches?(actual) { |el| el.assert_selector(*@args, &@filter_block) }
|
wrap_matches?(actual) { |el| el.assert_selector(*@args, &@filter_block) }
|
||||||
end
|
end
|
||||||
|
@ -79,11 +79,6 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
class HaveAllSelectors < Matcher
|
class HaveAllSelectors < Matcher
|
||||||
def initialize(*args, &filter_block)
|
|
||||||
@args = args
|
|
||||||
@filter_block = filter_block
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
wrap_matches?(actual) { |el| el.assert_all_of_selectors(*@args, &@filter_block) }
|
wrap_matches?(actual) { |el| el.assert_all_of_selectors(*@args, &@filter_block) }
|
||||||
end
|
end
|
||||||
|
@ -98,11 +93,6 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
class HaveNoSelectors < Matcher
|
class HaveNoSelectors < Matcher
|
||||||
def initialize(*args, &filter_block)
|
|
||||||
@args = args
|
|
||||||
@filter_block = filter_block
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
wrap_matches?(actual) { |el| el.assert_none_of_selectors(*@args, &@filter_block) }
|
wrap_matches?(actual) { |el| el.assert_none_of_selectors(*@args, &@filter_block) }
|
||||||
end
|
end
|
||||||
|
@ -135,11 +125,6 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
class HaveText < Matcher
|
class HaveText < Matcher
|
||||||
def initialize(*args)
|
|
||||||
@args = args.dup
|
|
||||||
@content = args[0].is_a?(Symbol) ? args[1] : args[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
wrap_matches?(actual) { |el| el.assert_text(*@args) }
|
wrap_matches?(actual) { |el| el.assert_text(*@args) }
|
||||||
end
|
end
|
||||||
|
@ -149,22 +134,21 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
"text #{format(@content)}"
|
"text #{format(text)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format(content)
|
def format(content)
|
||||||
content.inspect
|
content.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def text
|
||||||
|
@args[0].is_a?(Symbol) ? @args[1] : @args[0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class HaveTitle < Matcher
|
class HaveTitle < Matcher
|
||||||
def initialize(*args)
|
|
||||||
@args = args
|
|
||||||
|
|
||||||
# are set just for backwards compatability
|
|
||||||
@title = args.first
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
wrap_matches?(actual) { |el| el.assert_title(*@args) }
|
wrap_matches?(actual) { |el| el.assert_title(*@args) }
|
||||||
end
|
end
|
||||||
|
@ -174,16 +158,17 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
"have title #{@title.inspect}"
|
"have title #{title.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def title
|
||||||
|
@args.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class HaveCurrentPath < Matcher
|
class HaveCurrentPath < Matcher
|
||||||
def initialize(*args)
|
|
||||||
@args = args
|
|
||||||
@current_path = args.first
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
wrap_matches?(actual) { |el| el.assert_current_path(*@args) }
|
wrap_matches?(actual) { |el| el.assert_current_path(*@args) }
|
||||||
end
|
end
|
||||||
|
@ -193,7 +178,13 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
"have current path #{@current_path.inspect}"
|
"have current path #{current_path.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_path
|
||||||
|
@args.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -201,6 +192,7 @@ module Capybara
|
||||||
include ::Capybara::RSpecMatchers::Compound if defined?(::Capybara::RSpecMatchers::Compound)
|
include ::Capybara::RSpecMatchers::Compound if defined?(::Capybara::RSpecMatchers::Compound)
|
||||||
|
|
||||||
def initialize(matcher)
|
def initialize(matcher)
|
||||||
|
super()
|
||||||
@matcher = matcher
|
@matcher = matcher
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -226,10 +218,6 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
class HaveStyle < Matcher
|
class HaveStyle < Matcher
|
||||||
def initialize(*args)
|
|
||||||
@args = args
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(actual)
|
def matches?(actual)
|
||||||
wrap_matches?(actual) { |el| el.assert_style(*@args) }
|
wrap_matches?(actual) { |el| el.assert_style(*@args) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue