Add find?() method so "assert find?(...), msg" can be used in test cases.
authorTom Clegg <tom@curoverse.com>
Tue, 6 May 2014 16:58:14 +0000 (12:58 -0400)
committerTom Clegg <tom@curoverse.com>
Tue, 6 May 2014 16:58:14 +0000 (12:58 -0400)
apps/workbench/test/integration/folders_test.rb
apps/workbench/test/integration_helper.rb

index b39cf24ae07d5258cddf264615e45e625be46991..8752dadbdac943eceefdb7396844f826d4cb5c02 100644 (file)
@@ -20,8 +20,8 @@ class FoldersTest < ActionDispatch::IntegrationTest
       page.assert_no_selector '.editable-submit'
     end
     visit current_path
-    # Raise exception if description update did not survive page refresh:
-    find '.panel', text: 'I just edited this.'
+    assert(find?('.panel', text: 'I just edited this.'),
+           "Description update did not survive page refresh")
   end
 
   test 'Add a new name, then edit it, without creating a duplicate' do
index 88aec2ca6948ef8512b3b5604efe4b315d107560..1784779664bc1074beb7df5888a7f0565d8e7107 100644 (file)
@@ -22,4 +22,16 @@ class ActionDispatch::IntegrationTest
     q_string = URI.encode_www_form('api_token' => api_token)
     "#{path}#{sep}#{q_string}"
   end
+
+  # Find a page element, but return false instead of raising an
+  # exception if not found. Use this with assertions to explain that
+  # the error signifies a failed test rather than an unexpected error
+  # during a testing procedure.
+  def find? *args
+    begin
+      find *args
+    rescue Capybara::ElementNotFound
+      false
+    end
+  end
 end