lib/wildcard_finders/matchers.rb in wildcard_finders-0.1.0 vs lib/wildcard_finders/matchers.rb in wildcard_finders-0.1.1
- old
+ new
@@ -1,7 +1,7 @@
require "capybara/node/matchers"
-
+require "tapp"
module WildcardFinders
module Matchers
METHODS = []
def self.method_added(name)
@@ -11,10 +11,15 @@
::WildcardFinders::Finders::METHODS.each do |method|
if method =~ /\Afind_/
matcher_method = method.to_s.sub("find", "has") + "?"
no_matcher_method = method.to_s.sub("find", "has_no") + "?"
+ rspec_matcher_method = method.to_s.sub("find", "have")
+ rspec_matcher_method_without_block = method.to_s.sub("find", "have") + "_without_block"
+ rspec_no_matcher_method = method.to_s.sub("find", "have_no")
+ rspec_no_matcher_method_without_block = method.to_s.sub("find", "have_no") + "_without_block"
+
define_method(matcher_method) do |*args, &block|
wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until
__send__(wait_method) do
result = __send__(method, *args, &block)
@@ -31,9 +36,30 @@
result = __send__(method, *args, &block)
result and return(false)
end
true
+ end
+
+ RSpec::Matchers.define(rspec_matcher_method_without_block) do |expected|
+ match do |page|
+ page.__send__(matcher_method, expected)
+ end
+ end
+
+ RSpec::Matchers.define(rspec_no_matcher_method_without_block) do |expected|
+ match do |page|
+ page.__send__(no_matcher_method, expected)
+ end
+ end
+
+ # Note: block_given? does not work in define_method
+ RSpec::Matchers.__send__(:define_method, rspec_matcher_method) do |expected = nil, &block|
+ __send__(rspec_matcher_method_without_block, (block ? block : expected))
+ end
+
+ RSpec::Matchers.__send__(:define_method, rspec_no_matcher_method) do |expected = nil, &block|
+ __send__(rspec_no_matcher_method_without_block, (block ? block : expected))
end
end
end
end
end