Permalink
Browse files

Fix spec failures

  • Loading branch information...
1 parent 828bc2e commit d1e8828d8b2effdd6c9afac7da9306873b95f7cc tmertens committed Jan 17, 2014
Showing with 20 additions and 5 deletions.
  1. +13 −0 lib/capybara/helpers.rb
  2. +7 −5 lib/capybara/node/matchers.rb
View
@@ -70,6 +70,19 @@ def matches_count?(count, options={})
return true
end
+ ##
+ #
+ # Checks if a count of 0 is valid for the given options hash.
+ # Returns false if options hash does not specify any count options.
+ #
+ def expects_none?(options={})
+ if [:count, :maximum, :minimum, :between].any? { |k| options.has_key? k }
+ matches_count?(0,options)
+ else
+ false
+ end
+ end
+
##
#
# Generates a failure message given a description of the query and count
@@ -89,11 +89,10 @@ def has_no_selector?(*args)
# @raise [Capybara::ExpectationNotMet] If the selector does not exist
#
def assert_selector(*args)
- options = args.last.is_a?(Hash) ? args.pop.dup : {}
- expect_none = (options[:count] && Integer(options[:count]) == 0) ? true : false
+ options = args.last.is_a?(Hash) ? args.last.dup : {}
synchronize(Capybara::Query.new(*args).wait) do
result = all(*args)
- raise Capybara::ExpectationNotMet, result.failure_message if result.size == 0 unless expect_none
+ raise Capybara::ExpectationNotMet, result.failure_message if result.size == 0 && !Capybara::Helpers.expects_none?(options)
end
return true
end
@@ -115,13 +114,16 @@ def assert_selector(*args)
# @raise [Capybara::ExpectationNotMet] If the selector exists
#
def assert_no_selector(*args)
+ options = args.last.is_a?(Hash) ? args.last.dup : {}
synchronize(Capybara::Query.new(*args).wait) do
begin
result = all(*args)
rescue Capybara::ExpectationNotMet => e
return true
else
- raise(Capybara::ExpectationNotMet, result.negative_failure_message) if result.size > 0
+ if result.size > 0 || (result.size == 0 && Capybara::Helpers.expects_none?(options))
+ raise(Capybara::ExpectationNotMet, result.negative_failure_message)
+ end
end
end
return true
@@ -486,7 +488,7 @@ def text_found?(*args)
content, options = args
count = Capybara::Helpers.normalize_whitespace(text(type)).scan(Capybara::Helpers.to_regexp(content)).count
- Capybara::Helpers.matches_count?(count, options || {})
+ Capybara::Helpers.matches_count?(count, {:minimum=>1}.merge(options || {}))
end
end
end

0 comments on commit d1e8828

Please sign in to comment.