Permalink
Browse files

Refactor the RSpec matchers

I tried adding new matchers and the old code confused me at first…this is easier to
understand.
  • Loading branch information...
1 parent a56f7d1 commit bc33227c77cb5530444d96d4c9921910a7067020 @ferrous26 ferrous26 committed Apr 19, 2012
Showing with 8 additions and 20 deletions.
  1. +8 −20 lib/rspec/expectations/ax_elements.rb
@@ -15,7 +15,9 @@ def initialize kind, filters, &block
# @param [AX::Element]
def matches? parent
- !search(parent).blank?
+ @parent = parent
+ @result = parent.children.find { |x| @qualifier.qualifies? x }
+ !@result.blank?
end
# @return [String]
@@ -25,7 +27,7 @@ def failure_message_for_should
# @param [AX::Element]
def does_not_match? parent
- search(parent).blank?
+ !matches?(parent)
end
# @return [String]
@@ -38,14 +40,6 @@ def description
"should have a child that matches #{@qualifier.describe}"
end
-
- private
-
- def search parent
- @parent = parent
- @result = parent.children.find { |x| @qualifier.qualifies? x }
- end
-
end
##
@@ -83,7 +77,9 @@ def initialize kind, filters, &block
# @param [AX::Element]
def matches? ancestor
- !search(ancestor).blank?
+ @ancestor = ancestor
+ @result = ancestor.search(@kind, @filters, &@block)
+ !@result.blank?
end
# @return [String]
@@ -93,7 +89,7 @@ def failure_message_for_should
# @param [AX::Element]
def does_not_match? ancestor
- search(ancestor).blank?
+ !matches?(ancestor)
end
# @return [String]
@@ -106,14 +102,6 @@ def description
"should have a descendent matching #{@qualifier.describe}"
end
-
- private
-
- def search ancestor
- @ancestor = ancestor
- @result = ancestor.search(@kind, @filters, &@block)
- end
-
end
##

0 comments on commit bc33227

Please sign in to comment.