From b9e14eac0c2a617a04c0e82e9b0527e03567c06c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 25 Feb 2013 13:50:25 -0500 Subject: [PATCH] extend dont_find to Capybara::Element --- README.md | 4 +++ lib/semantic_rails_view_helpers/capybara.rb | 40 ++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0ec88ed..f722d02 100644 --- a/README.md +++ b/README.md @@ -89,5 +89,9 @@ Sometimes the absence of a thing is just as important as the presence of a thing # selector's not there dont_find('#user') + +# ...after you've already found something... + +find('.node').dont_find('.something_inside') ``` diff --git a/lib/semantic_rails_view_helpers/capybara.rb b/lib/semantic_rails_view_helpers/capybara.rb index 93fbad3..cf1f301 100644 --- a/lib/semantic_rails_view_helpers/capybara.rb +++ b/lib/semantic_rails_view_helpers/capybara.rb @@ -62,6 +62,26 @@ def find_object_action(object, action) find("[data-type='#{object}'][data-action='#{action}']") end +module DontFindable + def dont_find_wrap(search) + yield + + sleep Capybara.default_wait_time + + yield + + raise Capybara::ElementFound.new(search) + rescue Capybara::ElementNotFound + true + end + + def dont_find(search) + dont_find_wrap(search) do + find(search) + end + end +end + module Capybara class ElementFound < StandardError def initialize(search) @@ -72,26 +92,14 @@ module Capybara @search end end -end -def dont_find_wrap(search) - yield - - sleep Capybara.default_wait_time - - yield - - raise Capybara::ElementFound.new(search) -rescue Capybara::ElementNotFound - true -end - -def dont_find(search) - dont_find_wrap(search) do - find(search) + class Node::Element + include DontFindable end end +include DontFindable + def dont_find_object(object) case object when Class