From 93eff636a677215eb130f775b99e9421fb30f7a2 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 12 Aug 2016 08:19:55 -0400 Subject: Add test assertion helpers Adds assertions that are not part of Capybara but may be useful to Rails users writing system tests. --- actionpack/lib/system_testing/test_helper.rb | 1 + actionpack/lib/system_testing/test_helpers.rb | 1 + .../lib/system_testing/test_helpers/assertions.rb | 32 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 actionpack/lib/system_testing/test_helpers/assertions.rb diff --git a/actionpack/lib/system_testing/test_helper.rb b/actionpack/lib/system_testing/test_helper.rb index 9ac2e02f01..bb68cfe665 100644 --- a/actionpack/lib/system_testing/test_helper.rb +++ b/actionpack/lib/system_testing/test_helper.rb @@ -5,6 +5,7 @@ module SystemTesting module TestHelper include Capybara::DSL include TestHelpers::FormHelper + include TestHelpers::Assertions def after_teardown Capybara.reset_sessions! diff --git a/actionpack/lib/system_testing/test_helpers.rb b/actionpack/lib/system_testing/test_helpers.rb index add9596463..074a45d5c8 100644 --- a/actionpack/lib/system_testing/test_helpers.rb +++ b/actionpack/lib/system_testing/test_helpers.rb @@ -3,5 +3,6 @@ module SystemTesting extend ActiveSupport::Autoload autoload :FormHelper + autoload :Assertions end end diff --git a/actionpack/lib/system_testing/test_helpers/assertions.rb b/actionpack/lib/system_testing/test_helpers/assertions.rb new file mode 100644 index 0000000000..865b5e59db --- /dev/null +++ b/actionpack/lib/system_testing/test_helpers/assertions.rb @@ -0,0 +1,32 @@ +module SystemTesting + module TestHelpers + module Assertions + def assert_all_of_selectors(*items) + options = items.extract_options! + type = type_for_selector(items) + + items.each do |item| + assert_selector type, item, options + end + end + + def assert_none_of_selectors(*items) + options = items.extract_options! + type = type_for_selector(items) + + items.each do |item| + assert_no_selector type, item, options + end + end + + private + def type_for_selector(*items) + if items.first.is_a?(Symbol) + items.shift + else + Capybara.default_selector + end + end + end + end +end -- cgit v1.2.3