lib/capybara/rspec/matchers.rb in capybara-3.4.2 vs lib/capybara/rspec/matchers.rb in capybara-3.5.0
- old
+ new
@@ -7,10 +7,15 @@
class Matcher
include ::Capybara::RSpecMatchers::Compound if defined?(::Capybara::RSpecMatchers::Compound)
attr_reader :failure_message, :failure_message_when_negated
+ def initialize(*args, &filter_block)
+ @args = args.dup
+ @filter_block = filter_block
+ end
+
def wrap(actual)
actual = actual.to_capybara_node if actual.respond_to?(:to_capybara_node)
@context_el = if actual.respond_to?(:has_selector?)
actual
else
@@ -54,15 +59,10 @@
end
end
end
class HaveSelector < Matcher
- def initialize(*args, &filter_block)
- @args = args
- @filter_block = filter_block
- end
-
def matches?(actual)
wrap_matches?(actual) { |el| el.assert_selector(*@args, &@filter_block) }
end
def does_not_match?(actual)
@@ -77,15 +77,10 @@
@query ||= Capybara::Queries::SelectorQuery.new(*session_query_args, &@filter_block)
end
end
class HaveAllSelectors < Matcher
- def initialize(*args, &filter_block)
- @args = args
- @filter_block = filter_block
- end
-
def matches?(actual)
wrap_matches?(actual) { |el| el.assert_all_of_selectors(*@args, &@filter_block) }
end
def does_not_match?(_actual)
@@ -96,15 +91,10 @@
'have all selectors'
end
end
class HaveNoSelectors < Matcher
- def initialize(*args, &filter_block)
- @args = args
- @filter_block = filter_block
- end
-
def matches?(actual)
wrap_matches?(actual) { |el| el.assert_none_of_selectors(*@args, &@filter_block) }
end
def does_not_match?(_actual)
@@ -133,76 +123,78 @@
@query ||= Capybara::Queries::MatchQuery.new(*session_query_args, &@filter_block)
end
end
class HaveText < Matcher
- def initialize(*args)
- @args = args.dup
- @content = args[0].is_a?(Symbol) ? args[1] : args[0]
- end
-
def matches?(actual)
wrap_matches?(actual) { |el| el.assert_text(*@args) }
end
def does_not_match?(actual)
wrap_does_not_match?(actual) { |el| el.assert_no_text(*@args) }
end
def description
- "text #{format(@content)}"
+ "text #{format(text)}"
end
def format(content)
content.inspect
end
- end
- class HaveTitle < Matcher
- def initialize(*args)
- @args = args
+ private
- # are set just for backwards compatability
- @title = args.first
+ def text
+ @args[0].is_a?(Symbol) ? @args[1] : @args[0]
end
+ end
+ class HaveTitle < Matcher
def matches?(actual)
wrap_matches?(actual) { |el| el.assert_title(*@args) }
end
def does_not_match?(actual)
wrap_does_not_match?(actual) { |el| el.assert_no_title(*@args) }
end
def description
- "have title #{@title.inspect}"
+ "have title #{title.inspect}"
end
- end
- class HaveCurrentPath < Matcher
- def initialize(*args)
- @args = args
- @current_path = args.first
+ private
+
+ def title
+ @args.first
end
+ end
+ class HaveCurrentPath < Matcher
def matches?(actual)
wrap_matches?(actual) { |el| el.assert_current_path(*@args) }
end
def does_not_match?(actual)
wrap_does_not_match?(actual) { |el| el.assert_no_current_path(*@args) }
end
def description
- "have current path #{@current_path.inspect}"
+ "have current path #{current_path.inspect}"
end
+
+ private
+
+ def current_path
+ @args.first
+ end
end
class NegatedMatcher
include ::Capybara::RSpecMatchers::Compound if defined?(::Capybara::RSpecMatchers::Compound)
def initialize(matcher)
+ super()
@matcher = matcher
end
def matches?(actual)
@matcher.does_not_match?(actual)
@@ -224,13 +216,9 @@
@matcher.failure_message
end
end
class HaveStyle < Matcher
- def initialize(*args)
- @args = args
- end
-
def matches?(actual)
wrap_matches?(actual) { |el| el.assert_style(*@args) }
end
def does_not_match?(_actual)