From a624220a70563b3073fdf1a1357cefc13a2f32db Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 24 Jun 2019 12:19:26 -0700 Subject: [PATCH] Move CountSugar inclusion into a base class --- .codeclimate.yml | 1 + lib/capybara/rspec/matchers/base.rb | 4 ++++ lib/capybara/rspec/matchers/have_ancestor.rb | 4 +--- lib/capybara/rspec/matchers/have_selector.rb | 4 +--- lib/capybara/rspec/matchers/have_sibling.rb | 4 +--- lib/capybara/rspec/matchers/have_text.rb | 4 +--- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 7cc0d4cc..1df1287c 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -20,6 +20,7 @@ engines: exclude_patterns: - "lib/capybara/selector.rb" - "lib/capybara/minitest.rb" + - "lib/capybara/selector/definiton/" eslint: enabled: false fixme: diff --git a/lib/capybara/rspec/matchers/base.rb b/lib/capybara/rspec/matchers/base.rb index a0ea61b0..4315e0f8 100644 --- a/lib/capybara/rspec/matchers/base.rb +++ b/lib/capybara/rspec/matchers/base.rb @@ -65,6 +65,10 @@ module Capybara end end + class CountableWrappedElementMatcher < WrappedElementMatcher + include CountSugar + end + class NegatedMatcher include ::Capybara::RSpecMatchers::Matchers::Compound if defined?(::Capybara::RSpecMatchers::Matchers::Compound) diff --git a/lib/capybara/rspec/matchers/have_ancestor.rb b/lib/capybara/rspec/matchers/have_ancestor.rb index 7b3be039..92c86c81 100644 --- a/lib/capybara/rspec/matchers/have_ancestor.rb +++ b/lib/capybara/rspec/matchers/have_ancestor.rb @@ -6,9 +6,7 @@ require 'capybara/rspec/matchers/count_sugar' module Capybara module RSpecMatchers module Matchers - class HaveAncestor < WrappedElementMatcher - include CountSugar - + class HaveAncestor < CountableWrappedElementMatcher def element_matches?(el) el.assert_ancestor(*@args, &@filter_block) end diff --git a/lib/capybara/rspec/matchers/have_selector.rb b/lib/capybara/rspec/matchers/have_selector.rb index 41376821..7dc96dd9 100644 --- a/lib/capybara/rspec/matchers/have_selector.rb +++ b/lib/capybara/rspec/matchers/have_selector.rb @@ -6,9 +6,7 @@ require 'capybara/rspec/matchers/count_sugar' module Capybara module RSpecMatchers module Matchers - class HaveSelector < WrappedElementMatcher - include CountSugar - + class HaveSelector < CountableWrappedElementMatcher def element_matches?(el) el.assert_selector(*@args, &@filter_block) end diff --git a/lib/capybara/rspec/matchers/have_sibling.rb b/lib/capybara/rspec/matchers/have_sibling.rb index d9296a38..0cebefc2 100644 --- a/lib/capybara/rspec/matchers/have_sibling.rb +++ b/lib/capybara/rspec/matchers/have_sibling.rb @@ -6,9 +6,7 @@ require 'capybara/rspec/matchers/count_sugar' module Capybara module RSpecMatchers module Matchers - class HaveSibling < WrappedElementMatcher - include CountSugar - + class HaveSibling < CountableWrappedElementMatcher def element_matches?(el) el.assert_sibling(*@args, &@filter_block) end diff --git a/lib/capybara/rspec/matchers/have_text.rb b/lib/capybara/rspec/matchers/have_text.rb index b5dc4ff6..afdce79b 100644 --- a/lib/capybara/rspec/matchers/have_text.rb +++ b/lib/capybara/rspec/matchers/have_text.rb @@ -6,9 +6,7 @@ require 'capybara/rspec/matchers/count_sugar' module Capybara module RSpecMatchers module Matchers - class HaveText < WrappedElementMatcher - include CountSugar - + class HaveText < CountableWrappedElementMatcher def element_matches?(el) el.assert_text(*@args) end